diff --git a/libavformat/asf.c b/libavformat/asf.c index 455ca4d826..719cae9da5 100644 --- a/libavformat/asf.c +++ b/libavformat/asf.c @@ -147,6 +147,14 @@ const ff_asf_guid ff_asf_extended_stream_properties_object = { 0xcb, 0xa5, 0xe6, 0x14, 0x72, 0xc6, 0x32, 0x43, 0x83, 0x99, 0xa9, 0x69, 0x52, 0x06, 0x5b, 0x5a }; +const ff_asf_guid ff_asf_group_mutual_exclusion_object = { + 0x40, 0x5a, 0x46, 0xd1, 0x79, 0x5a, 0x38, 0x43, 0xb7, 0x1b, 0xe3, 0x6b, 0x8f, 0xd6, 0xc2, 0x49 +}; + +const ff_asf_guid ff_asf_mutex_language = { + 0x00, 0x2a, 0xe2, 0xd6, 0xda, 0x35, 0xd1, 0x11, 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe +}; + /* List of official tags at http://msdn.microsoft.com/en-us/library/dd743066(VS.85).aspx */ const AVMetadataConv ff_asf_metadata_conv[] = { { "WM/AlbumArtist", "album_artist" }, diff --git a/libavformat/asf.h b/libavformat/asf.h index 914ddef48e..43288ddbaf 100644 --- a/libavformat/asf.h +++ b/libavformat/asf.h @@ -100,6 +100,8 @@ extern const ff_asf_guid ff_asf_content_encryption; extern const ff_asf_guid ff_asf_ext_content_encryption; extern const ff_asf_guid ff_asf_digital_signature; extern const ff_asf_guid ff_asf_extended_stream_properties_object; +extern const ff_asf_guid ff_asf_group_mutual_exclusion_object; +extern const ff_asf_guid ff_asf_mutex_language; extern const AVMetadataConv ff_asf_metadata_conv[]; diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c index 14f92e258f..66551ea373 100644 --- a/libavformat/asfenc.c +++ b/libavformat/asfenc.c @@ -396,6 +396,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t header_offset, cur_pos, hpos; int bit_rate; int64_t duration; + int audio_language_counts[128] = { 0 }; ff_metadata_conv(&s->metadata, ff_asf_metadata_conv, NULL); @@ -444,6 +445,8 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, asf->streams[n].stream_language_index = asf->nb_languages; asf->nb_languages++; } + if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + audio_language_counts[asf->streams[n].stream_language_index]++; } } else { asf->streams[n].stream_language_index = 128; @@ -484,6 +487,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, if (asf->nb_languages) { int64_t hpos2; int i; + int nb_audio_languages = 0; hpos2 = put_header(pb, &ff_asf_language_guid); avio_wl16(pb, asf->nb_languages); @@ -493,6 +497,25 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, } end_header(pb, hpos2); + for (i = 0; i < asf->nb_languages; i++) + if (audio_language_counts[i]) + nb_audio_languages++; + + if (nb_audio_languages > 1) { + hpos2 = put_header(pb, &ff_asf_group_mutual_exclusion_object); + ff_put_guid(pb, &ff_asf_mutex_language); + avio_wl16(pb, nb_audio_languages); + for (i = 0; i < asf->nb_languages; i++) { + if (audio_language_counts[i]) { + avio_wl16(pb, audio_language_counts[i]); + for (n = 0; n < s->nb_streams; n++) + if (asf->streams[n].stream_language_index == i && s->streams[n]->codec->codec_type == AVMEDIA_TYPE_AUDIO) + avio_wl16(pb, n + 1); + } + } + end_header(pb, hpos2); + } + for (n = 0; n < s->nb_streams; n++) { int64_t es_pos; if (asf->streams[n].stream_language_index > 127)