Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Martin Storsjö" <martin@martin.st>
To: "Dennis Sädtler via ffmpeg-devel" <ffmpeg-devel@ffmpeg.org>
Cc: dennis@obsproject.com
Subject: Re: [FFmpeg-devel] [PATCH v2] lavc/videotoolboxenc: Add spatial_aq option
Date: Tue, 4 Feb 2025 23:51:23 +0200 (EET)
Message-ID: <a35ecae-6e56-6d86-c149-cdfcdd47be8@martin.st> (raw)
In-Reply-To: <20241216092829.1237-1-dennis@obsproject.com>

On Mon, 16 Dec 2024, Dennis Sädtler via ffmpeg-devel wrote:

> From: Dennis Sädtler <dennis@obsproject.com>
>
> Added in macOS 15 "Sequoia".
>
> Signed-off-by: Dennis Sädtler <dennis@obsproject.com>
> ---
> Fixed line-endings, otherwise identical to v1.
>
> libavcodec/videotoolboxenc.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index da7b291b03..fb2de7b960 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -121,6 +121,7 @@ static struct{
>     CFStringRef kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality;
>     CFStringRef kVTCompressionPropertyKey_ConstantBitRate;
>     CFStringRef kVTCompressionPropertyKey_EncoderID;
> +    CFStringRef kVTCompressionPropertyKey_SpatialAdaptiveQPLevel;
>
>     CFStringRef kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder;
>     CFStringRef kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder;
> @@ -208,6 +209,7 @@ static void loadVTEncSymbols(void){
>             "ReferenceBufferCount");
>     GET_SYM(kVTCompressionPropertyKey_MaxAllowedFrameQP, "MaxAllowedFrameQP");
>     GET_SYM(kVTCompressionPropertyKey_MinAllowedFrameQP, "MinAllowedFrameQP");
> +    GET_SYM(kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, "SpatialAdaptiveQPLevel");
> }
> 
> #define H264_PROFILE_CONSTRAINED_HIGH (AV_PROFILE_H264_HIGH | AV_PROFILE_H264_CONSTRAINED)
> @@ -279,6 +281,7 @@ typedef struct VTEncContext {
>     int max_slice_bytes;
>     int power_efficient;
>     int max_ref_frames;
> +    int spatialaq;
> } VTEncContext;
> 
> static void vtenc_free_buf_node(BufNode *info)
> @@ -1599,6 +1602,13 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
>         }
>     }
> 
> +    if (vtctx->spatialaq >= 0) {
> +        set_encoder_int_property_or_log(avctx,
> +                                        compat_keys.kVTCompressionPropertyKey_SpatialAdaptiveQPLevel,
> +                                        "spatialaq",
> +                                        vtctx->spatialaq ? kVTQPModulationLevel_Default : kVTQPModulationLevel_Disable);

These constants aren't available if building with an older SDK, so this 
would break building in such cases.

For other similar cases of compile time constants that may or may not be 
available, we have configure checks and provide the constants ourselves - 
that seems to be reasonable here too.

With the following changes on top, it seems to build successfully even for 
older versions:


diff --git a/configure b/configure
index 32fbe58126..020c2af843 100755
--- a/configure
+++ b/configure
@@ -2490,6 +2490,7 @@ TYPES_LIST="
      kCVImageBufferColorPrimaries_ITU_R_2020
      kCVImageBufferTransferFunction_ITU_R_2020
      kCVImageBufferTransferFunction_SMPTE_ST_428_1
+    kVTQPModulationLevel_Default
      socklen_t
      struct_addrinfo
      struct_group_source_req
@@ -6748,6 +6749,7 @@ enabled videotoolbox && {
      check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferColorPrimaries_ITU_R_2020 "-framework CoreVideo"
      check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_ITU_R_2020 "-framework CoreVideo"
      check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_SMPTE_ST_428_1 "-framework CoreVideo"
+    check_func_headers VideoToolbox/VTCompressionProperties.h kVTQPModulationLevel_Default "-framework CoreVideo"
  }

  enabled metal && test_cmd $metalcc -v || disable metal
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index fb2de7b960..950a29d9fa 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -54,6 +54,11 @@ enum { kCVPixelFormatType_420YpCbCr10BiPlanarFullRange 
= 'xf20' };
  enum { kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange = 'x420' };
  #endif

+#if !HAVE_KVTQPMODULATIONLEVEL_DEFAULT
+enum { kVTQPModulationLevel_Default = -1 };
+enum { kVTQPModulationLevel_Disable = 0 };
+#endif
+
  #ifndef TARGET_CPU_ARM64
  #   define TARGET_CPU_ARM64 0
  #endif


If you don't mind these changes, I could push the patch with these changes 
squashed in.

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

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

           reply	other threads:[~2025-02-04 21:51 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20241216092829.1237-1-dennis@obsproject.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a35ecae-6e56-6d86-c149-cdfcdd47be8@martin.st \
    --to=martin@martin.st \
    --cc=dennis@obsproject.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git