diff mbox

[FFmpeg-devel] avcodec/libopenh264enc.c

Message ID CAGTf1MkZKRbH92A3ndaMjPhwhKwh48iUA9-jBZNTL7pjt21KNg@mail.gmail.com
State Superseded
Headers show

Commit Message

Valery Kot Oct. 11, 2018, 1:31 p.m. UTC
When using libx264 (GPL) encoder, sample aspect ratio gets stored on
both container and frame levels. For libopenh264 (LGPL), aspect ratio
on codec/frame level currently is ignored, which results in weird
display aspect ratio for non-square pixels on some players.

Proposed patch fixes that, if FFmpeg being build against libopenh264
1.7 or newer.

---
 libavcodec/libopenh264enc.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

ASP_32x11;
+        else if (!av_cmp_q(av_make_q(80, 33),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_80x33;
+        else if (!av_cmp_q(av_make_q(18, 11),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_18x11;
+        else if (!av_cmp_q(av_make_q(15, 11),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_15x11;
+        else if (!av_cmp_q(av_make_q(64, 33),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_64x33;
+        else if (!av_cmp_q(av_make_q(160,99),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_160x99;
+        else {
+            param.sSpatialLayers[0].eAspectRatio = ASP_EXT_SAR;
+            param.sSpatialLayers[0].sAspectRatioExtWidth =
avctx->sample_aspect_ratio.num;
+            param.sSpatialLayers[0].sAspectRatioExtHeight =
avctx->sample_aspect_ratio.den;
+        }
+    }
+#endif
+
     if ((avctx->slices > 1) && (s->max_nal_size)) {
         av_log(avctx, AV_LOG_ERROR,
                "Invalid combination -slices %d and -max_nal_size %d.\n",

Comments

Timo Rothenpieler Oct. 11, 2018, 2:45 p.m. UTC | #1
This patch is corrupted, also needs a more meaningful commit message.
Moritz Barsnick Oct. 11, 2018, 5:13 p.m. UTC | #2
On Thu, Oct 11, 2018 at 16:45:02 +0200, Timo Rothenpieler wrote:
> This patch is corrupted, also needs a more meaningful commit message.

Valery previously sent the patch as an attachment, which looked okay.
(Perhaps needed a better commit message nevertheless.)

Moritz
Valery Kot Oct. 12, 2018, 7:18 a.m. UTC | #3
I sent a (hopefully valid) patch along with a proper commit message.
It resulted in a new thread, sorry.
diff mbox

Patch

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 83c3f0ce20..6d4d9e6192 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -164,6 +164,32 @@  FF_ENABLE_DEPRECATION_WARNINGS
     param.sSpatialLayers[0].iSpatialBitrate     = param.iTargetBitrate;
     param.sSpatialLayers[0].iMaxSpatialBitrate  = param.iMaxBitrate;

+    #if OPENH264_VER_AT_LEAST(1, 7)
+    if(avctx->sample_aspect_ratio.num == 0 ||
avctx->sample_aspect_ratio.den == 0)
+        param.sSpatialLayers[0].bAspectRatioPresent = false;
+    else {
+        param.sSpatialLayers[0].bAspectRatioPresent = true;
+        if      (!av_cmp_q(av_make_q( 1,  1),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_1x1;
+        else if (!av_cmp_q(av_make_q(12, 11),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_12x11;
+        else if (!av_cmp_q(av_make_q(10, 11),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_10x11;
+        else if (!av_cmp_q(av_make_q(16, 11),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_16x11;
+        else if (!av_cmp_q(av_make_q(40, 33),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_40x33;
+        else if (!av_cmp_q(av_make_q(24, 11),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_24x11;
+        else if (!av_cmp_q(av_make_q(20, 11),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =
ASP_20x11;
+        else if (!av_cmp_q(av_make_q(32, 11),
avctx->sample_aspect_ratio))  param.sSpatialLayers[0].eAspectRatio =