Avidemux Forum

Avidemux => Stable branch (2.5) discussion => Topic started by: Winny on April 07, 2016, 06:32:59 pm

Title: Script to recode .mpg
Post by: Winny on April 07, 2016, 06:32:59 pm
Hi everyone.
I have many videos from an old video recorder. All of them have a blue, vertical line at the right edge. I've tried to eliminate it using the "blacken" filter and it seems to work fine.
I'm trying to write a script to decode all the videos in the folder, apply the blacken filter and then recode. I'm setting the parameters for recoding, but i would like to have a quality similar to the original files. Is there a command to get the average bitrate or the size (in KB or MB) of the files?
My script at the moment looks like the following, but please focus on the function processFile at the end, where I set the video codec:

var app = new Avidemux();
var ds = new DirectorySearch();
var orgDir;
var destDir;
var reg =new RegExp(".$");

var sep="/";
var reg2 =new RegExp("\/.*\/");
var extension;
var target;

// set directories

      print("orgDir : <"+orgDir+">");
      print("destDir : <"+destDir+">");

// start processing files
      // Only process file i want
      if(!ds.isNotFile && !ds.isDirectory && !ds.isHidden && !ds.isArchive && !ds.isSingleDot && !ds.isDoubleDot)
          if(extension == "mpg")
              print("file < "+target+" >");
              displayInfo("file < "+target+" >");
          //print("File: "+ds.GetFileName()+" is "+ds.GetFileSize()+" bytes, extension "+extension);
  print("We just searched in directory \"" + ds.GetFileDirectory() + "\"");
  displayError("Error initializing the directory search");
displayInfo("Finished !");

function processFile(filename, targetfile)
      // Load the file
      displayInfo("filename: "+filename+" --> targetfile: "+targetfile+".");

      //** Postproc **

      app.video.fps1000 = 25000;

      //** Filters **

      //** Video Codec conf **
      app.video.codecPlugin("C16E9CCE-D9B3-4fbe-B0C5-8B1BEBF2178E", "mpeg2enc", "2PASSBITRATE=6500", "<?xml version='1.0'?      ><Mpeg2Config><Mpeg2Options><maxBitrate>9000</maxBitrate><fileSplit>4096</fileSplit><widescreen>true</widescreen><streamType>dvd</  streamType><interlaced>none</interlaced></Mpeg2Options></Mpeg2Config>");

      app.setContainer("PS", "00 00 00 00 00 00 00 00 ");

This seems to work fine. What I would like to do is to obtain the average bitrate of the original file in order to use it instead of 6500 in "2PASSBITRATE=6500" inside command app.video.codecPlugin.
So, what I would like to know is if there is a command that returns the average bitrate.
For example, something similar to app.video.getFps1000() that returns the frames per second.

Thanks in advance for your answers.
Title: Re: Script to recode .mpg
Post by: Jan Gruuthuse on April 08, 2016, 03:53:48 am
Perhaps with hasQpel (http://www.avidemux.org/admWiki/doku.php?id=using:scripting)
See Guide to encoding types Same Qz as input (http://www.avidemux.org/admWiki/doku.php?id=tutorial:guide_to_encoding_types#same_qz_as_input)
Probably getting info outside avidemux when 2pass is required: How can I obtain the bitrate of a video from a command line in Linux? (http://superuser.com/questions/55780/how-can-i-obtain-the-bitrate-of-a-video-from-a-command-line-in-linux)
Title: Re: Script to recode .mpg
Post by: Winny on April 08, 2016, 11:46:47 am
Thanks for your answer.. ..but unfortunately the guide does not give a command to do it..
And I would like to do it inside the Avidemux script. I think this is for sure an information that Avidemux gets from the file..
I don't think qpel function can be used for this purpose..