From 1c5f18308c16648341884fe99a98a54413c7c55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20G=C3=BCnther?= Date: Mon, 25 Aug 2014 13:27:57 +0200 Subject: [PATCH] FFMPEG Plugin: Fix correct decoding of first video frame. - The first decoded video frame was always zero bytes large, due to passing the wrong linesize to the color conversion function. The field containing the right linesize (fHeader.u.raw_video.bytes_per_row) simply wasn't initialized yet. Fix it by updating fHeader first before applying deinterlacing and color converting to the decoded video frame. Tested with mpeg2_decoder_test where the first picture now isn't empty (black) anymore. --- .../media/plugins/ffmpeg/AVCodecDecoder.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp b/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp index e3d195e226..3716411d15 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp @@ -1364,8 +1364,8 @@ AVCodecDecoder::_CopyChunkToChunkBufferAndAddPadding(const void* chunk, void AVCodecDecoder::_HandleNewVideoFrameAndUpdateSystemState() { - _DeinterlaceAndColorConvertVideoFrame(); _UpdateMediaHeaderForVideoFrame(); + _DeinterlaceAndColorConvertVideoFrame(); ConvertAVCodecContextToVideoFrameRate(*fContext, fOutputFrameRate); @@ -1444,7 +1444,9 @@ AVCodecDecoder::_UpdateMediaHeaderForVideoFrame() fHeader.file_pos = 0; fHeader.orig_size = 0; fHeader.start_time = fRawDecodedPicture->pkt_dts; - fHeader.size_used = fDecodedDataSizeInBytes; + fHeader.size_used = avpicture_get_size( + colorspace_to_pixfmt(fOutputColorSpace), fRawDecodedPicture->width, + fRawDecodedPicture->height); fHeader.u.raw_video.display_line_width = fRawDecodedPicture->width; fHeader.u.raw_video.display_line_count = fRawDecodedPicture->height; fHeader.u.raw_video.bytes_per_row @@ -1475,8 +1477,12 @@ AVCodecDecoder::_UpdateMediaHeaderForVideoFrame() It is assumed that fRawDecodedPicture wasn't deinterlaced and color converted yet (otherwise this function behaves in unknown manners). + This function MUST be called after _UpdateMediaHeaderForVideoFrame() as it + relys on the fHeader.size_used and fHeader.u.raw_video.bytes_per_row fields + for correct operation + You should only call this function when you got a new picture decoded by - the video decoder.. + the video decoder. When this function finishes the postprocessed video frame will be available in fPostProcessedDecodedPicture and fDecodedData (fDecodedDataSizeInBytes @@ -1526,8 +1532,7 @@ AVCodecDecoder::_DeinterlaceAndColorConvertVideoFrame() } #endif - fDecodedDataSizeInBytes = avpicture_get_size( - colorspace_to_pixfmt(fOutputColorSpace), displayWidth, displayHeight); + fDecodedDataSizeInBytes = fHeader.size_used; if (fDecodedData == NULL) fDecodedData