diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2016-03-19 15:41:30 +0100 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2016-04-27 04:40:11 +0200 |
commit | d7c15fb25a650bc9fed8c031bbe9ecbb5ce7985c (patch) | |
tree | 6b9de1c45f7f402b41c3d4de803945453136a1f5 | |
parent | 5c289c932fe46e173d2fb4fa034ea70dc32c8df0 (diff) | |
download | ffmpeg-d7c15fb25a650bc9fed8c031bbe9ecbb5ce7985c.tar.gz |
avcodec/mjpegenc_common: Store approximate aspect if exact cannot be stored
Fixes Ticket5244
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 068026b0f7845e0f1850094d974f60d181480d64)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavcodec/mjpegenc_common.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c index 64e14253eb..f3c8df2b8c 100644 --- a/libavcodec/mjpegenc_common.c +++ b/libavcodec/mjpegenc_common.c @@ -119,6 +119,16 @@ static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p) uint8_t *ptr; if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) { + AVRational sar = avctx->sample_aspect_ratio; + + if (sar.num > 65535 || sar.den > 65535) { + if (!av_reduce(&sar.num, &sar.den, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 65535)) + av_log(avctx, AV_LOG_WARNING, + "Cannot store exact aspect ratio %d:%d\n", + avctx->sample_aspect_ratio.num, + avctx->sample_aspect_ratio.den); + } + /* JFIF header */ put_marker(p, APP0); put_bits(p, 16, 16); @@ -128,8 +138,8 @@ static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p) * released revision. */ put_bits(p, 16, 0x0102); put_bits(p, 8, 0); /* units type: 0 - aspect ratio */ - put_bits(p, 16, avctx->sample_aspect_ratio.num); - put_bits(p, 16, avctx->sample_aspect_ratio.den); + put_bits(p, 16, sar.num); + put_bits(p, 16, sar.den); put_bits(p, 8, 0); /* thumbnail width */ put_bits(p, 8, 0); /* thumbnail height */ } |