0

I'm tring to preview cut video before process it on Windows, this Cut.bat is what I tried:

@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

The document said all of them support time duration expression, it's true for -ss and -to, but not working well with start & end of trim

Since startTime & toTime are entered by user (myself) so I hope to write it freely instead of using strict format

  • Did I wrote it wrong? If so, what's the correct syntax?
  • Is there any other simple and/or reliable way to achieve my goal?
Byzod
  • 295

1 Answers1

0

According to this answer, it's an escape trick (I have to say the escape syntax of ffmpeg is a good example of spaghetti

The correct syntax would be:

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"

instead of

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

Byzod
  • 295