Avidemux cmd script for batch conversion

Avidemux is a free video editor designed for simple cutting, filtering and encoding tasks.

Below is a DOS command line script to process multiple video on multiple level of directories.

Create a test.bat near the folder has the videos you want to convert, the converted files will be near source videos.

@echo off

REM https://stackoverflow.com/a/9681923/1320686
REM cmd expands variables when commands are parsed, not when they are run. Stick a setlocal enabledelayedexpansion at the start. Use instead of %var% the !var!
setlocal enabledelayedexpansion

REM which file extension dir command will try to find
set sorce_file_extenion=wmv

REM expected destination format extension
set destination_file_extenion=mp4

REM where avidemux exists
set avidemux="C:\Program Files\Avidemux\avidemux.exe"

REM these variables dont take place when using py_script [START]
set videocodec=x264
set audiocodec=Copy
set video_container=MP4
REM MATROSKA / MP4 / Copy
REM these variables dont take place when using py_script [END]

REM if py script defined ignore the above
set py_script=""


REM %~dp0 gets the batch file location
rem set output_folder=%~dp0\!converted

REM Create output folder if doesnt exists
rem if not exist "%output_folder%" mkdir %output_folder%

REM foreach file in folder & subfolders
FOR /F "usebackq delims==" %%f in (`dir *.%sorce_file_extenion% /s /b`) do (
	
	REM assing item properties to variables nf xf pf ff beause we set %%f, if was %%I will be nI xI pI fI
	set file_wo_ext=%%~nf
	set fileext=%%~xf
	set file_folder=%%~df%%~pf
	set full_pathfile=%%~ff
	set test=%%f
	
	set destination_pathfile=!file_folder!!file_wo_ext!.!destination_file_extenion!
	
	REM if file exists aka when converting to the same video format, merge current datetime to filename
	if exist "!destination_pathfile!" (
		@call :GetDateTime now
		set destination_pathfile=!file_folder!!file_wo_ext!!now!.!destination_file_extenion!
	) 
	
	echo Processing %%f
	
	IF %py_script%=="" (
		@call :RunJob "%%f" "!destination_pathfile!"
	) ELSE (
		@call :RunJobwScript "%%f" "!destination_pathfile!"
	)
)

goto the_end



REM ref - https://stackoverflow.com/a/19729941/1320686
REM https://stackoverflow.com/a/6728702/1320686 - eof return to the caller!!
:GetDateTime
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)
@set %1=%mydate%_%mytime%
goto :eof 

:RunJob
%avidemux% --output-format %video_container% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load %1 --save %2 --quit
goto :eof

:RunJobwScript
%avidemux% --load %1 --run %py_script% --save %2 --quit
goto :eof


:the_end
echo Process ended at %date%%time%

 
 


ref how to .py script – http://aldoniel.free.fr/calepindugeek/Batch-processing-of-multiple-video.html

alt

before :

#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
adm.loadVideo("C:/Users/user1/Documents/LMDMF/FRED.ET.CIE.(LMDMF).mp4")
adm.clearSegments()
adm.addSegment(0, 0, 743440000)
adm.markerA = 0
adm.markerB = 743440000
adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"unknown")
adm.audioAddTrack(0)
adm.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280")

after :

#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"unknown")
adm.audioAddTrack(0)
adm.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280")

ref – batch files IDE

By: |27/10/2019