[FFmpeg-devel] [PATCH]: Fix decoding of mpegts streams with h264 video that does *NOT* have b frames
Tony Strauss
tony at animoto.com
Thu Apr 28 17:29:07 CEST 2011
On Thu, Apr 28, 2011 at 10:14 AM, Mike Scheutzow <
mike.scheutzow at alcatel-lucent.com> wrote:
> 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.
>
> 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))
> s->low_delay=1;
>
> if(avctx->has_b_frames < 2)
>
Interesting. I actually had been testing in a -vcodec copy like context (w/
one of my programs that uses libav*), but I had the codec open in that
context, so I never the crash case. I've attached a revised patch that
fixes the crash case: one-line change to common_init in h264.c
For what it's worth, both patches seem like good ideas to me.
Tony
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_mpegts_h264_pts_dts_take_2.patch
Type: application/octet-stream
Size: 3604 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110428/cb52e0a1/attachment.obj>
More information about the ffmpeg-devel
mailing list