Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG reading keyframes

I am trying to write a c++ program that would read key frames from the video file using ffmpeg. So far I managed to get all the frames using av_read_frame where you sequentially read frame by frame.

But I having some problems using av_seek_frame which (if I am correct) supposed to do the trick for keyframes.

int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);

I have FormatContext but what are other correct arguments to sequentially get only all keyframes ?

Is there other function that I can use instead?

Thanks

EDIT: In av_read_frame i am getting AVPacket, which I can use to get frame data, but how I can get packet by using av_seek_frame ?

SOLUTION: OK there is a simple boolean value in AVFrame->key_frame. True if its a keyframe

like image 281
kirbo Avatar asked Dec 21 '25 22:12

kirbo


1 Answers

av_seek_frame has the ability to seek to a certain timestamp in a video file. It takes 4 parameters: a pointer to the AVFormatContext, a stream index, the timestamp to seek to and flags to select the direction and seeking mode.

The function will then seek to the first key frame before the given timestamp.

Check the documentation of that function for more information.

like image 98
karlphillip Avatar answered Dec 23 '25 13:12

karlphillip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!