[FFmpeg-devel] [PATCH]Read aspect ratio from mxf

2014-11-14 Thread Carl Eugen Hoyos
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
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 =
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]Read aspect ratio from mxf

2014-11-15 Thread Michael Niedermayer
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.
> 
> Please review, Carl Eugen

>  mxfdec.c |4 
>  utils.c  |   15 +++
>  2 files changed, 19 insertions(+)
> e669a2a2f5050b9fc4165c818b97e6d11ead87a5  patchmxfdar.diff
> 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);
> +}

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

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

DNS cache poisoning attacks, popular search engine, Google internet authority
dont be evil, please


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]Read aspect ratio from mxf

2014-11-15 Thread Carl Eugen Hoyos
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
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 =
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]Read aspect ratio from mxf

2014-11-15 Thread Michael Niedermayer
On Sun, Nov 16, 2014 at 02:03:04AM +0100, Carl Eugen Hoyos wrote:
> 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

>  avformat.h |7 +++
>  mxfdec.c   |2 ++
>  utils.c|5 +
>  3 files changed, 14 insertions(+)
> d1e24c2beb16c29ab9a79f9b745048b3b9245e15  patchmxfdar2.diff
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h

LGTM

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No snowflake in an avalanche ever feels responsible. -- Voltaire


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]Read aspect ratio from mxf

2014-11-18 Thread Carl Eugen Hoyos
Carl Eugen Hoyos  ag.or.at> writes:

> > 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.

The patch was merged.

Thank you, Carl Eugen

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]Read aspect ratio from mxf

2014-11-21 Thread Tomas Härdin
On Sun, 2014-11-16 at 02:03 +0100, Carl Eugen Hoyos wrote:
> 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

Looks good to me. I recall doing something similar way back that I never
sent to this list, in order to deal with similar issues.

/Tomas


signature.asc
Description: This is a digitally signed message part
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel