ffmpegseeklibavcodecfseeklibavformat

Seeking by bytes in FFmpeg


I'am developing a video converter which based on FFmpeg's libavformat, and I need to implement an accurate seeking API. First of all, I developed an indexer of video stream which just saves a presentation timestamps(PTS) of every packet. And then my encoder uses this index to seek the video file. Before this operations, I remux file to mp4 container, for example. Remux is needed for videos which have no correct index inside, or video has no index at all. I need to implement seeking by bytes, of course with previously built index. I tried many ways to implement this, but without any success. Maybe you know how to implement an accurate seeking by bytes in FFmpeg? Best regards.


Solution

  • Yury! You must seek until you meet the correct frame in the GOP area in where is destination frame. Before that you have to decode two both GOP in where are first frame and last frame of segment and save their positions. This position values will use finding your correct frames.

    I've found that matters in two years ago. If you don't have correct understood, I'll give you new algorithm. Best regards.