用于为视频制作 MP4 封装的 Sample 的批处理脚本
这个批处理脚本可以根据给定的起始时间和长度给视频制作样本文件。利用 Mencoder 转换,MP4Box 封装。最终生成的文件为 x264 + AAC 编码的 MP4 文件,可以在 Flash Player 中播放。

脚本中除了容易出问题的帧率识别那加了个简单的错误处理外,其他地方都没有进行错误处理。

  1. @echo off
  2. set path=C:\Program Files\Media Utilities\AviDump;%path:C:\Program Files\Media Utilities\AviDump;=%
  3. set src_file=%~f1
  4. set dest_file=%~f2
  5. set offset=%3
  6. set length=%4
  7. set tmp_avi_file=%~dpn2.avi
  8. set raw_264_file=%~dpn2.264
  9. set raw_aac_file=%~dpn2.aac
  10. @echo on
  11. "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%"
  12. "C:\Program Files\Media Utilities\MPlayer\mencoder.exe" -ovc copy -nosound -of rawvideo -o "%raw_264_file%" "%tmp_avi_file%"
  13. "C:\Program Files\Media Utilities\MPlayer\mencoder.exe" -ovc frameno -oac copy -of rawaudio -o "%raw_aac_file%" "%tmp_avi_file%"
  14. @echo off
  15. for /"tokens=1,2 delims=:" %%in ('avidump.exe "%tmp_avi_file%" ^| find "Video frame rate"') do set fps=%%b
  16. if not defined fps goto error
  17. set fps=%fps:~1%
  18. if "%fps%" == "" goto error
  19. "C:\Program Files\Media Utilities\MP4Box\MP4Box.exe" -add "%raw_264_file%":fps=%fps% -add "%raw_aac_file%" -new "%dest_file%"
  20. set fps=
  21. del "%raw_aac_file%"
  22. del "%raw_264_file%"
  23. del "%tmp_avi_file%"
  24. exit /b
  25. :error
  26. @echo off
  27. echo.
  28. echo Frame rate recognition failed.
  29. echo.
  30. pause
  31. @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: 中文 (简体)
Leave a Comment
Name
(required)
E-mail
(required, will not be published)
Website
(optional)
Comment
A syntax system which is similar to wiki markup is available, see the guide