diff options
author | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2014-04-17 14:55:49 +0200 |
---|---|---|
committer | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2014-04-17 14:55:49 +0200 |
commit | a3bd33af9edd71a8eb22b706b611661a096779ac (patch) | |
tree | d39bfa17275cb7fc4f4429d353b2e3928802c731 | |
parent | 6c18200c2f6c19891c7173ae85ac7e9babbe03f3 (diff) | |
download | ffmpeg-a3bd33af9edd71a8eb22b706b611661a096779ac.tar.gz |
Write sample_aspect_ratio to asf files.
Fixes ticket #3528.
-rw-r--r-- | libavformat/asfenc.c | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c index b456730229..89202fdd3c 100644 --- a/libavformat/asfenc.c +++ b/libavformat/asfenc.c @@ -352,7 +352,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, AVIOContext *pb = s->pb; AVDictionaryEntry *tags[5]; int header_size, n, extra_size, extra_size2, wav_extra_size, file_time; - int has_title; + int has_title, has_aspect_ratio = 0; int metadata_count; AVCodecContext *enc; int64_t header_offset, cur_pos, hpos; @@ -378,6 +378,10 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */ bit_rate += enc->bit_rate; + if ( enc->codec_type == AVMEDIA_TYPE_VIDEO + && enc->sample_aspect_ratio.num > 0 + && enc->sample_aspect_ratio.den > 0) + has_aspect_ratio++; } if (asf->is_streamed) { @@ -410,8 +414,40 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, /* unknown headers */ hpos = put_header(pb, &ff_asf_head1_guid); ff_put_guid(pb, &ff_asf_head2_guid); - avio_wl32(pb, 6); - avio_wl16(pb, 0); + avio_wl16(pb, 6); + if (has_aspect_ratio) { + int64_t hpos2; + avio_wl32(pb, 26 + has_aspect_ratio * 84); + hpos2 = put_header(pb, &ff_asf_metadata_header); + avio_wl16(pb, 2 * has_aspect_ratio); + for (n = 0; n < s->nb_streams; n++) { + enc = s->streams[n]->codec; + if ( enc->codec_type == AVMEDIA_TYPE_VIDEO + && enc->sample_aspect_ratio.num > 0 + && enc->sample_aspect_ratio.den > 0) { + AVRational sar = enc->sample_aspect_ratio; + avio_wl16(pb, 0); + // the stream number is set like this below + avio_wl16(pb, n + 1); + avio_wl16(pb, 26); // name_len + avio_wl16(pb, 3); // value_type + avio_wl32(pb, 4); // value_len + avio_put_str16le(pb, "AspectRatioX"); + avio_wl32(pb, sar.num); + avio_wl16(pb, 0); + // the stream number is set like this below + avio_wl16(pb, n + 1); + avio_wl16(pb, 26); // name_len + avio_wl16(pb, 3); // value_type + avio_wl32(pb, 4); // value_len + avio_put_str16le(pb, "AspectRatioY"); + avio_wl32(pb, sar.den); + } + } + end_header(pb, hpos2); + } else { + avio_wl32(pb, 0); + } end_header(pb, hpos); /* title and other infos */ |