C++ ffmpeg : always the same frame?

标签 c++ ffmpeg

我有一个代码,它(应该)为每次使用 ffmpeg 的调用提供另一个帧。我的问题是,我解码的始终是同一帧...

有人可以告诉我,我在这里缺少什么吗?

bool nextFrameFound = false;
while(!nextFrameFound)
{
    AVPacket pkt;

    int err = av_read_frame(ctx, &pkt);
    if (err < 0)
    {
        break;
        system("Pause");
        exit(2);
    }

    if (pkt.stream_index == strm)
    {
        int got = 0;
        AVFrame * frame = av_frame_alloc();
        int videoFrameBytes = avcodec_decode_video2(codecCtx, frame, &got, &pkt);

        if (got)
        {
            AVFrame * rgbFrame = av_frame_alloc();

            avpicture_alloc((AVPicture *)rgbFrame, AV_PIX_FMT_RGB24, codecCtx->width, codecCtx->height);
            sws_scale(swCtx, frame->data, frame->linesize, 0, frame->height, rgbFrame->data, rgbFrame->linesize);

            for (int i = 0; i < codecCtx->height; i++)
            {
                char * data = (char*)rgbFrame->data[0] + i*rgbFrame->linesize[0];
                //process data

            }
            nextFrameFound = true;
            avcodec_close(codecCtx);

        }

        av_free_packet(&pkt);
    }
}
avformat_network_deinit();

我想,这是对使用 ffmpeg 的误解,但我情不自禁:(

感谢您的帮助!

最佳答案

我找到了解决方案:

我不允许在完成框架后删除包。 相反,我必须在完成视频后将其删除。

谢谢你陪我猜!

关于C++ ffmpeg : always the same frame?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35686762/

相关文章:

c++ - OpenGL绘制一个矩形填充窗口

c++ - 为什么 *must* delete[] 和 delete 是不同的?

c++ - Visual C++ - 以函数作为参数 : change leads to unresolved external 的函数调用

c++ - 使用分隔符一个空格和一个分号读取文件

ffmpeg 和 ffmpeg-php 安装在 Fedora 13 上

ffmpeg - 如何将多个 H.264 流合并为单个 H.264 流

php - ffmpeg 在网络托管服务器中不起作用

C++ MSVS 项目内链接器错误 LNK2019 - 声明定义不匹配?

java - 使用 ffmpeg 从 Red5 转换音频

python - 使用 pydub 导出时出错 - 如何为 pydub 安装 mp3 编解码器?