Author Topic: Script to recode .mpg  (Read 835 times)


  • Newbie
  • *
  • Posts: 2
Script to recode .mpg
« 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:
Code: [Select]
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 **,3,0); = 25000;

      //** Filters **"blacken","left=0","right=96","top=0","bottom=6");

      //** Video Codec conf **"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
So, what I would like to know is if there is a command that returns the average bitrate.
For example, something similar to
Code: [Select] that returns the frames per second.

Thanks in advance for your answers.
« Last Edit: April 07, 2016, 10:11:07 PM by Winny »

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 5021
Re: Script to recode .mpg
« Reply #1 on: April 08, 2016, 03:53:48 AM »
Perhaps with hasQpel (
See 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?


  • Newbie
  • *
  • Posts: 2
Re: Script to recode .mpg
« Reply #2 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..