problem: FFMPEG seeking with av_seek_frame using byte positions

本小妞迷上赌 提交于 2019-11-30 02:06:48

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

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!