问题:FFMPEG寻找与av_seek_frame使用字节位置 [英] problem: FFMPEG seeking with av_seek_frame using byte positions
问题描述
我试图让av_seek_frame()函数去到我指定的字节位置。我为我的应用程序实现帧精确寻找机制,并且我的方式,我将扫描整个视频文件,并存储每个关键帧在一个结构中的字节位置。我发现在哪里得到当前字节位置:AVPacket.pos。我现在用 av_seek_frame
测试这个位置:
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 see it, I will scan the entire video file, and store byte positions for each keyframe in a struct. I found out where to get the current byte position: AVPacket.pos. I now test this position with av_seek_frame
like this:
av_seek_frame( pFormatCtx, videoStream, 110285594, AVSEEK_FLAG_BYTE);
< av_read_frame ,它只是从第23帧开始。如果我不搜索,它从第1帧开始。
However, this does not seem to do the right thing, when I call av_read_frame
, it just starts with frame 23. If I do not seek, it starts at frame 1.
推荐答案
对于那些有兴趣的人,我找到了解决方案。经过几个小时的googling和一些简单形式的逆向工程,我找到了如何获取和设置打开的视频的字节位置。
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.
获得文件位置:
AVFormatContext.pb.pos
To get the file position: AVFormatContext.pb.pos
例如:
int64_t byteposition = pFormatCtx->pb->pos;
设置文件位置:
url_seek(AVFormatContext.pb,Position,SEEK_SET);
To set the file position: url_seek(AVFormatContext.pb, Position, SEEK_SET);
例如:
url_seek(pFormatCtx->pb, 27909056, SEEK_SET);
如果在播放时更改位置,请不要忘记刷新缓冲区。如果你在第一次执行av_read_frame之前执行此操作,则无需刷新。
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.
种类:
Nick Verlinden
Kind Regards, Nick Verlinden
这篇关于问题:FFMPEG寻找与av_seek_frame使用字节位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!