3

As titles says, I want to extract certain frame from video file. Now I can use FFmpeg command line tool to do that.

ffmpeg -i in_video.avi -vf "select=gte(n\,100)" -vframes 1 out_img.png

However I can not use FFmpeg command line tool directly. So can I extract specific frame in C/C++ ?

0

2 Answers 2

4

Here is a sample from FFmpeg to decode a video. Just modify it so that instead of all frames being written to the output video file, you just seek to the position of the needed frame and then decode that single frame and write it to a file. For seeking take a look at av_seek_frame. The trick with seeking is that it requires pts but you can get the pts from the frame index by taking the time base of the stream and multiplying with the frame index.

0
0

I had this same problem and it took me a lot of work, but I have now implemented a frame extraction function in C++ directly using the ffmpeg libraries (within the QT Framework, but it should still help for plain C++).

See the function QImage Video::ffmpegLib_captureAt(const int percent, const int ofDuration) in my project Video simili duplicate cleaner Video.cpp file, it should be a self explanatory example : https://github.com/theophanemayaud/video-simili-duplicate-cleaner/blob/master/QtProject/app/video.cpp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.