ffmpeg | branch: master | Jan Ekström <jee...@gmail.com> | Sun Aug 29 19:24:12 
2021 +0300| [9b2281a4a383677ded522e603514789cc22498fa] | committer: Jan Ekström

avcodec/libx265: add support for setting chroma sample location

Unlike libx264, libx265 does not handle the chroma format check
on its own side, so in order to not write out values which are
supposed to be ignored according to the specification, we limit
the writing out of chroma sample location to 4:2:0 only.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9b2281a4a383677ded522e603514789cc22498fa
---

 libavcodec/libx265.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 71affbf61b..839b6ce9de 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -211,6 +211,19 @@ static av_cold int libx265_encode_init(AVCodecContext 
*avctx)
         ctx->params->vui.matrixCoeffs            = avctx->colorspace;
     }
 
+    // chroma sample location values are to be ignored in case of non-4:2:0
+    // according to the specification, so we only write them out in case of
+    // 4:2:0 (log2_chroma_{w,h} == 1).
+    ctx->params->vui.bEnableChromaLocInfoPresentFlag =
+        avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED &&
+        desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1;
+
+    if (ctx->params->vui.bEnableChromaLocInfoPresentFlag) {
+        ctx->params->vui.chromaSampleLocTypeTopField =
+        ctx->params->vui.chromaSampleLocTypeBottomField =
+            avctx->chroma_sample_location - 1;
+    }
+
     if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 
0) {
         char sar[12];
         int sar_num, sar_den;

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to