Search code examples
javaffmpegtimestampjavacvkeyframe

FFmpegFrameGrabber faster SetTimestamp using only Keyframes


i'm using javacv to read mp4 files and the following code to seek the video:

FFmpegFrameGrabber frameGrabber;
[...]
frameGrabber.setTimestamp(timestamp);

The problem is that it takes several seconds for "setTimestamp()" depending on how far away the timestamp is to a keyframe.

I'm searching for an way to do a faster setTimestamp() only seeking to keyframes.

Knowing all keyframe timestamps would be an option but i didn't find any solution for that except reading all KeyFrames and storing the keyframe-timestamps using:

frameGrabber.grabKeyFrame().timestamp

But that takes very long. I also tried to extrapolate the keyframe timestamps but that only works if the keyframe interval is exactly the same over the video file which is usually not the case .

Any ideas for a fast keyframe based setTimestamp/seeking for javacv?

Or do you know a videoplayer gui based on javacv/FFmpegFrameGrabber which has a fast time slider implementation?


Solution

  • ok, i just copied the FFmpegFrameGrabber.java and implemented a additional setTimestamp(long timestamp, boolean useOnlyKeyframes) method without the "//decode up to the desired frame" part and now the seeking is very fast and only to keyframes.