[FFmpeg-devel] avformat/mxfenc: calculate and store DAR from user SAR

Submitted by Paul B Mahol on Dec. 7, 2018, 8:30 p.m.

Details

Message ID 20181207203056.25613-1-onemda@gmail.com
State New
Headers show

Commit Message

Paul B Mahol Dec. 7, 2018, 8:30 p.m.
Fixes #5155

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavformat/mxfenc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Tomas Härdin Dec. 9, 2018, 12:26 p.m.
fre 2018-12-07 klockan 21:30 +0100 skrev Paul B Mahol:
> Fixes #5155
> 
> > Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavformat/mxfenc.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> index 3549b4137d..8f762c7eaf 100644
> --- a/libavformat/mxfenc.c
> +++ b/libavformat/mxfenc.c
> @@ -2726,6 +2726,14 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
>          }
>      }
>  
> +    if (st->codecpar->sample_aspect_ratio.num && st->codecpar->sample_aspect_ratio.den) {
> +        av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
> +                  st->codecpar->sample_aspect_ratio.num * st->codecpar->width,
> +                  st->codecpar->sample_aspect_ratio.den * st->codecpar->height, INT_MAX);

Can these multiplications ever overflow? av_reduce_q might be a better
choice.

/Tomas
Paul B Mahol Dec. 9, 2018, 12:53 p.m.
On 12/9/18, Tomas Härdin <tjoppen@acc.umu.se> wrote:
> fre 2018-12-07 klockan 21:30 +0100 skrev Paul B Mahol:
>> Fixes #5155
>>
>> > Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> ---
>>  libavformat/mxfenc.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
>> index 3549b4137d..8f762c7eaf 100644
>> --- a/libavformat/mxfenc.c
>> +++ b/libavformat/mxfenc.c
>> @@ -2726,6 +2726,14 @@ static int mxf_write_packet(AVFormatContext *s,
>> AVPacket *pkt)
>>          }
>>      }
>>
>> +    if (st->codecpar->sample_aspect_ratio.num &&
>> st->codecpar->sample_aspect_ratio.den) {
>> +        av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
>> +                  st->codecpar->sample_aspect_ratio.num *
>> st->codecpar->width,
>> +                  st->codecpar->sample_aspect_ratio.den *
>> st->codecpar->height, INT_MAX);
>
> Can these multiplications ever overflow? av_reduce_q might be a better
> choice.

There is no av_reduce_q.
Nicolas George Dec. 9, 2018, 12:57 p.m.
Paul B Mahol (2018-12-09):
> >> +    if (st->codecpar->sample_aspect_ratio.num &&
> >> st->codecpar->sample_aspect_ratio.den) {
> >> +        av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
> >> +                  st->codecpar->sample_aspect_ratio.num *
> >> st->codecpar->width,
> >> +                  st->codecpar->sample_aspect_ratio.den *
> >> st->codecpar->height, INT_MAX);

> There is no av_reduce_q.

But there are av_mul_q() and av_div_q(), that would make these
computations much more readable, and are protected from overflow.

Regards,

Patch hide | download patch | download mbox

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 3549b4137d..8f762c7eaf 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -2726,6 +2726,14 @@  static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
         }
     }
 
+    if (st->codecpar->sample_aspect_ratio.num && st->codecpar->sample_aspect_ratio.den) {
+        av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
+                  st->codecpar->sample_aspect_ratio.num * st->codecpar->width,
+                  st->codecpar->sample_aspect_ratio.den * st->codecpar->height, INT_MAX);
+    } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+        av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, st->codecpar->width, st->codecpar->height, INT_MAX);
+    }
+
     if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
         if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) {
             av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n");