我有一个代码,它(应该)为每次使用 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/