1

I've found many solutions to find the location of keyframes in videos using ffprobe, but all of them are slow, like roughly 0.1x real time on an 8k video.

While this is fine for finding a keyframe near the beginning of a video, I don't want to wait 10 hours to find the position of a keyframe near the 1 hour mark.

Does anyone know of a way to quickly get the location of a keyframe shortly before or after a timestamp?

Example slow answers:

How to get time stamp of closest keyframe before a given timestamp with FFmpeg?
get timestamp of a keyframe exactly before a given timestamp with FFmpeg
Get the list of I-Frames in a video in FFMPEG / Python

1 Answers1

2

The basic command would be of the form

ffprobe -v 0 -of compact=p=0 -select_streams v -show_entries packet=pts_time,flags -read_intervals 2990%3010 "input.mkv" | grep K

In my test file, this prints

pts_time=2988.986000|flags=K__
pts_time=2990.988000|flags=K__
pts_time=2992.990000|flags=K__
pts_time=2994.992000|flags=K__
pts_time=2996.994000|flags=K__
pts_time=2998.996000|flags=K__
pts_time=3000.998000|flags=K__
pts_time=3003.000000|flags=K__
pts_time=3005.002000|flags=K__
pts_time=3007.004000|flags=K__
pts_time=3009.006000|flags=K__

This shows all packets flagged as keyframes within the time range 2990s to 3010s. It starts at 2988s because that's the seek point for 2990s.

This took 160ms to run.

Gyan
  • 38,955