用于windows的FFMPEG批处理脚本,用于删除前13秒和后6秒

用于windows的FFMPEG批处理脚本,用于删除前13秒和后6秒,ffmpeg,video-editing,Ffmpeg,Video Editing,所以,在过去的两天里,我一直在这方面工作,在这里浏览文章,很多人只给了我一半的答案。我有大约200个视频都需要批量转换。我只有阅读的窗口。我已经成功地删除了前13秒没有问题。但最后6个需要从每个文件中删除。我的最新迭代是: for %%a in ("*.mp4") do set /a dur=(ffprobe -i "%%a" -show_entries format=duration -v quiet -of csv="p=0") s

所以,在过去的两天里,我一直在这方面工作,在这里浏览文章,很多人只给了我一半的答案。我有大约200个视频都需要批量转换。我只有阅读的窗口。我已经成功地删除了前13秒没有问题。但最后6个需要从每个文件中删除。我的最新迭代是:

for %%a in ("*.mp4") do set /a dur=(ffprobe -i "%%a" -show_entries format=duration -v quiet -of csv="p=0") set /a trim=(dur-6 -sexagesimal) ffmpeg -t trim -i "%%a" "output\%%~na.mp4"
然而,当我运行这个程序时,我得到了“不平衡括号”。错误。完整读数如下:

C:\Users\Me\Desktop\FFMPEG Test Folder>set /a dur=(ffprobe -i "test.mp4" -show_entries format=duration -v quiet -of csv="p=0") set /a trim=(dur-6 -sexagesimal) ffmpeg -t trim -i "test.mp4" "output\test.mp4"
Unbalanced parenthesis.

这就是最终起作用的原因

@Echo Off
SetLocal
Set "ext=mp4"
Set "opts=-v quiet"
Set "opts=%opts% -print_format "compact=print_section=0:nokey=1:escape=csv""
Set "opts=%opts% -show_entries "format=duration""
If Exist *.%ext% (If Not Exist "Trimmed\" MD Trimmed)
For %%a In (*.%ext%) Do Call :Sub "%%~a"
Exit/B

:Sub
For /f "Tokens=1* Delims=." %%a In (
    'C:\ffmpeg\bin\FFProbe %opts% %1') Do (Set/A "ws=%%a-6.00" & Set "ps=%%b")
rem If %ws% Lss 20 GoTo :EOF
Set/A hh=ws/(60*60), lo=ws%%(60*60), mm=lo/60, ss=lo%%60
If %hh% Lss 10 Set hh=0%hh%
If %mm% Lss 10 Set mm=0%mm%
If %ss% Lss 10 Set ss=0%ss%
C:\ffmpeg\bin\FFMpeg -i %1 -ss 00:00:13.0000 -to %hh%:%mm%:%ss%.%ps:~,3% -filter:v "crop=950:720:170:0" -r 24 -c:a copy "Trimmed\%~1"

这就是最终起作用的原因

@Echo Off
SetLocal
Set "ext=mp4"
Set "opts=-v quiet"
Set "opts=%opts% -print_format "compact=print_section=0:nokey=1:escape=csv""
Set "opts=%opts% -show_entries "format=duration""
If Exist *.%ext% (If Not Exist "Trimmed\" MD Trimmed)
For %%a In (*.%ext%) Do Call :Sub "%%~a"
Exit/B

:Sub
For /f "Tokens=1* Delims=." %%a In (
    'C:\ffmpeg\bin\FFProbe %opts% %1') Do (Set/A "ws=%%a-6.00" & Set "ps=%%b")
rem If %ws% Lss 20 GoTo :EOF
Set/A hh=ws/(60*60), lo=ws%%(60*60), mm=lo/60, ss=lo%%60
If %hh% Lss 10 Set hh=0%hh%
If %mm% Lss 10 Set mm=0%mm%
If %ss% Lss 10 Set ss=0%ss%
C:\ffmpeg\bin\FFMpeg -i %1 -ss 00:00:13.0000 -to %hh%:%mm%:%ss%.%ps:~,3% -filter:v "crop=950:720:170:0" -r 24 -c:a copy "Trimmed\%~1"