我有一个代码,(应该)为每个使用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时是一个误会,但我无能为力:(

谢谢你的帮助!

最佳答案

我找到了解决方案:

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

感谢您与我的猜测!

10-08 08:57