[FFmpeg-devel] [PATCH]Read aspect ratio from mxf
Carl Eugen Hoyos
cehoyos at ag.or.at
Sat Nov 15 02:50:38 CET 2014
Hi!
Attached patch fixes ticket #4107 for me.
An alternative would be to force the sar to 4:3
if h264 10bit 1440x1080 video has sar 3:4.
Please review, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index b533e2a..3ac5e68 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1771,6 +1771,10 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
if (source_track->sequence->origin) {
av_dict_set_int(&st->metadata, "source_track_origin", source_track->sequence->origin, 0);
}
+ if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den) {
+ av_dict_set_int(&st->metadata, "display_aspect_ratio_num", descriptor->aspect_ratio.num, 0);
+ av_dict_set_int(&st->metadata, "display_aspect_ratio_den", descriptor->aspect_ratio.den, 0);
+ }
} else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul);
/* Only overwrite existing codec ID if it is unset or A-law, which is the default according to SMPTE RP 224. */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8da8db4..d90541c 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3298,6 +3298,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
for (i = 0; i < ic->nb_streams; i++) {
st = ic->streams[i];
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ AVDictionaryEntry *dar;
+ int darnum = 0, darden = 0;
if (st->codec->codec_id == AV_CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample) {
uint32_t tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
if (avpriv_find_pix_fmt(avpriv_get_raw_pix_fmt_tags(), tag) == st->codec->pix_fmt)
@@ -3346,6 +3348,19 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
st->r_frame_rate.den = st->time_base.num;
}
}
+ dar = av_dict_get(st->metadata, "display_aspect_ratio_num", NULL, 0);
+ if (dar)
+ darnum = strtol(dar->value, NULL, 0);
+ dar = av_dict_get(st->metadata, "display_aspect_ratio_den", NULL, 0);
+ if (dar)
+ darden = strtol(dar->value, NULL, 0);
+ if (darnum && darden) {
+ av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den,
+ st->codec->height * darnum, st->codec->width * darden,
+ INT32_MAX);
+ av_dict_set(&st->metadata, "display_aspect_ratio_num", NULL, 0);
+ av_dict_set(&st->metadata, "display_aspect_ratio_den", NULL, 0);
+ }
} else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
if (!st->codec->bits_per_coded_sample)
st->codec->bits_per_coded_sample =
More information about the ffmpeg-devel
mailing list