FFmpeg&FFPlay:过滤器“trim”的选项“start”和“end”无法解析时间长度字符串,但“-ss”和“-to”可以完美运行

FFmpeg&FFPlay:过滤器“trim”的选项“start”和“end”无法解析时间长度字符串,但“-ss”和“-to”可以完美运行

我正在尝试在处理之前预览剪切的视频在 Windows 上,Cut.bat我尝试了以下方法:

@echo off
@cd/d %~dp0

REM Entered by user
set startTime1=5
REM Entered by user
set startTime2=00:05
REM Entered by user
set toTime1=13
REM Entered by user
set toTime2=00:13

echo [96mPreviewing...press any key to process[0m

REM No, ffplay don't support `-to` option
REM ffplay  -i in.mp4  -ss %startTime1%  -to %toTime1%  out1.mp4

REM Result: 8 seconds long video preview, start from 00:05 (correct)
ffplay  -i in.mp4  -vf trim=start=%startTime1%:end=%toTime1%,setpts=PTS-STARTPTS -af atrim=start=%startTime1%:end=%toTime1%,asetpts=PTS-STARTPTS

REM Result: 13 seconds long video preview, start from 00:00
ffplay  -i in.mp4  -vf trim=start=%startTime2%:end=%toTime1%,setpts=PTS-STARTPTS -af atrim=start=%startTime2%:end=%toTime1%,asetpts=PTS-STARTPTS

REM Result: failed to preview so I commented it out
REM ffplay  -i in.mp4  -vf trim=start=%startTime1%:end=%toTime2%,setpts=PTS-STARTPTS -af atrim=start=%startTime1%:end=%toTime2%,asetpts=PTS-STARTPTS

REM Result: failed to preview so I commented it out
REM ffplay  -i in.mp4  -vf trim=start=%startTime2%:end=%toTime2%,setpts=PTS-STARTPTS -af atrim=start=%startTime2%:end=%toTime2%,asetpts=PTS-STARTPTS

pause

REM Result: All of them are 8 seconds long videoes, start from 00:05 (correct)
ffmpeg  -i in.mp4  -ss %startTime1%  -to %toTime1%  -c copy  out1.mp4
ffmpeg  -i in.mp4  -ss %startTime2%  -to %toTime1%  -c copy  out2.mp4
ffmpeg  -i in.mp4  -ss %startTime1%  -to %toTime2%  -c copy  out3.mp4
ffmpeg  -i in.mp4  -ss %startTime2%  -to %toTime2%  -c copy  out4.mp4

pause

该文件称他们都支持 时间持续表达-ss,对于和来说是正确的-to,但对于startendtrim

由于startTime&toTime是由用户(我自己)输入的,所以我希望自由书写,而不是使用严格的格式

  • 我写错了吗?如果是,正确的语法是什么?
  • 还有其他简单和/或可靠的方法来实现我的目标吗?

答案1

根据这个答案,这是一个转义技巧(我不得不说 ffmpeg 的转义语法就是意大利面条式语法的一个很好的例子

正确的语法是:

set startTime2Es=%startTime2::=\:%
set toTime2Es=%toTime2::=\:%

ffplay  -i in.mp4  -vf "trim=start='%startTime2Es%':end='%toTime2Es%',setpts=PTS-STARTPTS" -af "atrim=start='%startTime2Es%':end='%toTime2Es%',asetpts=PTS-STARTPTS"

代替

ffplay -i in.mp4 -vf trim=start=%startTime2%:end=%toTime2%,setpts=PTS-STARTPTS -af atrim=start=%startTime2%:end=%toTime2%,asetpts=PTS-STARTPTS

相关内容