[FFmpeg-devel] [PATCH]Read aspect ratio from mxf
Carl Eugen Hoyos
cehoyos at ag.or.at
Sun Nov 16 02:03:04 CET 2014
On Saturday 15 November 2014 11:57:00 pm Michael Niedermayer wrote:
> On Sat, Nov 15, 2014 at 02:50:38AM +0100, Carl Eugen Hoyos wrote:
> > 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.
> > + av_dict_set(&st->metadata, "display_aspect_ratio_num",
> > NULL, 0); + av_dict_set(&st->metadata,
> > "display_aspect_ratio_den", NULL, 0); + }
>
> I suggest you add a documented as private/internal
> display_aspect_ratio to AVStream instead of metadata
> also av_reduce can be replaced by av_mul_q which is probably simpler
New patch attached.
Thank you, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 3733549..34f2a68 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1097,6 +1097,13 @@ typedef struct AVStream {
*/
int inject_global_side_data;
+ /**
+ * display aspect ratio (0 if unknown)
+ * - encoding: unused
+ * - decoding: Set by libavformat to calculate sample_aspect_ratio internally
+ */
+ AVRational display_aspect_ratio;
+
} AVStream;
AVRational av_stream_get_r_frame_rate(const AVStream *s);
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 87f1e51..fa0a2f4 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1781,6 +1781,8 @@ 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)
+ st->display_aspect_ratio = descriptor->aspect_ratio;
} 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..aef0eca 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3346,6 +3346,11 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
st->r_frame_rate.den = st->time_base.num;
}
}
+ if (st->display_aspect_ratio.num && st->display_aspect_ratio.den) {
+ AVRational hw_ratio = { st->codec->height, st->codec->width };
+ st->sample_aspect_ratio = av_mul_q(st->display_aspect_ratio,
+ hw_ratio);
+ }
} 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