How to use slow motion effect in a specific time interval with ffmpeg
The setpts
filter does not have timeline editing functionality like some of the other filters (refer to ffmpeg -filters
to see which do).
This means you will have to make a slow video and concatenate it into your normal speed videos or perform some fancy filtering.
Example: video only
Using the trim
, setpts
, and concat
filters:
The input in this example has a duration of 60 seconds. 0-10 will be normal speed, 10-30 will be 50% slower, and 30-end will be normal speed resulting in an output with a duration of ~80 seconds:
ffmpeg -i input.mkv -filter_complex \
"[0:v]trim=0:10,setpts=PTS-STARTPTS[v1]; \
[0:v]trim=10:30,setpts=PTS-STARTPTS[v2]; \
[0:v]trim=start=30,setpts=PTS-STARTPTS[v3]; \
[v2]setpts=PTS/0.5[slowv]; \
[v1][slowv][v3]concat=n=3:v=1:a=0[out]" \
-map "[out]" output.mp4
Example: with audio
ffmpeg -i input.mkv -filter_complex \
"[0:v]trim=0:10,setpts=PTS-STARTPTS[v1]; \
[0:v]trim=10:30,setpts=PTS-STARTPTS[v2]; \
[0:v]trim=start=30,setpts=PTS-STARTPTS[v3]; \
[0:a]atrim=0:10,asetpts=PTS-STARTPTS[a1]; \
[0:a]atrim=10:30,asetpts=PTS-STARTPTS[a2]; \
[0:a]atrim=start=30,asetpts=PTS-STARTPTS[a3]; \
[v2]setpts=PTS/0.5[slowv]; \
[a2]atempo=0.5[slowa]; \
[v1][a1][slowv][slowa][v3][a3]concat=n=3:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" output.mp4
slowmoVideo
Alternatively you could try slowmoVideo which will probably result in a better looking slowdown effect compared to ffmpeg alone (slowmoVideo uses ffmpeg). It also allows you to use Bézier curves to plot the effect so you can smoothly initiate the effect, and it can include motion blur.