May 14, 2021, 11:46:21 PM



Need help with batch processing script.

Started by Samj22, April 28, 2021, 06:57:42 AM

Previous topic - Next topic


I have been using a bat file to convert MKV to MP4 and have had no problems, but I need to change it. This is my current script.

set avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"
set videocodec=Copy
set audiocodec=Copy
for %%f in (*.mkv) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%f" --save "%%f.mp4" --quit

del *.mkv

My question is what lines do I have to add to do the same thing convert to MP4 from MKV, but also downsize a 2160p video (4k video) to a 1080p video? I'm not so smart when it comes to scripting, but the script has been the best way I found to convert my videos. It will take too long to do each video 1 by 1 so I can manually add the resize filter. So is there any way to add it to the batch script?


If you modify the properties of the video stream in any way (i.e. if you apply filters), you need to re-encode. Load a video, choose and setup the video encoder which suits your needs best the way you need it, add and configure swsResize video filter, then use "File" --> "Project Script" --> "Save As Project" to export the current configuration as a tinyPy script. Edit the script removing lines with calls to loadVideo ("adm.loadVideo" if "adm" has been defined as "Avidemux()"), setPostProc, all calls to methods starting with "audio" (and "setSourceTrackLanguage") and to "setContainer". It should become like that:

adm = Avidemux()
adm.addVideoFilter("swscale", ...)

with a proper encoder and swscale configuration instead of "...".

Then use

set avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"
set myproject="Drive:\Path\to\the\edited\project\"
set audiocodec=Copy
for %%f in (*.mkv) do %avidemux% --load "%%f" --audio-codec %audiocodec% --run %myproject% --save "%%f.mp4" --quit

to process the files.

I would strongly advise against deleting source files before having verified that the output is fine. By the way, deleting files is the only thing which mandates usage of batch scripting rather than internal Avidemux scripting.

A few notes:

a) "--force-alt-h264" is invalid since a decade or so;

b) always "--load" first, set codec etc. second;

c) if you re-encode, make sure you have completely disabled post-processing in Avidemux Preferences unless you know exactly why you need post-processing for some specific task.

If you don't use hardware accelerated video decoding ("DXVA2" on Windows), you can also use the command-line version of Avidemux (avidemux_cli.exe) instead of the graphical one.


Thank you so much! It worked perfectly! and thank you for fixing my issues with the code. I copied it from somewhere. and wouldn't know the problems with it otherwise. Now I got my new code and know how to adjust it for each video for the best result.