[英]Problem: av_seek_frame() always returns me the beginning of the video
我目前正在尝试使用 FFMpeg 来构建播放器。 当我使用 av_seek_frame() 更改时间戳时,它总是给我流的开头。
这是我的代码:
bool XDemux::Seek(double pos)
{
mux.lock();
if (!ic)
{
mux.unlock();
return false;
}
avformat_flush(ic);
long long seekPos = 0;
seekPos = ic->streams[videoStream]->duration * pos;
int re = av_seek_frame(ic, videoStream, seekPos, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_FRAME);
mux.unlock();
if (re < 0)
{
return false;
}
return true;
}
其中 ic 和 mux 定义为
AVFormatContext* ic
std::mutex mux;
当我尝试调用 Seek 函数并打印出帧索引时,它将类似于:
//Read() is called:
0 0 21 42 40 ...
//Then Seek(0.9) is called, should have begin with a later frame, but it also returns me:
0 0 21 42 40 ...
av_seek_frame 需要帧中的位置,但您的“seekPos”使用时基。 你需要这样的东西来将流时间转换为帧:
frmseekPos = av_rescale(seekPos, ic->streams[videoStream]->time_base.den, ic->streams[videoStream]->time_base.num);
frmseekPos /= 1000;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.