What's right way to change playback speed with ffmpeg?
Solution 1
If your file contains standard PTS reference information, I think the best way to change back playback speed will be using the setpts
filter.
For example, to speed up the video by x2 try:
ffplay [INPUT] -vf setpts=0.5*PTS
The filter works in FFmpeg
as well.
Solution 2
ffplay [INPUT] -vf setpts=0.5*PTS
will drop frames to achieve the desired speed. You can avoid dropped frames by specifying a higher output frame rate than the input.
To preserve all the frames and just increase the frame rate by 4 times and speed as consequence exec:
ffmpeg -i input.mkv -r NEW_FPS -filter:v "setpts=0.25*PTS" output.mkv
where NEW_FPS = old_fps * 4
To check the frame rate:
ffprobe video_name
To check number of frames:
ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 video_name
user2440195
Updated on June 04, 2022Comments
-
user2440195 about 2 years
In my project i'm using ffmpeg to playback media. Currently I'm trying to implement changing of playback speed. Will it be right to drop certain packets at high rates, for example not keyframes ? Or I should rely only on changing timestamps and duration, even if performance is low(for example 4k video) and as a consequence increased speed isn't noticable ?
-
Kartick Vaddadi over 5 yearsDon't all or most videos have PTS information? If not, how will the video player know when to play each frame?