This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
tutorial:batch_processing [2011/01/08 19:04] agent_007 ECMA mention |
tutorial:batch_processing [2012/11/11 08:51] (current) |
||
|---|---|---|---|
| Line 7: | Line 7: | ||
| ===== Short introduction to different methods ===== | ===== Short introduction to different methods ===== | ||
| - | Since AVIdemux supports both Command-line processing ([[using:command_line_usage]]) and JS scripting ([[using:Scripting]]) possibilities, there are multiple ways to batch process your files: | + | Since AVIdemux supports both Command-line processing ([[using:command_line_usage]]) and JS scripting (ECMAScript) ([[using:Scripting]]) possibilities, there are multiple ways to batch process your files: |
| - | 1. Command-line only processing with bash script/.bat file or similar. | + | - Command-line only processing with bash script/.bat file or similar. |
| - | 2. JS scripting (ECMAScript) only processing | + | - JS scripting (ECMAScript) only processing |
| - | 3. Combination of command-line and JS scripting | + | - Combination of command-line and JS scripting |
| ==== Command-line only batch processing ==== | ==== Command-line only batch processing ==== | ||
| Line 25: | Line 25: | ||
| 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. | 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. | ||
| - | If you want to force certain bitrate for audio and video, do following | + | For Linux/Unixes using Bash shell similar script would be |
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | VIDEOCODEC="Xvid" | ||
| + | AUDIOCODEC="MP3" | ||
| + | for FIL in `ls *mp4 | sort` ; do | ||
| + | avidemux2 --video-codec $VIDEOCODEC --audio-codec $AUDIOCODEC --force-alt-h264 --load "$FIL" --save ${FIL%.*}.avi --quit | ||
| + | done | ||
| + | </code> | ||
| + | (this will create **something.avi** from **something.mp4**) | ||
| + | |||
| + | |||
| + | If you want to force certain bitrate for audio and video with Win32, do following | ||
| <code> | <code> | ||
| set avidemux="C:\softa\avidemux_r6854\avidemux2.exe" | set avidemux="C:\softa\avidemux_r6854\avidemux2.exe" | ||
| Line 34: | Line 46: | ||
| 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 %%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 | ||
| </code> | </code> | ||
| + | |||
| + | For Linux/Unixes using Bash shell similar script would be | ||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | VAR="batchfiles.txt" | ||
| + | VIDEOCODEC="Xvid" | ||
| + | AUDIOCODEC="MP3" | ||
| + | VIDEOBITRATE="cbr=512" | ||
| + | AUDIOBITRATE="64" | ||
| + | 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 | ||
| + | done | ||
| + | </code> | ||
| + | (this will create **something.avi** from **something.mp4**) | ||
| ==== JS scripting (ECMAScript) only batch processing ==== | ==== 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. | 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 one can also use additional GUI elements (file folder select dialog) which helps if you must make newbie friendly scripts. | + | 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 are all files of same type from first folder and save them as XviD+MP3 AVI to second folder. | + | 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. |
| <code javascript> | <code javascript> | ||
| //AD <- | //AD <- | ||
| Line 55: | Line 81: | ||
| var dstDir; | var dstDir; | ||
| var reg = new RegExp(".$"); | var reg = new RegExp(".$"); | ||
| - | var extReg = new RegExp(".*[.](.+)$"); | + | var extReg = new RegExp(".*[.](.+)$"); |
| - | + | ||
| //this is the directory separator char for WINDOWS! for *nix, it should be: sep = "/"; | //this is the directory separator char for WINDOWS! for *nix, it should be: sep = "/"; | ||
| Line 186: | Line 211: | ||
| } | } | ||
| </code> | </code> | ||
| + | |||
| + | 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**) | ||
| + | <code javascript> | ||
| + | //AD <- Needed to identify// | ||
| + | var app = new Avidemux(); | ||
| + | //** Postproc ** | ||
| + | app.video.setPostProc(3,3,0); | ||
| + | |||
| + | //** Filters ** | ||
| + | |||
| + | //** Video Codec conf ** | ||
| + | app.video.codecPlugin("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 ** | ||
| + | app.audio.reset(); | ||
| + | app.audio.codec("Lame",128,20,"80 00 00 00 00 00 00 00 01 00 00 00 02 00 00 00 00 00 00 00 "); | ||
| + | app.audio.normalizeMode=0; | ||
| + | app.audio.normalizeValue=0; | ||
| + | app.audio.delay=0; | ||
| + | app.audio.mixer="STEREO"; | ||
| + | app.setContainer("AVI"); | ||
| + | setSuccess(1); | ||
| + | //app.Exit(); | ||
| + | |||
| + | //End of script | ||
| + | </code> | ||
| + | |||
| + | 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** | ||
| + | <code> | ||
| + | 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 | ||
| + | </code> | ||
| + | |||
| + | For Linux/Unixes using Bash shell similar script would be | ||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | for FIL in `ls *mp4 | sort` ; do | ||
| + | avidemux2 --force-alt-h264 --load "$FIL" --run something.js --save ${FIL%.*}.avi --quit | ||
| + | done | ||
| + | </code> | ||
| + | (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 given order). | ||
| + | ==== Tips ==== | ||
| + | * 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!) | ||