aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2012-09-26 12:13:53 +0200
committerAnton Khirnov <anton@khirnov.net>2013-11-14 18:59:39 +0100
commitecf442a58b09bdb1dc1d2c3904b82ac5f79b2878 (patch)
treeb82cc9d1c164106eac10095d6c92994811787f1a
parent951d819006730145255333749367c4ea722ffd9b (diff)
downloadffmpeg-ecf442a58b09bdb1dc1d2c3904b82ac5f79b2878.tar.gz
lavf: improve support for AVC-Intra files.
Generate extradata with SPS/PPS based on container dimensions. Authors of this commit are: Reimar and Thomas Mundt Signed-off-by: Anton Khirnov <anton@khirnov.net>
-rw-r--r--libavformat/internal.h6
-rw-r--r--libavformat/isom.c1
-rw-r--r--libavformat/isom.h16
-rw-r--r--libavformat/mov.c8
-rw-r--r--libavformat/mxfdec.c14
-rw-r--r--libavformat/utils.c102
6 files changed, 143 insertions, 4 deletions
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 1bc3e51761..e92f476f50 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -339,4 +339,10 @@ enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag);
*/
enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags);
+/**
+ * Generate standard extradata for AVC-Intra based on width/height and field
+ * order.
+ */
+int ff_generate_avci_extradata(AVStream *st);
+
#endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/isom.c b/libavformat/isom.c
index 372e877ff0..9b32b7dc57 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -152,6 +152,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/isom.h b/libavformat/isom.h
index 94f1296a1d..bf0792c324 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -195,6 +195,22 @@ void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
#define MOV_TKHD_FLAG_IN_PREVIEW 0x0004
#define MOV_TKHD_FLAG_IN_POSTER 0x0008
+#define TAG_IS_AVCI(tag) \
+ ((tag) == MKTAG('a', 'i', '5', 'p') || \
+ (tag) == MKTAG('a', 'i', '5', 'q') || \
+ (tag) == MKTAG('a', 'i', '5', '2') || \
+ (tag) == MKTAG('a', 'i', '5', '3') || \
+ (tag) == MKTAG('a', 'i', '5', '5') || \
+ (tag) == MKTAG('a', 'i', '5', '6') || \
+ (tag) == MKTAG('a', 'i', '1', 'p') || \
+ (tag) == MKTAG('a', 'i', '1', 'q') || \
+ (tag) == MKTAG('a', 'i', '1', '2') || \
+ (tag) == MKTAG('a', 'i', '1', '3') || \
+ (tag) == MKTAG('a', 'i', '1', '5') || \
+ (tag) == MKTAG('a', 'i', '1', '6') || \
+ (tag) == MKTAG('A', 'V', 'i', 'n'))
+
+
int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom);
enum AVCodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index d9cb36b67a..99ba23fafd 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2142,6 +2142,14 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc->time_scale*st->nb_frames, st->duration, INT_MAX);
}
+ // done for ai5q, ai52, ai55, ai1q, ai12 and ai15.
+ if (!st->codec->extradata_size && st->codec->codec_id == AV_CODEC_ID_H264 &&
+ TAG_IS_AVCI(st->codec->codec_tag)) {
+ ret = ff_generate_avci_extradata(st);
+ if (ret < 0)
+ return ret;
+ }
+
switch (st->codec->codec_id) {
#if CONFIG_H261_DECODER
case AV_CODEC_ID_H261:
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 3fcdb8220f..a947c6794d 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1466,10 +1466,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
/* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */
codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->essence_codec_ul);
st->codec->codec_id = codec_ul->id;
- if (descriptor->extradata) {
- st->codec->extradata = descriptor->extradata;
- st->codec->extradata_size = descriptor->extradata_size;
- }
+
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
source_track->intra_only = mxf_is_intra_only(descriptor);
container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, essence_container_ul);
@@ -1555,6 +1552,15 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
st->need_parsing = AVSTREAM_PARSE_FULL;
}
}
+ if (descriptor->extradata) {
+ st->codec->extradata = av_mallocz(descriptor->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (st->codec->extradata)
+ memcpy(st->codec->extradata, descriptor->extradata, descriptor->extradata_size);
+ } else if (st->codec->codec_id == AV_CODEC_ID_H264) {
+ ret = ff_generate_avci_extradata(st);
+ if (ret < 0)
+ return ret;
+ }
if (st->codec->codec_type != AVMEDIA_TYPE_DATA && (*essence_container_ul)[15] > 0x01) {
/* TODO: decode timestamps */
st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index bec70a9e01..6193d32f03 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3264,3 +3264,105 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
}
return 0;
}
+
+int ff_generate_avci_extradata(AVStream *st)
+{
+ static const uint8_t avci100_1080p_extradata[] = {
+ // SPS
+ 0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
+ 0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
+ 0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
+ 0x18, 0x21, 0x02, 0x56, 0xb9, 0x3d, 0x7d, 0x7e,
+ 0x4f, 0xe3, 0x3f, 0x11, 0xf1, 0x9e, 0x08, 0xb8,
+ 0x8c, 0x54, 0x43, 0xc0, 0x78, 0x02, 0x27, 0xe2,
+ 0x70, 0x1e, 0x30, 0x10, 0x10, 0x14, 0x00, 0x00,
+ 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xca,
+ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ // PPS
+ 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
+ 0xd0
+ };
+ static const uint8_t avci100_1080i_extradata[] = {
+ // SPS
+ 0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 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,
+ 0x00, 0x08, 0x00, 0x00, 0x03, 0x01, 0x94, 0x00,
+ // PPS
+ 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
+ 0xd0
+ };
+ static const uint8_t avci50_1080i_extradata[] = {
+ // SPS
+ 0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x28,
+ 0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
+ 0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
+ 0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6e, 0x61,
+ 0x87, 0x3e, 0x73, 0x4d, 0x98, 0x0c, 0x03, 0x06,
+ 0x9c, 0x0b, 0x73, 0xe6, 0xc0, 0xb5, 0x18, 0x63,
+ 0x0d, 0x39, 0xe0, 0x5b, 0x02, 0xd4, 0xc6, 0x19,
+ 0x1a, 0x79, 0x8c, 0x32, 0x34, 0x24, 0xf0, 0x16,
+ 0x81, 0x13, 0xf7, 0xff, 0x80, 0x01, 0x80, 0x02,
+ 0x71, 0x80, 0x80, 0x80, 0xa0, 0x00, 0x00, 0x03,
+ 0x00, 0x20, 0x00, 0x00, 0x06, 0x50, 0x80, 0x00,
+ // PPS
+ 0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
+ 0x11
+ };
+ static const uint8_t avci100_720p_extradata[] = {
+ // SPS
+ 0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
+ 0xb6, 0xd4, 0x20, 0x2a, 0x33, 0x1d, 0xc7, 0x62,
+ 0xa1, 0x08, 0x40, 0x54, 0x66, 0x3b, 0x8e, 0xc5,
+ 0x42, 0x02, 0x10, 0x25, 0x64, 0x2c, 0x89, 0xe8,
+ 0x85, 0xe4, 0x21, 0x4b, 0x90, 0x83, 0x06, 0x95,
+ 0xd1, 0x06, 0x46, 0x97, 0x20, 0xc8, 0xd7, 0x43,
+ 0x08, 0x11, 0xc2, 0x1e, 0x4c, 0x91, 0x0f, 0x01,
+ 0x40, 0x16, 0xec, 0x07, 0x8c, 0x04, 0x04, 0x05,
+ 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03,
+ 0x00, 0x64, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
+ // PPS
+ 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x31, 0x12,
+ 0x11
+ };
+
+ const uint8_t *data = NULL;
+ int size = 0;
+
+ if (st->codec->width == 1920) {
+ if (st->codec->field_order == AV_FIELD_PROGRESSIVE) {
+ data = avci100_1080p_extradata;
+ size = sizeof(avci100_1080p_extradata);
+ } else {
+ data = avci100_1080i_extradata;
+ size = sizeof(avci100_1080i_extradata);
+ }
+ } else if (st->codec->width == 1440) {
+ data = avci50_1080i_extradata;
+ size = sizeof(avci50_1080i_extradata);
+ } else if (st->codec->width == 1280) {
+ data = avci100_720p_extradata;
+ size = sizeof(avci100_720p_extradata);
+ }
+
+ if (!size)
+ return 0;
+
+ 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 AVERROR(ENOMEM);
+
+ memcpy(st->codec->extradata, data, size);
+ st->codec->extradata_size = size;
+
+ return 0;
+}