0

I have a video where I would like to change the time scale of a video based on ratios read in from a file.

I have figured out that to double the speed for an entire video I could use the setpts filter doing setpts=2*PTS, however what I want to do is change the scale over time so the video would

  • Start at 1x speed
  • At the 5.7564 second mark it would switch to 1.4x speed
  • At the 10.2571 second mark it would switch to 0.983333x speed
  • At the 15.6251 second mark it would switch to 1x speed for the rest of the video.

I have figured out I would likely need to make a script file that could be read by -filter_script:v but I don't know what to use to get the behavior I want.

My first naive approach was to do

setpts='
if(lt(T,5.7564),
    1*PTS,      
if(lt(T,10.2571),
    1.4*PTS,
if(lt(T,15.6251),
    0.983333*PTS,
    1*PTS
))))'

but that causes the video to jump around at the cut points and can cause parts of the video to be skipped or repeated. I now understand why this happens, but I don't know what I should do instead.

The best way would likely be to cut the video into 4 segments and just use a single setpts=#*PTS to per segment, but I don't know how to script that.

1 Answer 1

1

As you mentioned one approach would be to trim the input into four separate segments, apply the setpts filter on two of them and at last concatenate all of them. here is the command for it:

ffmpeg -i input.mp4 -lavfi "[0:v]trim=0:5.7564[firstpart];[0:v]trim=start=5.7564:10.2571,setpts=PTS-STARTPTS[secondpart];[0:v]trim=10.2571:15.6251,setpts=PTS-STARTPTS[thirdpart];[0:v]trim=15.6251,setpts=PTS-STARTPTS[forthpart];[secondpart]setpts=PTS/1.4[second];[thirdpart]setpts=PTS/0.983333[third];[firstpart][second][third][forthpart]concat=n=4:v=1:unsafe=1[out]" -map '[out]' output.mp4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .