problem: FFMPEG seeking with av_seek_frame using byte positions

后端 未结 2 2034
耶瑟儿~
耶瑟儿~ 2020-12-28 09:26

I am trying to get the av_seek_frame() function to go to a byte position I specify. I am implementing a frame accurate seeking mechanism for my application, and the way I se

相关标签:
2条回答
  • 2020-12-28 09:54

    For those who are interested, I found the solution. After hours of googling and some simplistic form of reverse engineering, I found how to get and set the byte location of the open video.

    To get the file position: AVFormatContext.pb.pos

    for example:

    int64_t byteposition = pFormatCtx->pb->pos;
    

    To set the file position: url_seek(AVFormatContext.pb, Position, SEEK_SET);

    for example:

    url_seek(pFormatCtx->pb, 27909056, SEEK_SET);
    

    Don't forget to flush the buffers if you change the location while playing. If you do this before you do av_read_frame for the first time, flushing is not necessary.

    Kind Regards, Nick Verlinden

    0 讨论(0)
  • 2020-12-28 10:04

    In recent versions of libav, url_seek has been made an internal function. One should now use the following function:

    /**
    * fseek() equivalent for AVIOContext.
    * @return new position or AVERROR.
    */
    int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
    
    0 讨论(0)
提交回复
热议问题