diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2015-11-09 14:24:26 +0100 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2015-11-10 23:27:51 +0100 |
commit | d9726893f311b7bbbc9887db2c3ffbefaad78ca3 (patch) | |
tree | 5967b3b57802fa66df33edd51e39f50a7932c90b /libavformat | |
parent | 3ea60c505f3f6d489d31170d1fb40b4083c5074d (diff) | |
download | ffmpeg-d9726893f311b7bbbc9887db2c3ffbefaad78ca3.tar.gz |
avformat/mxfenc: Only store user comment related tags when needed
Also support disabling them as they seem to cause problems to some
Users. They are also not allowed in IRT D-10 thus the default for
mxf_d10 is not to write them
This also decreases the filesize when no user comment are stored
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/mxfenc.c | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index f2e0e4d7e4..e4e42720fe 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -21,7 +21,8 @@ */ /* - * signal_standard, color_siting and klv_fill_key version fixes sponsored by NOA GmbH + * signal_standard, color_siting, store_user_comments and klv_fill_key version + * fixes sponsored by NOA GmbH */ /* @@ -323,6 +324,7 @@ typedef struct MXFContext { int signal_standard; uint32_t tagged_value_count; AVRational audio_edit_rate; + int store_user_comments; } MXFContext; static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; @@ -380,7 +382,6 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = { { 0x4404, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x05,0x00,0x00}}, /* Package Modified Date */ { 0x4402, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x03,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Package Name */ { 0x4403, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x05,0x00,0x00}}, /* Tracks Strong reference array */ - { 0x4406, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0C,0x00,0x00,0x00}}, /* User Comments */ { 0x4701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x03,0x00,0x00}}, /* Descriptor */ // Track { 0x4801, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x07,0x01,0x01,0x00,0x00,0x00,0x00}}, /* Track ID */ @@ -400,9 +401,6 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = { { 0x1501, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x05,0x00,0x00}}, /* Start Time Code */ { 0x1502, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x04,0x01,0x01,0x02,0x06,0x00,0x00}}, /* Rounded Time Code Base */ { 0x1503, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x04,0x01,0x01,0x05,0x00,0x00,0x00}}, /* Drop Frame */ - // Tagged Value - { 0x5001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x09,0x01,0x00,0x00}}, /* Name */ - { 0x5003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0A,0x01,0x00,0x00}}, /* Value */ // File Descriptor { 0x3F01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x04,0x06,0x0B,0x00,0x00}}, /* Sub Descriptors reference array */ { 0x3006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x06,0x01,0x01,0x03,0x05,0x00,0x00,0x00}}, /* Linked Track ID */ @@ -448,6 +446,12 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = { { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */ }; +static const MXFLocalTagPair mxf_user_comments_local_tag[] = { + { 0x4406, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0C,0x00,0x00,0x00}}, /* User Comments */ + { 0x5001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x09,0x01,0x00,0x00}}, /* Name */ + { 0x5003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0A,0x01,0x00,0x00}}, /* Value */ +}; + static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value) { avio_write(pb, uuid_base, 12); @@ -525,10 +529,12 @@ static int mxf_get_essence_container_ul_index(enum AVCodecID id) static void mxf_write_primer_pack(AVFormatContext *s) { + MXFContext *mxf = s->priv_data; AVIOContext *pb = s->pb; int local_tag_number, i = 0; local_tag_number = FF_ARRAY_ELEMS(mxf_local_tag_batch); + local_tag_number += mxf->store_user_comments * FF_ARRAY_ELEMS(mxf_user_comments_local_tag); avio_write(pb, primer_pack_key, 16); klv_encode_ber_length(pb, local_tag_number * 18 + 8); @@ -536,10 +542,15 @@ static void mxf_write_primer_pack(AVFormatContext *s) avio_wb32(pb, local_tag_number); // local_tag num avio_wb32(pb, 18); // item size, always 18 according to the specs - for (i = 0; i < local_tag_number; i++) { + for (i = 0; i < FF_ARRAY_ELEMS(mxf_local_tag_batch); i++) { avio_wb16(pb, mxf_local_tag_batch[i].local_tag); avio_write(pb, mxf_local_tag_batch[i].uid, 16); } + if (mxf->store_user_comments) + for (i = 0; i < FF_ARRAY_ELEMS(mxf_user_comments_local_tag); i++) { + avio_wb16(pb, mxf_user_comments_local_tag[i].local_tag); + avio_write(pb, mxf_user_comments_local_tag[i].uid, 16); + } } static void mxf_write_local_tag(AVIOContext *pb, int size, int tag) @@ -1253,14 +1264,15 @@ static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type, int user_comment_count = 0; if (type == MaterialPackage) { - user_comment_count = mxf_write_user_comments(s, s->metadata); + if (mxf->store_user_comments) + user_comment_count = mxf_write_user_comments(s, s->metadata); mxf_write_metadata_key(pb, 0x013600); PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16); - klv_encode_ber_length(pb, 104 + name_size + (16*track_count) + (16*user_comment_count)); + klv_encode_ber_length(pb, 92 + name_size + (16*track_count) + (16*user_comment_count) + 12*mxf->store_user_comments); } else { mxf_write_metadata_key(pb, 0x013700); PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16); - klv_encode_ber_length(pb, 124 + name_size + (16*track_count)); // 20 bytes length for descriptor reference + klv_encode_ber_length(pb, 112 + name_size + (16*track_count) + 12*mxf->store_user_comments); // 20 bytes length for descriptor reference } // write uid @@ -1295,10 +1307,12 @@ static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type, mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, i); // write user comment refs - mxf_write_local_tag(pb, user_comment_count*16 + 8, 0x4406); - mxf_write_refs_count(pb, user_comment_count); - for (i = 0; i < user_comment_count; i++) - mxf_write_uuid(pb, TaggedValue, mxf->tagged_value_count - user_comment_count + i); + if (mxf->store_user_comments) { + mxf_write_local_tag(pb, user_comment_count*16 + 8, 0x4406); + mxf_write_refs_count(pb, user_comment_count); + for (i = 0; i < user_comment_count; i++) + mxf_write_uuid(pb, TaggedValue, mxf->tagged_value_count - user_comment_count + i); + } // write multiple descriptor reference if (type == SourcePackage) { @@ -2038,6 +2052,9 @@ static int mxf_write_header(AVFormatContext *s) return -1; } + if (!av_dict_get(s->metadata, "comment_", NULL, AV_DICT_IGNORE_SUFFIX)) + mxf->store_user_comments = 0; + for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; MXFStreamContext *sc = av_mallocz(sizeof(*sc)); @@ -2656,6 +2673,8 @@ static int mxf_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int static const AVOption mxf_options[] = { MXF_COMMON_OPTIONS + { "store_user_comments", "", + offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, { NULL }, }; @@ -2670,6 +2689,8 @@ static const AVOption d10_options[] = { { "d10_channelcount", "Force/set channelcount in generic sound essence descriptor", offsetof(MXFContext, channel_count), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 8, AV_OPT_FLAG_ENCODING_PARAM}, MXF_COMMON_OPTIONS + { "store_user_comments", "", + offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, { NULL }, }; |