Changes between Version 16 and Version 17 of How to speed up / slow down a video
- Timestamp:
- Feb 11, 2021, 9:57:01 AM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
How to speed up / slow down a video
v16 v17 1 1 = Speeding up/slowing down video = 2 2 3 You can change the speed of a video stream using the [http://ffmpeg.org/ffmpeg-all.html#setpts_002c-asetpts setpts] video filter. Note that in the following examples, the audio stream is not changed, so it should ideally be disabled with `-an`.3 The speed of a video stream can be changed by changing the presentation timestamp (PTS) of each video frame. This can be done via two methods: using the [http://ffmpeg.org/ffmpeg-all.html#setpts_002c-asetpts setpts] video filter (which requires re-encoding) or by erasing the timestamps by exporting the video to a raw bitstream format and muxing to a container while creating new timestamps. 4 4 5 To double the speed of the video, you can use: 5 Note that in the following examples, the audio stream is not changed, so it should ideally be disabled with `-an`. 6 7 == raw bitstream method == 8 9 This method is lossless and apart from changing the timestamps, copies the video stream as-is. Use this if you require no other changes to your input video. 10 11 First, copy the video to a raw bitstream format. 12 13 For H.264: 14 {{{ 15 ffmpeg -i input.mp4 -map 0:v -c:v copy -bsf:v h264_mp4toannexb raw.h264 16 }}} 17 18 For H.265: 19 {{{ 20 ffmpeg -i input.mp4 -map 0:v -c:v copy -bsf:v hevc_mp4toannexb raw.h265 21 }}} 22 23 Then generate new timestamps while muxing to a container: 24 {{{ 25 ffmpeg -fflags +genpts -r 30 -i raw.h264 -c:v copy output.mp4 26 }}} 27 28 Change the value of `-r` to the desired playback frame rate. 29 30 == setpts filter == 31 32 To double the speed of the video with the setpts filter, you can use: 6 33 {{{ 7 34 ffmpeg -i input.mkv -filter:v "setpts=0.5*PTS" output.mkv … … 20 47 }}} 21 48 22 == Smooth==49 === Smooth === 23 50 24 51 You can smooth out slow/fast video with the [http://ffmpeg.org/ffmpeg-filters.html#minterpolate minterpolate] video filter. This is also known as "motion interpolation" or "optical flow".
