[FFmpeg-devel] [PATCH] libavformat/avc.c annexb parsing corrupts packets

Michael Niedermayer michaelni
Fri Aug 14 02:00:07 CEST 2009


4On Mon, Jul 27, 2009 at 05:10:33PM +0200, matteo.elli at m-elli.it wrote:
> Hi,
> 
> code in libavformat/avc.c is seldom executed but it surely does when you transmux (vcodec=copy) from h264 in a ts container to h264 in an mp4/mov/mkv/avi container.
> 
> The code there fails to handle annexb 00 00 01 NAL three byets prefixes properly and cuts the last byte in the previous NAL corrupting the whole frame.
> 
> Here is my proposed fix.
> 
> Index: libavformat/avc.c
> ===================================================================
> --- libavformat/avc.c	(revision 19515)
> +++ libavformat/avc.c	(working copy)
> @@ -39,15 +39,15 @@
>          if( (x - 0x01010101) & (~x) & 0x80808080 ) { // generic
>              if( p[1] == 0 ) {
>                  if( p[0] == 0 && p[2] == 1 )
> -                    return p-1;
> +                    return p;
>                  if( p[2] == 0 && p[3] == 1 )
> -                    return p;
> +                    return p+1;
>              }
>              if( p[3] == 0 ) {
>                  if( p[2] == 0 && p[4] == 1 )
> -                    return p+1;
> +                    return p+2;
>                  if( p[4] == 0 && p[5] == 1 )
> -                    return p+2;
> +                    return p+3;
>              }
>          }
>      }

the code as is in svn is wrong but your change is as well
there can be 0001 and 001 startcodes, the return value has to point
to the first byte of either


> @@ -69,8 +69,9 @@
>      size = 0;
>      nal_start = ff_avc_find_startcode(p, end);
>      while (nal_start < end) {
> -        while(!*(nal_start++));
> +        while(nal_start < end && !*(nal_start++)); if(nal_start == end) break;

what is this?


>          nal_end = ff_avc_find_startcode(nal_start, end);
> +		while(nal_end > nal_start && !*(nal_end - 1)) nal_end--;
>          put_be32(pb, nal_end - nal_start);

tabs are not allowed in svn

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Thouse who are best at talking, realize last or never when they are wrong.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090814/53df20fa/attachment.pgp>



More information about the ffmpeg-devel mailing list