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 使用字节位置进行搜索


基础教程推荐
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01