[FFmpeg-devel] [PATCH] h264 parser: detect new extradata on frame parsing.

Hendrik Leppkes h.leppkes at gmail.com
Wed Jul 23 16:05:43 CEST 2014


Am 23.07.2014 15:49 schrieb "Benoit Fouet" <benoit.fouet at free.fr>:
>
> Try to detect new extradata when parsing frames, and decode it.
> Fixes issue #3787
> ---
>  libavcodec/h264_parser.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>
> diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
> index ea0ab98..c8276a7 100644
> --- a/libavcodec/h264_parser.c
> +++ b/libavcodec/h264_parser.c
> @@ -489,6 +489,40 @@ static int h264_parse(AVCodecParserContext *s,
>          }
>      }
>
> +    /* See if this is extradata */
> +    if (h->is_avc &&
> +        buf_size >= 9 &&
> +        buf[0] == 1 &&
> +        (buf[4] & 0xFC) == 0xFC &&
> +        (buf[5] & 0x1F) &&
> +        buf[8] == 0x67) {
> +
> +        /* Skip the SPSs */
> +        int cnt = buf[5] & 0x1f;
> +        const uint8_t *p = buf + 6;
> +        while (cnt--) {
> +            int nalsize = AV_RB16(p) + 2;
> +            if (nalsize > buf_size - (p - buf) || p[2] != 0x67)
> +                goto not_extra;
> +            p += nalsize;
> +        }
> +
> +        /* Skip the PPSs */
> +        cnt = *p++;
> +        if (!cnt)
> +            goto not_extra;
> +        while (cnt--) {
> +            int nalsize = AV_RB16(p) + 2;
> +            if (nalsize > buf_size - (p - buf) || p[2] != 0x68)
> +                goto not_extra;
> +            p += nalsize;
> +        }
> +
> +        /* Decode (new) extradata */
> +        return ff_h264_decode_extradata(h, buf, buf_size);
> +    }
> +
> +not_extra:
>      parse_nal_units(s, avctx, buf, buf_size);
>
>      if (h->sei_cpb_removal_delay >= 0) {
> --
> 2.0.1.442.g7fe6834
>

Having AVC style extradata in the middle of a stream seems like an invalid
file. The stream should only include NALUs, with start code or with size
prefix, but not random extra data.

I'm not liking such a hack, especially in the parser, as the decoder and
parser could even use separate context (parsing is typically done in the
demuxing step)

- Hendrik


More information about the ffmpeg-devel mailing list