News:

--

Main Menu

Script to recode .mpg

Started by Winny, April 07, 2016, 06:32:59 PM

Previous topic - Next topic

Winny

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
      orgDir="/media/...."
      destDir="/media/...."
      orgDir=pathOnly(orgDir);
      destDir=pathOnly(destDir);

      orgDir=orgDir.replace(reg,"");
      destDir=destDir.replace(reg,"");
      print("orgDir : <"+orgDir+">");
      print("destDir : <"+destDir+">");

// start processing files
if(ds.Init(orgDir))
{
  while(ds.NextFile())
  {
      // Only process file i want
      if(!ds.isNotFile && !ds.isDirectory && !ds.isHidden && !ds.isArchive && !ds.isSingleDot && !ds.isDoubleDot)
      {
          extension=ds.GetExtension();
          if(extension == "mpg")
          {
              target=ds.GetFileName();
              print("file < "+target+" >");
              displayInfo("file < "+target+" >");
              target=destDir+sep+target;
              displayInfo("***"+ds.GetFileName()+"-->"+target);
              processFile(orgDir+sep+ds.GetFileName(),target);
              }
          //print("File: "+ds.GetFileName()+" is "+ds.GetFileSize()+" bytes, extension "+extension);
      }
  }
  print("We just searched in directory \"" + ds.GetFileDirectory() + "\"");
  ds.Close();
}
else
  displayError("Error initializing the directory search");
displayInfo("Finished !");

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

      //** Postproc **
      app.video.setPostProc(3,3,0);

      app.video.fps1000 = 25000;

      //** Filters **
      app.video.addFilter("blacken","left=0","right=96","top=0","bottom=6");

      //** 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 ");
      setSuccess(1);
}



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.

Jan Gruuthuse


Winny

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..