目前有很多视频剪辑合并工具,其功能很强大.但是用起来很麻烦,一段一段需要手动处理.为了弥补这个弊端利用
批处理文件完成全自动剪辑和合并的功能.效率灰常高哈哈 通过配置文件输入剪辑时间使用起来更加方便
__________________________________________________________
Conversion_Batch.bat 从 _Periods.ini 中读取剪辑信息和时间
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setlocal enabledelayedexpansion
echo @echo off>zCmd_tmp.bat
set /a count=0
rem Directory or file name contains an ! exclamation point problem
for /f "eol=# delims=" %%i in (_Periods.ini) do (
set /a count=!count!+1
if !count! EQU 1 (set ifn="%%i")
if !count! EQU 2 (set ofn=%%i)
if !count! EQU 3 (set extn=%%i
set mCmd=call Lib_Conversion !ifn! !ofn! !extn!)
if !count! GEQ 4 (
set /a newindex=!count!-3
if !newindex! LEQ 9 (set index=0!newindex!) else (set index=!newindex!)
set _time=%%i
rem echo !mCmd! !_time:~0,12! !_time:~13,12! !index!
echo !mCmd! !_time:~0,12! !_time:~13,12! !index!>>zCmd_tmp.bat ))
setlocal disabledelayedexpansion
call zCmd_tmp.bat
del zCmd_tmp.bat
__________________________________________________________________________
计算总时间 Lib_CalculateTotalTime.bat 01:02:03.400 04:03:10.510 [display]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@echo off
set start_pos_tmp=%1
set end_pos_tmp=%2
if "%start_pos_tmp:~1,1%"==":" set "start_pos_tmp=0%start_pos_tmp%"
if "%end_pos_tmp:~1,1%"==":" set "end_pos_tmp=0%end_pos_tmp%"
set hour=%start_pos_tmp:~0,2%
set min=%start_pos_tmp:~3,2%
set sec=%start_pos_tmp:~6,2%
set msec=%start_pos_tmp:~9,3%
rem --------for skip 08 09---------------
if %hour:~0,1%==0 set hour=%hour:~1,1%
if %min:~0,1%==0 set min=%min:~1,1%
if %sec:~0,1%==0 set sec=%sec:~1,1%
if %msec:~0,1%==0 set msec=%msec:~1,2%
if %msec:~0,1%==0 set msec=%msec:~1,1%
set /a hour=%hour%
set /a min=%min%
set /a sec=%sec%
set /a msec=%msec%
set /a start_millsec=%hour%*60*60+%min%*60+%sec%
set /a start_millsec=%start_millsec%*1000+%msec%
set ehour=%end_pos_tmp:~0,2%
set emin=%end_pos_tmp:~3,2%
set esec=%end_pos_tmp:~6,2%
set emsec=%end_pos_tmp:~9,3%
rem --------for skip 08 09---------------
if %ehour:~0,1%==0 set ehour=%ehour:~1,1%
if %emin:~0,1%==0 set emin=%emin:~1,1%
if %esec:~0,1%==0 set esec=%esec:~1,1%
if %emsec:~0,1%==0 set emsec=%emsec:~1,2%
if %emsec:~0,1%==0 set emsec=%emsec:~1,1%
set /a ehour=%ehour%
set /a emin=%emin%
set /a esec=%esec%
set /a emsec=%emsec%
set /a end_millsec=%ehour%*60*60+%emin%*60+%esec%
set /a end_millsec=%end_millsec%*1000+%emsec%
set /a total_time_millsec=%end_millsec%-%start_millsec%
rem echo %hour% %min% %sec% %msec%
rem echo %ehour% %emin% %esec% %emsec%
rem echo %start_millsec% %end_millsec% %total_time_millsec%
set /a tsec=%total_time_millsec%/1000
set /a tmsec=%total_time_millsec%-%tsec%*1000
set /a tmin=%tsec%/60
set /a tsec=%tsec%-%tmin%*60
set /a thour=%tmin%/60
set /a tmin=%tmin%-%thour%*60
if %thour% LEQ 9 (set thour=0%thour%)
if %tmin% LEQ 9 (set tmin=0%tmin%)
if %tsec% LEQ 9 (set tsec=0%tsec%)
if %tmsec% LEQ 9 (set tmsec=00%tmsec%) else (if %tmsec% LEQ 99 (set tmsec=0%tmsec%))
set total_time=%thour%:%tmin%:%tsec%.%tmsec%
if "%3"=="display" (echo [%start_pos_tmp% - %end_pos_tmp%] = %total_time%)
_______________________
转换 Lib_Conversion.bat
~~~~~~~~~~~~~~~~~~~~~~~
@echo off
set h=%time:~0,2%
if "%h:~0,1%"==" " set "h=0%h:~1%"
set m=%time:~3,2%
set s=%time:~6,2%
set hms=%h%%m%%s%
rem ------------------------------input parameters-----------------------------
set inFile=%1
set outFile=%2_%hms%_%6.%3
set start_pos=%4
set end_pos=%5
rem set video_bit_rate=-b:v 1500k
rem set audio_bit_rate=-b:a 64k
rem set frame_size=-s 720x404
rem set aspect=-aspect 16:9
set logFileName=%2_conversion.log
rem for copy
set video_codec=-c:v copy
set audio_codec=-c:a copy
rem for H264
rem set video_codec=-c:v libx264
rem set audio_codec=-c:a libvo_aacenc
rem for mpeg4 xvid
rem set video_codec=-c:v mpeg4
rem set fourcc_tag_out=-tag:v XVID
rem set audio_codec=-c:a libmp3lame
rem set inFile="D:\TDDOWNLOAD\01.mp4"
rem set outFile="%hms%.avi"
rem set start_pos=00:40:10.000
rem set end_pos=00:40:11.000
rem ------------------------------calctime-------------------------------------
if "%end_pos%" NEQ "" (call Lib_CalculateTotalTime %start_pos% %end_pos% display)
if "%total_time%" NEQ "" (set total_time=-t %total_time%)
if "%start_pos%" NEQ "" (set start_pos=-ss %start_pos%)
rem ------------------------------make cmd-------------------------------------
set cmd=ffmpeg
set cmd=%cmd% %start_pos%
set cmd=%cmd% -y -i %inFile% %total_time%
set cmd=%cmd% %audio_codec% %audio_bit_rate%
set cmd=%cmd% %video_codec% %fourcc_tag_out% %video_bit_rate%
rem set cmd=%cmd% -g 12 -bf 2 -qcomp 0.2 -dc 10 -mbd 2 %frame_size% %aspect%
set cmd=%cmd% %frame_size% %aspect%
set cmd=%cmd% %outFile%
rem ------------------------------run cmd--------------------------------------
set begin_time=%date:~0,10% %time:~0,11%
@echo on
%cmd%
@echo off
set end_time=%date:~0,10% %time%
rem ------------------------------write to log---------------------------------
echo ---%date:~0,10% %time:~0,11%---------------------------------------------->>%logFileName%
echo %cmd%>>%logFileName%
echo.>>%logFileName%
echo inFile = %inFile%>>%logFileName%
echo outFile = %outFile%>>%logFileName%
if "%video_bit_rate%" NEQ "" (echo Video bit rate = %video_bit_rate:~5,10%>>%logFileName%)
if "%audio_bit_rate%" NEQ "" (echo Audio bit rate = %audio_bit_rate:~5,10%>>%logFileName%)
echo.>>%logFileName%
echo start_pos = %start_pos:~4,12%>>%logFileName%
echo end_pos = %end_pos%>>%logFileName%
echo total_time = %total_time:~3,12%>>%logFileName%
echo.>>%logFileName%
echo begin time = %begin_time%>>%logFileName%
echo end time = %end_time%>>%logFileName%
rem ------------------------------put message----------------------------------
echo -------The end of the conversion------------------------------------------
rem echo inFile = %inFile%
rem echo outFile = %outFile%
if "%video_bit_rate%" NEQ "" (echo video bit rate = [v:%video_bit_rate:~5,10%] [a:%audio_bit_rate:~5,10%])
echo video time = [%start_pos:~4,12% - %end_pos%] = %total_time:~3,12%
call Lib_CalculateTotalTime %begin_time:~11,11% %end_time:~11,11%
echo conversion time = [%begin_time:~11,11% - %end_time:~11,11% ] = %total_time:~0,12%
echo --------------------------------------------------------------------------
__________________
合并 Lib_Joins.bat
~~~~~~~~~~~~~~~~~~
@echo off
setlocal enabledelayedexpansion
dir *.avi/b/w/n/on>all_avi_name.txt
set aaf=mencoder
for /f %%i in (all_avi_name.txt) do (set aaf=!aaf! "%%i")
set aaf=!aaf! -oac copy -ovc copy -o join.avi
rem set aaf=!aaf! -oac pcm -ovc copy -o join.avi
echo %aaf%>>join.log
set begin_time=%date:~0,10% %time:~0,11%
%aaf%
set end_time=%date:~0,10% %time%
echo ------------ All video join are completed ------------
call Lib_CalculateTotalTime %begin_time:~11,11% %end_time:~11,11%
echo join time = [%begin_time:~11,11% - %end_time:~11,11%] = %total_time:~0,12%
echo ------------------------------------------------------
下载批处理