PR #25024 opened by Jamaika1
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25024
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25024.patch

Rebase https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24500


>From ddbe40c1e1d0e83ba58990d5bd0215d7466d6894 Mon Sep 17 00:00:00 2001
From: Jamaika1 <[email protected]>
Date: Sun, 11 Oct 2026 09:36:24 +0000
Subject: [PATCH 1/5] libavcodec/libkvazaar: Support 444 and 422 subsampling

---
 doc/general_contents.texi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 1bc07fa743..6eea6bf547 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -193,7 +193,9 @@ FFmpeg can make use of the Kvazaar library for HEVC 
encoding.
 
 Go to @url{https://github.com/ultravideo/kvazaar} and follow the
 instructions for installing the library. Then pass
+@code{git 1f11f9ae33ef0cbe48a7d335b7144af1ecfe8092 --check}
 @code{--enable-libkvazaar} to configure to enable it.
+@code{-DKVZ_RANGE_EXTENSION=ON} libkvazaar 4:4:4 and 4:2:2 subsampling enabled.
 
 @section LAME
 
-- 
2.52.0


>From 002a90a20f8d7051e6198e65c205d14093ec3109 Mon Sep 17 00:00:00 2001
From: Jamaika1 <[email protected]>
Date: Sun, 11 Oct 2026 09:37:36 +0000
Subject: [PATCH 2/5] libavcodec/libkvazaar: Support 444 and 422 subsampling

---
 libavcodec/libkvazaar.c | 46 +++++++++++++++++++++++++++++++++++++++++
 libavcodec/version.h    |  4 ++--
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index 908c7a0383..f30cec739a 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -87,6 +87,28 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
         cfg->framerate_denom = avctx->time_base.num;
     }
     cfg->target_bitrate = avctx->bit_rate;
+#ifdef KVZ_RANGE_EXTENSION
+    if (avctx->pix_fmt == AV_PIX_FMT_YUV420P
+        ) {
+        cfg->chroma_format = KVZ_CSP_420;
+        cfg->chroma_shift = cfg->chroma_shift_w = 1;
+        cfg->chroma_shift_h = 1;
+    } else if (avctx->pix_fmt == AV_PIX_FMT_YUV422P
+               ) {
+        cfg->chroma_format = KVZ_CSP_422;
+        cfg->chroma_shift = cfg->chroma_shift_w = 1;
+        cfg->chroma_shift_h = 0;
+    } else if (avctx->pix_fmt == AV_PIX_FMT_YUV444P
+               ) {
+        cfg->chroma_format = KVZ_CSP_444;
+        cfg->chroma_shift = cfg->chroma_shift_w = 0;
+        cfg->chroma_shift_h = 0;
+    } else {
+        return -1;
+    }
+    cfg->enable_cross_component_prediction = 0;
+    const enum kvz_chroma_format expected_csp = cfg->chroma_format;
+#endif
     cfg->vui.sar_width  = avctx->sample_aspect_ratio.num;
     cfg->vui.sar_height = avctx->sample_aspect_ratio.den;
     if (avctx->bit_rate) {
@@ -114,6 +136,14 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
         av_dict_free(&dict);
     }
 
+#ifdef KVZ_RANGE_EXTENSION
+    if (cfg->chroma_format != expected_csp) {
+        av_log(avctx, AV_LOG_ERROR,
+               "kvazaar-params input-format conflicts with the input pixel 
format.\n");
+        return AVERROR(EINVAL);
+    }
+#endif
+
     ctx->encoder = enc = api->encoder_open(cfg);
     if (!enc) {
         av_log(avctx, AV_LOG_ERROR, "Could not open kvazaar encoder.\n");
@@ -198,7 +228,12 @@ static int libkvazaar_encode(AVCodecContext *avctx,
         }
 
         // Allocate input picture for kvazaar.
+#ifdef KVZ_RANGE_EXTENSION
+        enum kvz_chroma_format csp = 
KVZ_FORMAT2CSP(ctx->config->chroma_format);
+        input_pic = ctx->api->picture_alloc_csp(csp, frame->width, 
frame->height);
+#else
         input_pic = ctx->api->picture_alloc(frame->width, frame->height);
+#endif
         if (!input_pic) {
             av_log(avctx, AV_LOG_ERROR, "Failed to allocate picture.\n");
             retval = AVERROR(ENOMEM);
@@ -213,12 +248,19 @@ static int libkvazaar_encode(AVCodecContext *avctx,
                 input_pic->data[2],
                 NULL,
             };
+#ifdef KVZ_RANGE_EXTENSION
+            int dst_linesizes[4];
+            retval = av_image_fill_linesizes(dst_linesizes, frame->format, 
frame->width);
+            if (retval < 0)
+                goto done;
+#else
             int dst_linesizes[4] = {
               frame->width,
               frame->width / 2,
               frame->width / 2,
               0
             };
+#endif
             av_image_copy2(dst, dst_linesizes,
                            frame->data, frame->linesize,
                            frame->format, frame->width, frame->height);
@@ -294,6 +336,10 @@ done:
 }
 
 static const enum AVPixelFormat pix_fmts[] = {
+#ifdef KVZ_RANGE_EXTENSION
+    AV_PIX_FMT_YUV444P,
+    AV_PIX_FMT_YUV422P,
+#endif
     AV_PIX_FMT_YUV420P,
     AV_PIX_FMT_NONE
 };
diff --git a/libavcodec/version.h b/libavcodec/version.h
index d8604fd00c..4b7ec515fe 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,8 +29,8 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  18
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR  19
+#define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
-- 
2.52.0


>From 2b6b9e49af90f9e6b16f4234e303a830f0572008 Mon Sep 17 00:00:00 2001
From: Jamaika1 <[email protected]>
Date: Sun, 11 Oct 2026 09:53:10 +0000
Subject: [PATCH 3/5] libavcodec/libkvazaar: Support 444 and 422 subsampling

---
 libavcodec/libkvazaar.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index f30cec739a..1c6802d4c0 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -93,6 +93,7 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
         cfg->chroma_format = KVZ_CSP_420;
         cfg->chroma_shift = cfg->chroma_shift_w = 1;
         cfg->chroma_shift_h = 1;
+        cfg->intra_period = 1;
     } else if (avctx->pix_fmt == AV_PIX_FMT_YUV422P
                ) {
         cfg->chroma_format = KVZ_CSP_422;
@@ -103,6 +104,7 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
         cfg->chroma_format = KVZ_CSP_444;
         cfg->chroma_shift = cfg->chroma_shift_w = 0;
         cfg->chroma_shift_h = 0;
+        cfg->intra_period = 1;
     } else {
         return -1;
     }
-- 
2.52.0


>From 986d9a80d34615eb40d1e0ab4f40137d36b317d5 Mon Sep 17 00:00:00 2001
From: Jamaika1 <[email protected]>
Date: Mon, 12 Oct 2026 12:28:25 +0000
Subject: [PATCH 4/5] libavcodec/libkvazaar: Support 444 and 422 subsampling

---
 doc/general_contents.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 6eea6bf547..0ccd4fbf1f 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -193,7 +193,7 @@ FFmpeg can make use of the Kvazaar library for HEVC 
encoding.
 
 Go to @url{https://github.com/ultravideo/kvazaar} and follow the
 instructions for installing the library. Then pass
-@code{git 1f11f9ae33ef0cbe48a7d335b7144af1ecfe8092 --check}
+@code{git checkout --detach 1f11f9ae33ef0cbe48a7d335b7144af1ecfe8092}
 @code{--enable-libkvazaar} to configure to enable it.
 @code{-DKVZ_RANGE_EXTENSION=ON} libkvazaar 4:4:4 and 4:2:2 subsampling enabled.
 
-- 
2.52.0


>From 855795b07326c19573dc47d3063bc25116c81673 Mon Sep 17 00:00:00 2001
From: Jamaika1 <[email protected]>
Date: Mon, 12 Oct 2026 12:32:17 +0000
Subject: [PATCH 5/5] libavcodec/libkvazaar: Support 444 and 422 subsampling

---
 doc/general_contents.texi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 0ccd4fbf1f..0fc32c1ab3 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -195,7 +195,8 @@ Go to @url{https://github.com/ultravideo/kvazaar} and 
follow the
 instructions for installing the library. Then pass
 @code{git checkout --detach 1f11f9ae33ef0cbe48a7d335b7144af1ecfe8092}
 @code{--enable-libkvazaar} to configure to enable it.
-@code{-DKVZ_RANGE_EXTENSION=ON} libkvazaar 4:4:4 and 4:2:2 subsampling enabled.
+To enable range extensions in Kvazaar, configure its CMake build
+with @code{-DUSE_RANGE_EXTENSION=ON}.
 
 @section LAME
 
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to