2016-02-28 74 views
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,但我不能帮助自己:(

感谢您的帮助

+0

如果它总是帧,它应该在for循环中......你确定要访问'rgbFrame-> data [0]'有史以来的时间吗? – hgiesel

+0

我认为,该rgbFrame只在我的视频帧,而不是一个视频序列 – 3DExtended

+0

所有其他数据项为零,所以这不是问题 – 3DExtended

回答

1

我找到了解决办法:

我m完成相框后不允许删除包。 取而代之,我必须在完成视频后将其删除。

感谢您的猜测克与我!