User Tools

Site Tools


This is an old revision of the document!

Batch processing

This page tries to explain how batch processing works with Avidemux.

This tutorial shows how one can process multiple video files with same settings. This is useful for cases where you have to e.g. convert multiple video files to certain format.

Short introduction to different methods

Since AVIdemux supports both Command-line processing (command_line_usage) and JS scripting (ECMAScript) (Scripting) possibilities, there are multiple ways to batch process your files:

  1. Command-line only processing with bash script/.bat file or similar.
  2. JS scripting (ECMAScript) only processing
  3. Combination of command-line and JS scripting

Command-line only batch processing

AVIdemux command-line support doesn't allow you to change all possible options. But it usually works OK for simple format conversions. Since it allows you to use additional command-line tools, you can for example automate YouTube uploads after AVIdemux has processed the files. Because different operating systems and shells have different kind of filename limits, commands etc. some command-line samples presented below won't work in all systems/shells.

Win32 example (.bat file) that will convert all .mp4 files in current folder to .avi (XviD+MP3). Original files aren't modified. New files are named like something.mp4.avi

set avidemux="C:\Program Files\Avidemux 2.5\avidemux2.exe"
set videocodec=Xvid
set audiocodec=MP3
for %%f in (*.mp4) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%f" --save "%%f.avi" --quit

(you should change “C:\Program Files\Avidemux 2.5\avidemux2.exe” in case your AVIdemux installation is located in different folder) You can copy that text to new text file, then rename the text file to something.bat and move it to the folder where you want to process the files. Then just double click the something.bat and processing should start.

For Linux/Unixes using Bash shell similar script would be

for FIL in `ls *mp4 | sort` ; do
  avidemux2 --video-codec $VIDEOCODEC --audio-codec $AUDIOCODEC --force-alt-h264 --load "$FIL" --save ${FIL%.*}.avi --quit

(this will create something.avi from something.mp4)

If you want to force certain bitrate for audio and video with Win32, do following

set avidemux="C:\softa\avidemux_r6854\avidemux2.exe"
set videocodec=Xvid
set videobitrate=cbr=512
set audiocodec=MP3
set audiobitrate=64
for %%f in (*.mp4) do %avidemux% --video-codec %videocodec% --video-conf %videobitrate% --audio-codec %audiocodec% --audio-bitrate %audiobitrate% --force-alt-h264 --load "%%f" --save "%%f.avi" --quit

For Linux/Unixes using Bash shell similar script would be

for FIL in `ls *mp4 | sort` ; do
  avidemux2 --video-codec $VIDEOCODEC --video-conf $VIDEOBITRATE --audio-codec $AUDIOCODEC --audio-bitrate $AUDIOBITRATE --force-alt-h264 --load "$FIL" --save ${FIL%.*}.avi --quit

(this will create something.avi from something.mp4)

JS scripting (ECMAScript) only batch processing

Since AVIdemux supports JS scripting (ECMAScript), you can create scripts with it also. These scripts can be loaded from command-line (–run) or from GUI (File → Load/Run project…). Because environment is same on all platforms, the scripts are quite portable. Only problematic part is slashing since some operating systems assume / is the proper one and few systems think \ is the right one.

With JS scripts (ECMAScripts) one can also use additional GUI elements (file and folder select dialogs) which helps if you must make newbie friendly scripts.

First the actual script you can save as something.js, when you run it, it will ask input folder and filetype (first dialog) + output folder and filename (second dialog). Script picks all files of same type from first folder and saves them as XviD+MP3 AVI to second folder.

//AD  <-
  Simple script that scans the orgDir directory
  and loads all .xyz files and encodes them to Xvid+MP3 AVI
  The resulting file is put in destDir directory
  Using new directorySearch API
var app = new Avidemux();
var ds = new DirectorySearch();
var srcDir;
var dstDir;
var reg = new RegExp(".$");
var extReg = new RegExp(".*[.](.+)$"); 
//this is the directory separator char for WINDOWS! for *nix, it should be: sep = "/";
var sep = "\\";
var fileExt;
var pickedExt;
var dstPath;
var filesDone = 0;
var filesSkip = 0;
var filesErrd = 0;
displayInfo("Pick any file in the source directory. All files of that type (.xyz) will be processed. Filename will be ignored but the file extension will be used! \r\n\r\ne.g. If you want to process AVIs, be sure to pick any .avi file!");
//pop up a dialog asking for a source file. We will remove the file name leaving just the dir
srcDir = fileReadSelect();
//run the extReg regex designed to pull out just the extension of this file
pickedExt = srcDir.replace(extReg, "$1").toLowerCase();
displayInfo(pickedExt + "Pick the destination directory and enter a random filename. Filename will be ignored");
//pop up a dialog asking for a destination file. We will remove the file name leaving just the dir 
dstDir = fileWriteSelect();
//extract just the path part of each picked file
srcDir = pathOnly(srcDir);
dstDir = pathOnly(dstDir);
//if the path ends with a directory separator characters, remove them
//it shouldnt be more than one, but a while loop will cater for any number of them
//so c:\temp\\\\ becomes c:\temp
while(srcDir.charAt(srcDir.length-1) == sep){
while(dstDir.charAt(dstDir.length-1) == sep){
//initalise the directory search by telling it the directory
  //while we havent reached the end of the files list in the directory
  // --> note that every call to ds.NextFile() moves it on by one
  // --> until ds.NextFIle() returns false meaning it finished the list
    //pull the filename out (no path)
    //only process valid files that are not directories
    if(!ds.isNotFile && !ds.isDirectory && !ds.isSingleDot && !ds.isDoubleDot)
      //we want to do some work with the extension so pull it out now
      //is the extension of this file the same as the one we picked?
      if(ext.toLowerCase() == pickedExt)
        //build the output file name. To avoid ovwriting source file, if dir is the same prefix a _        
        if(srcDir.toLowerCase() == dstDir.toLowerCase()){
          dstPath = dstDir + sep + "_" + ds.GetFileName() + ".avi";
          dstPath = dstDir + sep + ds.GetFileName() + ".avi";
        //build the source file path
        srcPath = srcDir + sep + ds.GetFileName();
        //we set this option first. If Avidemux loads a file it thinks need unpacking/time mapping
        //then setting this option now will ensure that operation is done when we load
        //load the file. this action also purges all the video filters and codec settings
        //see if the audio is VBR. if it is, this builds a time map. if it is not, this does nothing;
        //this might not need doing if forceUnpack has been stated. I dont think it can be done
        //twice though so its safe to repeat here
        //all the code in this section was generated by the app. if you want to write a script and use filters
        //you can get the app to do the hard work by:
        // load one of the files you will script
        // set all the video and audio options you want
        // on file menu, pick Save Project as (note: NOT save avi file!!)
        //the job file you save will have a section detailing the filters. copy it
        //re-encode to xvid 2 pass, bitrate = 1000 (plus 128 for audio = 1128 kbps, 507.6 megs per hour)
        //all options are set to simple, no GMC, no Qpel etc so that standalone simple players are ok"92B544BE-59A3-4720-86F0-6AD5A2526FD2", "Xvid", "2PASSBITRATE=1000", "<?xml version='1.0'?><XvidConfig><XvidOptions><threads>0</threads><vui><sarAsInput>false</sarAsInput><sarHeight>1</sarHeight><sarWidth>1</sarWidth></vui><motionEstimation>high</motionEstimation><rdo>dct</rdo><bFrameRdo>false</bFrameRdo><chromaMotionEstimation>true</chromaMotionEstimation><qPel>false</qPel><gmc>false</gmc><turboMode>false</turboMode><chromaOptimiser>false</chromaOptimiser><fourMv>false</fourMv><cartoon>false</cartoon><greyscale>false</greyscale><interlaced>none</interlaced><frameDropRatio>0</frameDropRatio><maxIframeInterval>300</maxIframeInterval><maxBframes>2</maxBframes><bFrameSensitivity>0</bFrameSensitivity><closedGop>false</closedGop><packed>false</packed><quantImin>1</quantImin><quantPmin>1</quantPmin><quantBmin>1</quantBmin><quantImax>31</quantImax><quantPmax>31</quantPmax><quantBmax>31</quantBmax><quantBratio>150</quantBratio><quantBoffset>100</quantBoffset><quantType>h.263</quantType><intraMatrix><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value></intraMatrix><interMatrix><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value></interMatrix><trellis>true</trellis><singlePass><reactionDelayFactor>16</reactionDelayFactor><averagingQuantiserPeriod>100</averagingQuantiserPeriod><smoother>100</smoother></singlePass><twoPass><keyFrameBoost>10</keyFrameBoost><maxKeyFrameReduceBitrate>20</maxKeyFrameReduceBitrate><keyFrameBitrateThreshold>1</keyFrameBitrateThreshold><overflowControlStrength>5</overflowControlStrength><maxOverflowImprovement>5</maxOverflowImprovement><maxOverflowDegradation>5</maxOverflowDegradation><aboveAverageCurveCompression>0</aboveAverageCurveCompression><belowAverageCurveCompression>0</belowAverageCurveCompression><vbvBufferSize>0</vbvBufferSize><maxVbvBitrate>0</maxVbvBitrate><vbvPeakBitrate>0</vbvPeakBitrate></twoPass></XvidOptions></XvidConfig>");;"Lame",128,20,"80 00 00 00 00 00 00 00 01 00 00 00 02 00 00 00 00 00 00 00 ");;;;"STEREO";
        //write that file;
      } else{ //we decide not to process this file
        //some diagnostic info incase you wonder why a whole dir of files arent processing
        whyNot = dstPath + " wasnt processed because: ";
          whyNot += "it is not a file, ";
          whyNot += "it is a directory, ";
          whyNot += "it is hidden, ";
          whyNot += "it is marked for archive, ";
          whyNot += "it is a meta-ref to the current dir (.), ";
          whyNot += "it is a meta-ref to the parent dir (..), ";
        //whats that reason now?  

You can create scripts quite easily by yourself. You can apply needed settings via GUI and then use File → Save Project As… to create text file that contains all settings. Then you can open that file in text editor and copy+paste needed stuff to new script (or replaces parts of other script).

Combination of command-line and JS scripting

Last option is to combine best of both worlds. Usually the best situation for this is to create automated script (no dialogs) that you will run for all files.

Short Win32 example below, first the script (again save it as something.js)

//AD  <- Needed to identify//
var app = new Avidemux();
//** Postproc **,3,0);
//** Filters **
//** Video Codec conf **"92B544BE-59A3-4720-86F0-6AD5A2526FD2", "Xvid", "2PASSBITRATE=1000", "<?xml version='1.0'?><XvidConfig><XvidOptions><threads>0</threads><vui><sarAsInput>false</sarAsInput><sarHeight>1</sarHeight><sarWidth>1</sarWidth></vui><motionEstimation>high</motionEstimation><rdo>dct</rdo><bFrameRdo>false</bFrameRdo><chromaMotionEstimation>true</chromaMotionEstimation><qPel>false</qPel><gmc>false</gmc><turboMode>false</turboMode><chromaOptimiser>false</chromaOptimiser><fourMv>false</fourMv><cartoon>false</cartoon><greyscale>false</greyscale><interlaced>none</interlaced><frameDropRatio>0</frameDropRatio><maxIframeInterval>300</maxIframeInterval><maxBframes>2</maxBframes><bFrameSensitivity>0</bFrameSensitivity><closedGop>false</closedGop><packed>false</packed><quantImin>1</quantImin><quantPmin>1</quantPmin><quantBmin>1</quantBmin><quantImax>31</quantImax><quantPmax>31</quantPmax><quantBmax>31</quantBmax><quantBratio>150</quantBratio><quantBoffset>100</quantBoffset><quantType>h.263</quantType><intraMatrix><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value></intraMatrix><interMatrix><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value></interMatrix><trellis>true</trellis><singlePass><reactionDelayFactor>16</reactionDelayFactor><averagingQuantiserPeriod>100</averagingQuantiserPeriod><smoother>100</smoother></singlePass><twoPass><keyFrameBoost>10</keyFrameBoost><maxKeyFrameReduceBitrate>20</maxKeyFrameReduceBitrate><keyFrameBitrateThreshold>1</keyFrameBitrateThreshold><overflowControlStrength>5</overflowControlStrength><maxOverflowImprovement>5</maxOverflowImprovement><maxOverflowDegradation>5</maxOverflowDegradation><aboveAverageCurveCompression>0</aboveAverageCurveCompression><belowAverageCurveCompression>0</belowAverageCurveCompression><vbvBufferSize>0</vbvBufferSize><maxVbvBitrate>0</maxVbvBitrate><vbvPeakBitrate>0</vbvPeakBitrate></twoPass></XvidOptions></XvidConfig>");
//** Audio **;"Lame",128,20,"80 00 00 00 00 00 00 00 01 00 00 00 02 00 00 00 00 00 00 00 ");;;;"STEREO";
//End of script

Win32 example (.bat file) that will convert all .mp4 files in current folder to .avi (XviD+MP3). Original files aren't modified. New files are named like something.mp4.avi

set avidemux="C:\Program Files\Avidemux 2.5\avidemux2.exe"
for %%f in (*.mp4) do %avidemux% --force-alt-h264 --load "%%f" --run something.js --save "%%f.avi" --quit

For Linux/Unixes using Bash shell similar script would be

ls *.mp4 | sort > $VAR # Collect the files in the current directory
cat $VAR | while read line; do  # Loop read the filenames from the file
  INPUT=$(echo ${line}) # Grab the next new filename
  OUTPUT=${INPUT%.*4} # Remove shortest match of characters between the '. ' and the '4' at end of string
  OUTPUT+=".avi" # Append new extension
  avidemux2 --force-alt-h264 --load "$INPUT" --run something.js --save "$OUTPUT" --quit 
rm $VAR # Remove the text file with the file names

(this will create something.avi from something.mp4)

If you create your own combine batch settings, make sure order of command-line parameters is always –load something, –run something and –save something (AVIdemux will run these options in give order).


  • You can replace avidemux2 with avidemux2_cli if you want to process files without GUI
  • You can use –nogui option in case you want to suppress all dialogs (it must be first option!)
tutorial/batch_processing.1303038998.txt.gz · Last modified: 2012/11/11 08:51 (external edit)