2
我有一個代碼,(應)給我使用ffmpeg每次調用另一幀。我的問題是,它始終是相同的幀,我解碼...C++ 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一個missunderstanding,但我不能幫助自己:(
感謝您的幫助
如果它總是幀,它應該在for循環中......你確定要訪問'rgbFrame-> data [0]'有史以來的時間嗎? – hgiesel
我認爲,該rgbFrame只在我的視頻幀,而不是一個視頻序列 – 3DExtended
所有其他數據項爲零,所以這不是問題 – 3DExtended