[FFmpeg-devel] [PATCH] h264 parser: detect new extradata on frame parsing.
Benoit Fouet
benoit.fouet at free.fr
Wed Jul 23 15:49:43 CEST 2014
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
More information about the ffmpeg-devel
mailing list