[FFmpeg-devel] [PATCH]: Fix decoding of mpegts streams with h264 video that does *NOT* have b frames

Michael Niedermayer michaelni at gmx.at
Sun May 1 04:37:28 CEST 2011


On Thu, Apr 28, 2011 at 10:14:26AM -0400, Mike Scheutzow wrote:
> Tony Strauss wrote:
>> ...
>>
>> Basically, the earlier patch made h264_parse() invoke
>> ff_h264_decode_extradata() the first time through.  The problem,
>> however, is that the H264Context that was passed in belongs to the
>> AVCodecParserContext and is uninitialized.  In particular, low_delay =
>> 0 and that eventually leads to has_b_frames = 1.  My fix is to split
>> off a new ff_h264_context_init() function from ff_h264_decode_init();
>> this will initialize the AVCodecParserContext's H264Context and also
>> invoke ff_h264_decode_extradata().
>>
>> ...
>
> This problem was more difficult to solve than I expected. I've attached  
> a patch which takes a different approach than Tony's patch.
>
> One of the causes of this bug is that the h264 parser defaults low_delay  
> to 1, but the h264 codec defaults low_delay to 0. Really Ugly.
>
> After many hours of looking at this, I'm still not sure how has_b_frames  
> is *intended* to behave, but to me the implementation appears way more  
> complicated than it ought to be.
>
> My patch relies on the encoder to set an optional field in the SPS. This  
> works for libx264 streams, but I'm not sure that all h264 encoders will  
> set it.
>
>
> Mike Scheutzow
>
> P.S. Tony: did you try '-vcodec copy'? For me, your patch crashes with a  
> null ptr exception.

>  h264.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 277d629a82822796a0bc90413edbb1e808382af8  fix-no-b-v2.patch
> diff --git a/libavcodec/h264.c b/libavcodec/h264.c
> index 6cd597e..a40afbc 100644
> --- a/libavcodec/h264.c
> +++ b/libavcodec/h264.c
> @@ -3413,7 +3413,8 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
>              init_get_bits(&s->gb, ptr, bit_length);
>              ff_h264_decode_seq_parameter_set(h);
>  
> -            if(s->flags& CODEC_FLAG_LOW_DELAY)
> +            if(s->flags& CODEC_FLAG_LOW_DELAY ||
> +              (h->sps.bitstream_restriction_flag && !h->sps.num_reorder_frames))

applied & pushed
thx

[..]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 
-------------- 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/20110501/68b51cbb/attachment.asc>


More information about the ffmpeg-devel mailing list