while(av_read_frame(m_pFormatCtx, &m_sPacket) >= 0) { if(m_sPacket.stream_index == m_lVideoStream) { int fDecodedFrame = 0; avcodec_decode_video(m_pVideoCodecCtx, m_pFrame, &fDecodedFrame, m_sPacket.data, m_sPacket.size); if(fDecodedFrame) { TRACE(DbgPlugins, "Decoded frame %d\n", m_pFrame->display_picture_number); /* Enqueue frame */ /* Copy data and specs from m_pFrame into our CFrame */ ColorModel eCM = ConvertPixFmt(m_pVideoCodecCtx->pix_fmt); CFrame *pFrame = new CFrame(m_pFrame->display_picture_number); // Force converstion ... while we say YV12, just go to RGB right now for testing if(1 || eCM == CM_UNKNOWN) { /* Convert image to YV12 */ m_pFrameYV12 = avcodec_alloc_frame(); avpicture_fill((AVPicture *)m_pFrameYV12, m_pYV12Buffer, PIX_FMT_RGB24, m_pVideoCodecCtx->width, m_pVideoCodecCtx->height); img_convert((AVPicture *)m_pFrameYV12, PIX_FMT_RGB24, (AVPicture *)m_pFrame, m_pVideoCodecCtx->pix_fmt, m_pVideoCodecCtx->width, m_pVideoCodecCtx->height); eCM = CM_YV12; } else { m_pFrameYV12 = m_pFrame; } pFrame->CopyToBuffer(m_pFrameYV12->data[0], m_ulYV12BufferSize); pFrame->SetDimensions(m_pVideoCodecCtx->width, m_pVideoCodecCtx->height); pFrame->SetColorModel(eCM); pFrame->SetPitch(m_pFrameYV12->linesize[0]); if(m_pFrameYV12 != m_pFrame) free(m_pFrameYV12); m_pFrameYV12 = NULL; if(m_pFrameQueue->Count() > FRAMES_TO_BUFFER) delete m_pFrameQueue->Dequeue(); m_pFrameQueue->Append(pFrame); // Break out of the loop av_free_packet(&m_sPacket); break; } } av_free_packet(&m_sPacket); }