I am attempting to seek in a movie using ffmpeg's av_seek_frame method however I'm having the most trouble determining how to generate a time-stamp to seek to. Assuming I want to seek x amount of frames either forward or backward and I know what frame the movie is currently on, how would I go about doing this?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
Simple answer: You should have an AVFormatContext object lying around. Its
duration
property tells you how long your file is in terms of the time-stamp multiplied by 1000 that can be used in av_seek_frame, so treat it as 100%. Then you can calculate how far into the video you want to seek to.if you want to go forward one frame, simply call av_read_frame and avcodec_decode_video until it fills the got_picture_ptr with a non-zero value. Before calling avcodec_decode_video make sure the packet from av_read_frame is from the video stream. avcodec_decode_video will then fill in the AVFrame structure which you can use to do anything with.
Here is how i did it:
The AVSEEK_FLAG_ANY enables seeking to every frame and not just keyframes.