What's the correct way to change the playback speed using ffmpeg?

In my project I am using ffmpeg to play media. I am currently trying to implement changing the playback speed. Is it correct to drop certain packets at a high rate, such as non- keyframes? Or should I only rely on changing the timestamps and duration, even if the performance is low (e.g. 4k video) and as a result the increased speed is not noticeable?

+3


source to share


2 answers


If your file contains standard PTS reference information, I think the best way to change the playback speed would be to use a filter setpts

.

For example, to speed up a video with x2 try:



ffplay [INPUT] -vf setpts=0.5*PTS

The filter works in FFmpeg

.

+6


source


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 input.

To save all frames and just quadruple the frame rate and speed as a consequence of exec:

ffmpeg -i input.mkv -r NEW_FPS -filter:v "setpts=0.25*PTS" output.mkv

      



Where NEW_FPS = old_fps * 4

  • To check your frame rate: ffprobe video_name

  • To check the 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
    
          

+2


source







All Articles