@echo off :: :: Encode a source video file as MPEG-2. :: By Helge Klein, http://it-from-inside.blogspot.com/ :: Version: 1.4 :: :: Input: The source file needs to be specified as first argument. Wildcards are allowed. Example: "C:\Videos\New Files\*.mov" :: Output: Input-filename.mpg. One output file per input file. :: :: Optimized for videos from Panasonic's Lumix LX3 :: :: - Container: Quicktime MOV :: - Codec: MJPEG :: - Resolution: 1280x720 :: - Audio: 1 Channel (mono) :: :: Notes on MEncoder messages: :: :: - "BUFFER UNDEFLOW at stream 0, raising muxrate to 12196 kb/s, delta_scr: 36269" :: This is an informational message only (can unfortunately only be discerned in the source code). Buffer size is adjusted automatically. :: :: - "BUFFER OVERFLOW: 4704 > 4096, pts: 828837000" :: This is an error message (can unfortunately only be discerned in the source code). :: If it is logged at the end of processing, the last frame is incomplete. :: Resolution: the "abuf_size" must be increased (for reference: default value is 4). This value is multiplied by 1024. The resulting number is used as buffer size. It must not be too small or data will be lost. :: :: Version history: :: :: 1.0 :: - Initial version :: 1.1 :: - Paths with spaces in them are now handled correctly :: 1.2 :: - Wildcards are now supported as input file name (e.g. "C:\Data\Videos\*.mov") :: 1.3 :: - The timestamp on the destination video file is copied from the source video file after conversion. When the script is finished, both files will have identical modification dates/times. For this, touch.exe is required. :: - Increased abuf_size from 8 (*1024) to 10 (*1024) to reduce the probability of buffer overflows :: 1.4 :: - File names with spaces in them are now handled correctly :: :: Requirements: :: :: - MPlayer/MEncoder (http://www.mplayerhq.hu/design7/dload.html) :: - Touch (http://sourceforge.net/projects/touchforwindows/) :: :: Variables used during encoding set X_RES=1280 set Y_RES=720 set ASPECT_RATIO=16/9 set FRAMERATE=24 set VIDEO_BITRATE=12000 set VIDEO_BITRATE_MAX=16000 set AUDIO_FREQ=48000 set AUDIO_BITRATE=112 set AUDIO_CHANNELS=1 set LAVC_OPTIONS=vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=%VIDEO_BITRATE_MAX%:vbitrate=%VIDEO_BITRATE%:keyint=15:trell:mbd=2:acodec=mp2:abitrate=%AUDIO_BITRATE% set MPEG_OPTIONS=format=dvd:vaspect=%ASPECT_RATIO%:vwidth=%X_RES%:vheight=%Y_RES%:vframerate=%FRAMERATE%:interleaving2:abuf_size=10 :: Loop through all input files for /f "usebackq delims=" %%i in (`dir /b "%~1"`) do call :ConvertThis "%~dp1%%i" goto :eof :: :: End of script. Subroutines follow. :: :ConvertThis :: Safety check for output file existence if not exist "%~dpn1.mpg" goto ConvertNow echo. echo WARNING: Output file %~dpn1.mpg already exists. Corresponding source file will not be converted again. echo. goto :eof :ConvertNow :: 1-pass convervsion mencoder -oac lavc -ovc lavc -of mpeg -mpegopts %MPEG_OPTIONS% -ofps %FRAMERATE% -lavcopts %LAVC_OPTIONS% -noskip -channels %AUDIO_CHANNELS% -srate %AUDIO_FREQ% -af lavcresample=%AUDIO_FREQ% -o "%~dpn1.mpg" "%~1" :: Copy the timestamp from the source to the destination file touch -c -r "%~1" "%~dpn1.mpg" goto :eof