[FFmpeg-devel] [PATCH] Support AVC-Intra in mov.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sat Sep 15 19:01:53 CEST 2012


A separate function is used, since the same code will be used
to support AVC-Intra in MXF (trac ticket #1294).
Currently only AVC-Intra 100 is supported, I do not yet have
the reference SPS/PPS for AVC-Intra 50.
Fixes trac tickets #524.
Ticket #1666 probably requires yet another SPS/PPS set.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
 libavformat/internal.h |    5 +++++
 libavformat/isom.c     |    1 +
 libavformat/mov.c      |    4 ++++
 libavformat/utils.c    |   36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 46 insertions(+)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index cd91eb1..52ecbe7 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -346,4 +346,9 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
 
 void ff_free_stream(AVFormatContext *s, AVStream *st);
 
+/**
+ * Generate standard extradata for AVC-Intra based on width/height.
+ */
+void ff_generate_avci_extradata(AVStream *st);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/isom.c b/libavformat/isom.c
index caa4d17..32fe888 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -165,6 +165,7 @@ const AVCodecTag ff_codec_movvideo_tags[] = {
     { AV_CODEC_ID_H264, MKTAG('a', 'i', '1', '3') }, /* AVC-Intra 100M 1080p24/30/60 */
     { AV_CODEC_ID_H264, MKTAG('a', 'i', '1', '5') }, /* AVC-Intra 100M 1080i50 */
     { AV_CODEC_ID_H264, MKTAG('a', 'i', '1', '6') }, /* AVC-Intra 100M 1080i60 */
+    { AV_CODEC_ID_H264, MKTAG('A', 'V', 'i', 'n') }, /* AVC-Intra with implicit SPS/PPS */
 
     { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', '1') }, /* Apple MPEG-1 Camcorder */
     { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 078bd3f..0b43d17 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2146,6 +2146,10 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 #endif
     }
 
+    if (!st->codec->extradata_size && st->codec->codec_id == AV_CODEC_ID_H264 &&
+        st->codec->codec_tag == MKTAG('A', 'V', 'i', 'n'))
+        ff_generate_avci_extradata(st);
+
     switch (st->codec->codec_id) {
 #if CONFIG_H261_DECODER
     case AV_CODEC_ID_H261:
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 6847091..f7c4fa4 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4669,3 +4669,39 @@ int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
     av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
     return AVERROR(EINVAL);
 }
+
+void ff_generate_avci_extradata(AVStream *st)
+{
+    static const uint8_t avci100_extradata[] = {
+        // SPS
+        0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x00, 0x29,
+        0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
+        0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
+        0x18, 0x21, 0x03, 0x3a, 0x46, 0x65, 0x6a, 0x65,
+        0x24, 0xad, 0xe9, 0x12, 0x32, 0x14, 0x1a, 0x26,
+        0x34, 0xad, 0xa4, 0x41, 0x82, 0x23, 0x01, 0x50,
+        0x2b, 0x1a, 0x24, 0x69, 0x48, 0x30, 0x40, 0x2e,
+        0x11, 0x12, 0x08, 0xc6, 0x8c, 0x04, 0x41, 0x28,
+        0x4c, 0x34, 0xf0, 0x1e, 0x01, 0x13, 0xf2, 0xe0,
+        0x3c, 0x60, 0x20, 0x20, 0x28, 0x00, 0x00, 0x03,
+        // PPS
+        0x00, 0x08, 0x00, 0x00, 0x03, 0x01, 0x94, 0x20,
+        0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x32, 0x48,
+        0x90
+    };
+    int size = 0;
+    const uint8_t *data = 0;
+    if (st->codec->width == 1920) {
+        data = avci100_extradata;
+        size = sizeof(avci100_extradata);
+    }
+    if (!size)
+        return;
+    av_freep(&st->codec->extradata);
+    st->codec->extradata_size = 0;
+    st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
+    if (!st->codec->extradata)
+        return;
+    memcpy(st->codec->extradata, data, size);
+    st->codec->extradata_size = size;
+}
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list