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 ?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With