我使用ffmpeg的MPEG4解码器。该译码器具有CODEC_CAP_DELAY等性能。这意味着解码器将给我解码帧的延迟为1帧。
我有一组来自AVI文件的MPEG4 (I& P- )帧和使用这些帧的feed ffmpeg解码器。对于第一个I帧解码器,我什么也没有,但是成功地解码了这些帧。我可以强迫解码器使用avcodec_decode_video2的第二次调用获得解码帧,并提供空(刷新它),但如果我这样做,我得到的第一组图片的伪像(例如,第二个解码的P-帧是灰色)。
如果我现在不强迫ffmpeg解码器给我解码帧,那么它的工作是完美无缺的,没有工件。
问题:,但是在不给解码器下一个帧和没有伪影的情况下,是否有可能得到解码帧?
关于如何为每一帧实现解码的一个小例子:
// decode
int got_frame = 0;
int err = 0;
int tries = 5;
do
{
err = avcodec_decode_video2(m_CodecContext, m_Frame, &got_frame, &m_Packet);
/* some codecs, such as MPEG, transmit the I and P frame with a
latency of one frame. You must do the following to have a
chance to get the last frame of the video */
m_Packet.data = NULL;
m_Packet.size = 0;
--tries;
}
while (err >= 0 && got_frame == 0 && tries > 0);但就像我说的那样,这给了我第一个共和党的手工艺品。
发布于 2015-04-16 14:21:42
使用"-flags +low_delay“选项(或在代码中设置AVCodecContext.flags |= CODEC_FLAG_LOW_DELAY)。
发布于 2021-07-02 16:34:51
我测试了几个选项,"-flags low_delay“和"-probesize 32”比其他选项更重要。贝娄密码对我有用。
AVDictionary* avDic = nullptr;
av_dict_set(&avDic, "flags", "low_delay", 0);
av_dict_set(&avDic, "probesize", "32", 0);
const int errorCode = avformat_open_input(&pFormatCtx, mUrl.c_str(), nullptr, &avDic);https://stackoverflow.com/questions/29675479
复制相似问题