用于为视频制作 MP4 封装的 Sample 的批处理脚本
2010-09-02 15:02:35 · Author: 五帝 · Tagged with: Video Processing
这个批处理脚本可以根据给定的起始时间和长度给视频制作样本文件。利用 Mencoder 转换,MP4Box 封装。最终生成的文件为 x264 + AAC 编码的 MP4 文件,可以在 Flash Player 中播放。
脚本中除了容易出问题的帧率识别那加了个简单的错误处理外,其他地方都没有进行错误处理。
将这个批处理脚本保存为 make_sample.bat 文件,则用法就是:
例如将 src.avi 从 1h12m5s 处开始的 30s 做成一个样本 dest.mp4 可以用如下命令:
外部链接:
1. MPlayer (Win32)
2. MP4Box
3. MPlayer Manual
4. MP4Box Documentation
5. WinMEnc (including avidump.exe)
脚本中除了容易出问题的帧率识别那加了个简单的错误处理外,其他地方都没有进行错误处理。
- @echo off
- set path=C:\Program Files\Media Utilities\AviDump;%path:C:\Program Files\Media Utilities\AviDump;=%
- set src_file=%~f1
- set dest_file=%~f2
- set offset=%3
- set length=%4
- set tmp_avi_file=%~dpn2.avi
- set raw_264_file=%~dpn2.264
- set raw_aac_file=%~dpn2.aac
- @echo on
- "C:\Program Files\Media Utilities\MPlayer\mencoder.exe" -of avi -af pan=1:0.5:0.5 -vf harddup -srate 44100 -oac faac -faacopts br=48:mpeg=4:object=2 -ovc x264 -ffourcc H264 -x264encopts crf=30:level_idc=41 -ss %offset% -endpos %length% -o "%tmp_avi_file%" "%src_file%"
- "C:\Program Files\Media Utilities\MPlayer\mencoder.exe" -ovc copy -nosound -of rawvideo -o "%raw_264_file%" "%tmp_avi_file%"
- "C:\Program Files\Media Utilities\MPlayer\mencoder.exe" -ovc frameno -oac copy -of rawaudio -o "%raw_aac_file%" "%tmp_avi_file%"
- @echo off
- for /f "tokens=1,2 delims=:" %%a in ('avidump.exe "%tmp_avi_file%" ^| find "Video frame rate"') do set fps=%%b
- if not defined fps goto error
- set fps=%fps:~1%
- if "%fps%" == "" goto error
- "C:\Program Files\Media Utilities\MP4Box\MP4Box.exe" -add "%raw_264_file%":fps=%fps% -add "%raw_aac_file%" -new "%dest_file%"
- set fps=
- del "%raw_aac_file%"
- del "%raw_264_file%"
- del "%tmp_avi_file%"
- exit /b
- :error
- @echo off
- echo.
- echo Frame rate recognition failed.
- echo.
- pause
- @echo on
将这个批处理脚本保存为 make_sample.bat 文件,则用法就是:
call "make_sample.bat" <src> <dest> <offset> <length>
例如将 src.avi 从 1h12m5s 处开始的 30s 做成一个样本 dest.mp4 可以用如下命令:
call "make_sample.bat" "src.avi" "dest.mp4" 1:12:05:0 0:0:30:0
外部链接:
1. MPlayer (Win32)
2. MP4Box
3. MPlayer Manual
4. MP4Box Documentation
5. WinMEnc (including avidump.exe)
Current language: 中文 (简体)