2016-02-28 18 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完成相框後不允許刪除包。 取而代之,我必須在完成視頻後將其刪除。

感謝您的猜測克與我!