[FFmpeg-devel] Two problems with MPEG2 decoder

Michael Niedermayer michaelni at gmx.at
Tue Feb 26 21:42:54 CET 2013

On Tue, Feb 26, 2013 at 07:18:00PM +0000, Joseph Artsimovich wrote:
> On 26/02/2013 18:40, Michael Niedermayer wrote:
> >...
> >fixed
> >the is_d10 variable could be renamed now though ...
> Thanks.
> >>2. One of the frames fails to decode.
> >>The frame in question is frame 16 (counting from 0, ignoring the
> >>edit list and 2 initial B-frames that can't be decoded as the stream
> >>is open GOP).
> >>If you use ffmpeg to convert the file to another format:
> >>ffmpeg -i segment.mov -an -vcodec qtrle out.mov
> >>You'll get a duplicated frame in positions 16 and 17.
> >>Now, it turns out the frame that fails to decode has a redundant
> >>(and probably invalid) second picture header in MPEG2 stream. That
> >>is, the frame is encoded as a single picture, yet it has 2 picture
> >>headers. If I modify the code to ignore the second picture header,
> >>like this:

> >>         case PICTURE_START_CODE:
> >>+            if (picture_start_code_seen) {
> >>+               break;
> >>+            } else {
> >>+               picture_start_code_seen = 1;
> >>+            }

this breaks fate

> >>[in decode_chunks() in mpeg12.c; variable initialization not shown]
> >>Then the frame in question decodes fine.
> >>The code above is again just a hack, as a frame can be encoded with
> >>more than one pictures.
> >is it just one frame in the video or does the original full video
> >have more with this issue ?
> The original file of about 45min had somewhere between 5 and 10 of
> frames like that. Sure, those frames may be technically broken, but
> I believe we should try to handle them anyway, because:
> 1. Other software does handle them. The original file came from a
> broadcaster, so I expect a wide range of software and hardware being
> able to handle them.
> 2. Currently the failure to decode such a frame doesn't get reported
> through the API. When I use the CLI ffmpeg executable to convert
> such a file, I get a duplicated frame. When I use FFMpeg's C API
> (through libquicktime in this case), I get a frame shift, which is
> even worse. If for one or another reason it's not possible to decode
> such a frame, I'd like to get an error back, at least.

you can try: (if it works it could be tried to limit it to the kind
of videos that actually need it)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 137f79b..4a51581 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1562,6 +1562,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
         st->need_parsing = AVSTREAM_PARSE_FULL;
         st->need_parsing = AVSTREAM_PARSE_FULL;
     case AV_CODEC_ID_VC1:


Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130226/7239f92d/attachment.asc>

More information about the ffmpeg-devel mailing list