problem: FFMPEG seeking with av_seek_frame using byte positions(问题:FFMPEG 使用 av_seek_frame 使用字节位置进行搜索)
问题描述
我试图让 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.
推荐答案
对于那些有兴趣的人,我找到了解决方案.经过数小时的谷歌搜索和一些简单的逆向工程,我找到了如何获取和设置打开视频的字节位置.
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.
亲切的问候,尼克·维林登
Kind Regards, Nick Verlinden
这篇关于问题:FFMPEG 使用 av_seek_frame 使用字节位置进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:问题:FFMPEG 使用 av_seek_frame 使用字节位置进行搜索


- Stroustrup 的 Simple_window.h 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- C++ 协变模板 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 静态初始化顺序失败 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01