Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's right way to change playback speed with ffmpeg?

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 ?

like image 965
user2440195 Avatar asked May 21 '15 10:05

user2440195


People also ask

Why is Ffmpeg so slow?

If your CPU usage is still low after FFmpeg has managed to seek to the defined point in the video, it's likely due to one or more of the filters you're using. Some filters may not be able to use all the available CPU threads, and some filters aren't even multi-threaded.


2 Answers

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.

like image 99
occvtech Avatar answered Oct 16 '22 20:10

occvtech


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
    
like image 5
Temak Avatar answered Oct 16 '22 18:10

Temak