junglemike
3rd July 2012, 18:16
Hello fellas.
I've written some simple batch script which takes any videos in specific folder, and converts them to format supported by Nokia phone 5800 (with it's Real player).
My programming skills are very very basic, so don't be harsh :)
What I've done so far:
-extracting audio into .wav with ffmpeg
-compress audio with nero aac into .mp4
-create simple avisynth script (video only)
-encode .avs file with 2-pass by Xvid_encraw. Real player
supports only mper4-Asp - so no x264 :-((
-mux compressed video & audio into .mp4 using mp4box.exe
What I need your help with:
Phone's resolution is 640x320, so I would like to implement smart resize option. I already written the algorithm itself using batch. All I need - is to get the the video resolution into my script, so I can manipulate it and calculate optimal output resolution for nokia.
I know it's no problem for .avs file (smth like clip.width) - but what about batch file? How Can I get width and height of video file into batch variable?
set bitrate=300
set my_temp=f:\temp
set resize=464,352
rem Create the avs script
set my_cur_dir=%cd%
for %%f in (*.avi *.flv *.mkv *.mpg *.mp4) do (
Rem Extract audio from avi file using ffmpeg
c:\encode\ffmpeg.exe -i "%my_cur_dir%\%%f" "%my_temp%\%%f.wav"
rem Encode the audio with Nero AAC using 39kbps bitrate
cd /d %my_temp%
c:\encode\neroAacEnc.exe -q 0.19 -if "%my_temp%\%%f.wav" -of "%my_temp%\%%f.wav.mp4"
Rem Create .avs file in temp dir
cd /d %my_cur_dir%
echo directshowsource("%my_cur_dir%\%%f",audio=false^) lanczosresize(%resize%^)>%my_temp%\%%f.avs
cd /d %my_temp%
rem Encode the original video file with xvid (2 passes)
start "encode" /b /low /wait "d:\Program Files\Xvid\xvid_encraw.exe" -progress 100 -nopacked -max_bframes 0 -qtype 0 -vhqmode 1 -i "%my_temp%\%%f.avs" -max_key_interval 100 -pass1 src.pass -quality 5 -nochromame -turbo
start "encode" /b /low /wait "d:\Program Files\Xvid\xvid_encraw.exe" -progress 100 -nopacked -max_bframes 0 -qtype 0 -vhqmode 4 -i "%my_temp%\%%f.avs" -max_key_interval 100 -pass2 src.pass -bitrate %bitrate% -quality 6 -avi "%my_temp%\%%f.avi"
rem mux the encoded video and audio and put it in source folder
cd /d %my_cur_dir%
md out
"c:\MP4Box.exe" -add "%my_temp%\\%%f.wav.mp4" -add "%my_temp%\\%%f.avi" "%my_cur_dir%\out\%%f.mp4"
rem delete all temp files
cd /d %my_temp%
del *.* /q
cd /d %my_cur_dir%
)
cd /d %my_cur_dir%\out
for %%f in (*.*) do move "%%f" "%my_cur_dir%"
cd..
rmdir out
pause
I've written some simple batch script which takes any videos in specific folder, and converts them to format supported by Nokia phone 5800 (with it's Real player).
My programming skills are very very basic, so don't be harsh :)
What I've done so far:
-extracting audio into .wav with ffmpeg
-compress audio with nero aac into .mp4
-create simple avisynth script (video only)
-encode .avs file with 2-pass by Xvid_encraw. Real player
supports only mper4-Asp - so no x264 :-((
-mux compressed video & audio into .mp4 using mp4box.exe
What I need your help with:
Phone's resolution is 640x320, so I would like to implement smart resize option. I already written the algorithm itself using batch. All I need - is to get the the video resolution into my script, so I can manipulate it and calculate optimal output resolution for nokia.
I know it's no problem for .avs file (smth like clip.width) - but what about batch file? How Can I get width and height of video file into batch variable?
set bitrate=300
set my_temp=f:\temp
set resize=464,352
rem Create the avs script
set my_cur_dir=%cd%
for %%f in (*.avi *.flv *.mkv *.mpg *.mp4) do (
Rem Extract audio from avi file using ffmpeg
c:\encode\ffmpeg.exe -i "%my_cur_dir%\%%f" "%my_temp%\%%f.wav"
rem Encode the audio with Nero AAC using 39kbps bitrate
cd /d %my_temp%
c:\encode\neroAacEnc.exe -q 0.19 -if "%my_temp%\%%f.wav" -of "%my_temp%\%%f.wav.mp4"
Rem Create .avs file in temp dir
cd /d %my_cur_dir%
echo directshowsource("%my_cur_dir%\%%f",audio=false^) lanczosresize(%resize%^)>%my_temp%\%%f.avs
cd /d %my_temp%
rem Encode the original video file with xvid (2 passes)
start "encode" /b /low /wait "d:\Program Files\Xvid\xvid_encraw.exe" -progress 100 -nopacked -max_bframes 0 -qtype 0 -vhqmode 1 -i "%my_temp%\%%f.avs" -max_key_interval 100 -pass1 src.pass -quality 5 -nochromame -turbo
start "encode" /b /low /wait "d:\Program Files\Xvid\xvid_encraw.exe" -progress 100 -nopacked -max_bframes 0 -qtype 0 -vhqmode 4 -i "%my_temp%\%%f.avs" -max_key_interval 100 -pass2 src.pass -bitrate %bitrate% -quality 6 -avi "%my_temp%\%%f.avi"
rem mux the encoded video and audio and put it in source folder
cd /d %my_cur_dir%
md out
"c:\MP4Box.exe" -add "%my_temp%\\%%f.wav.mp4" -add "%my_temp%\\%%f.avi" "%my_cur_dir%\out\%%f.mp4"
rem delete all temp files
cd /d %my_temp%
del *.* /q
cd /d %my_cur_dir%
)
cd /d %my_cur_dir%\out
for %%f in (*.*) do move "%%f" "%my_cur_dir%"
cd..
rmdir out
pause