From patchwork Tue Mar 26 19:25:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Samuelson X-Patchwork-Id: 47499 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp173009pzb; Tue, 26 Mar 2024 12:26:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVjE4XckV6sN5awOgFRe789Uak80PmYnnYxbG7sv6AWSs5iu44TV7iwmt9RmbBzNTjxZKdcDr8g3LIcl/Um25981hicH3Azp4kJTw== X-Google-Smtp-Source: AGHT+IHvfWKv4WAoHaFS8RDvNr7SyjqIl22e9p5sLhzsubSh/v52hZ9amUgOjyIzxQA6yc733K83 X-Received: by 2002:a17:906:b789:b0:a46:f9a0:748 with SMTP id dt9-20020a170906b78900b00a46f9a00748mr7334675ejb.5.1711481173758; Tue, 26 Mar 2024 12:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711481173; cv=none; d=google.com; s=arc-20160816; b=hhb6Beokv15fk8a74Ze193tsTI+yNPBIzz6O8ISBVR/IEp4JBxQqG6592rSYokrUbg /n1b5iSvG9193UC9Fhj2IImcWvJ6xQdfxVtl7CR8+T8oOt7qEq409fCx03dNFJHxObKV UO/CGW/tQSKEC4MThi+HfCodlpyh9UQw4z3qsuGyvf/XboE5tWdl/bdNe+WRB3xWFZJh Udvjfx3fXHTPLhnPDrrqsVAvRJRvc7Lk42abeupKg/UI35HGo55lRJLu1tJBdjuZpRX0 HK+ZGAYO4nOcwwEVQeeNHxMwEmwlDdeet526mKTYO8YnyezuhKX3GyKJpC8DSU8K9ZGa nOWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=Q8pzGpydusn8J+5qd5/oxq5mtfdbkf1GudhK+BxYeUA=; fh=QKFI4dMj83J2pxOiuhiYCo6Z/ly20dID22f33yRIZqE=; b=UgOlA7RY95Vr6kspOcYDAESQH+2D8kGsqtAhp9PtBPibRz1Y73qkDPGefYS+cMvvDf H9xhOoO3ip3kDwfUbnFPhmUHB7yd8JVheasoiF63D2xAMMIZPE7DMc6QGs/RVR+fwgxa CtWkrxcntol6zMUwoPHOCNkc/bcIaI99UT5UDubmyS/L6+7waxhdlHr5SclKEiuxzRFT 6A6dUoKJluKv7RDMXxDgEVaofo5VvCNDDrgikbHzl1b8XxLIHIRUstWooVoHDLbC8xQp 3/B9pWnm2i1lSNGoQNR8AS0CtEUxVTWR3gXtZVVPkK2UM3+1vxhk/9kpgsDDM6CvRvE3 CNdA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="bFL8q/Hd"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e24-20020a170906c01800b00a4633a910desi3835096ejz.867.2024.03.26.12.26.13; Tue, 26 Mar 2024 12:26:13 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="bFL8q/Hd"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4E21168D682; Tue, 26 Mar 2024 21:26:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A89A68D0F6 for ; Tue, 26 Mar 2024 21:26:03 +0200 (EET) Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-22a639aedb6so513054fac.3 for ; Tue, 26 Mar 2024 12:26:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711481161; x=1712085961; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2qKV2P0ySlYV7oa3wpsf+SQfXeuuXtrkjvF00WUqK4A=; b=bFL8q/Hdfco6QduAQ54kMQw5P+vXXP9cBHq1lKLImsTIK3Dqjn5775slrxrN/6/vC7 zT4sAHhn+FQbOTpecKbnXjBxJcUF3DAtIzUyae9qyf1Ozre6hT69ch86q9WurD4Mzi4z rSBcJNrR8PF+hU29LaTifK1seutX55nkbn6Ye8r+Z+yz4X3BYB+R90BKuv6QPfFfzMk4 5jgc6NzMd5YpSZte5Fw4rIR3ZylV7cetNHUTVHluXrIHkVjQH2dmldjBVPSvQcwORI04 1kJyA3IsxFT7FVy0QGS0mwqcvU6V1XM6RxFNhEhlQUKS/TJ6lB12p5q1YRP3DdqfR+Vn sG9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711481161; x=1712085961; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2qKV2P0ySlYV7oa3wpsf+SQfXeuuXtrkjvF00WUqK4A=; b=e0ofME5qL5gpnIAf7YKEI4w7++A1Zq49fCHeIKqfqd2vNYanabz+jv9UxEktTRWTct VQ5nKUiM5KpXrKIeq7w6S7+WlNM3DXXCzxfqu2i0tYagoOk59CWDBNFMfpwMyudyRGuR 9ut3n2v1SvrhpsiP8kQkK2LJryBrJg9UMCToX4EtPHRTyYCzQ1J2p+tvnJKms1n1MOLW fmsbHellKB9NS665PYzvszF35FgcEs4jFo30IK1gXfSc+WpVRW7q16GNvtabrviFCY0h zuYBkzodvl+a+60lsi1O9WXRP9NwGhF+BLz2BI+42Jd8GYXSTziOfxFGWprhsYLrWT1m BA0A== X-Gm-Message-State: AOJu0YyBAAPTOyroSqRbVOyDx1X9m6BvJI1CoRzA+GMAvS9il9cS9bMM uIwr/FhIsNq0ElVMYVLR5TqHqLx0nwRtcjbOC4Thn4RCje3FpGCEU+gU3pSp X-Received: by 2002:a05:6870:96a7:b0:221:8e59:b3e7 with SMTP id o39-20020a05687096a700b002218e59b3e7mr592181oaq.1.1711481161441; Tue, 26 Mar 2024 12:26:01 -0700 (PDT) Received: from localhost.localdomain (174-082-139-008.res.spectrum.com. [174.82.139.8]) by smtp.gmail.com with ESMTPSA id wz8-20020a0568707ec800b0022a36b9d147sm1497704oab.47.2024.03.26.12.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 12:26:01 -0700 (PDT) From: Mark Samuelson To: ffmpeg-devel@ffmpeg.org Date: Tue, 26 Mar 2024 14:25:37 -0500 Message-ID: <20240326192537.272-1-samuelsonm@gmail.com> X-Mailer: git-send-email 2.44.0.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/mfenc: expose more properties of the media foundation encoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Mark Samuelson Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /3gTQuil1pkG --- libavcodec/mf_utils.h | 5 +++++ libavcodec/mfenc.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libavcodec/mf_utils.h b/libavcodec/mf_utils.h index aebfb9ad21..387c005f38 100644 --- a/libavcodec/mf_utils.h +++ b/libavcodec/mf_utils.h @@ -97,6 +97,11 @@ DEFINE_GUID(ff_CODECAPI_AVEncH264CABACEnable, 0xee6cad62, 0xd305, 0x4248, 0xa DEFINE_GUID(ff_CODECAPI_AVEncVideoForceKeyFrame, 0x398c1b98, 0x8353, 0x475a, 0x9e, 0xf2, 0x8f, 0x26, 0x5d, 0x26, 0x3, 0x45); DEFINE_GUID(ff_CODECAPI_AVEncMPVDefaultBPictureCount, 0x8d390aac, 0xdc5c, 0x4200, 0xb5, 0x7f, 0x81, 0x4d, 0x04, 0xba, 0xba, 0xb2); DEFINE_GUID(ff_CODECAPI_AVScenarioInfo, 0xb28a6e64,0x3ff9,0x446a,0x8a,0x4b,0x0d,0x7a,0x53,0x41,0x32,0x36); +DEFINE_GUID(ff_CODECAPI_AVEncCommonBufferSize, 0x0db96574, 0xb6a4, 0x4c8b, 0x81, 0x06, 0x37, 0x73, 0xde, 0x03, 0x10, 0xcd); +DEFINE_GUID(ff_CODECAPI_AVEncCommonMaxBitRate, 0x9651eae4, 0x39b9, 0x4ebf, 0x85, 0xef, 0xd7, 0xf4, 0x44, 0xec, 0x74, 0x65); +DEFINE_GUID(ff_CODECAPI_AVEncCommonQualityVsSpeed, 0x98332df8, 0x03cd, 0x476b, 0x89, 0xfa, 0x3f, 0x9e, 0x44, 0x2d, 0xec, 0x9f); +DEFINE_GUID(ff_CODECAPI_AVEncMPVGOPSize, 0x95f31b26, 0x95a4, 0x41aa, 0x93, 0x03, 0x24, 0x6a, 0x7f, 0xc6, 0xee, 0xf1); +DEFINE_GUID(ff_CODECAPI_AVEncVideoEncodeQP, 0x2cb5696b, 0x23fb, 0x4ce1, 0xa0, 0xf9, 0xef, 0x5b, 0x90, 0xfd, 0x55, 0xca); DEFINE_GUID(ff_MF_SA_D3D11_BINDFLAGS, 0xeacf97ad, 0x065c, 0x4408, 0xbe, 0xe3, 0xfd, 0xcb, 0xfd, 0x12, 0x8b, 0xe2); DEFINE_GUID(ff_MF_SA_D3D11_USAGE, 0xe85fe442, 0x2ca3, 0x486e, 0xa9, 0xc7, 0x10, 0x9d, 0xda, 0x60, 0x98, 0x80); diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c index 9225692c51..36f64a93b8 100644 --- a/libavcodec/mfenc.c +++ b/libavcodec/mfenc.c @@ -54,6 +54,8 @@ typedef struct MFContext { int opt_enc_quality; int opt_enc_scenario; int opt_enc_hw; + int opt_enc_bufferSize; + int opt_enc_encodeQP; } MFContext; static int mf_choose_output_type(AVCodecContext *avctx); @@ -695,6 +697,21 @@ FF_ENABLE_DEPRECATION_WARNINGS if (c->opt_enc_quality >= 0) ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonQuality, FF_VAL_VT_UI4(c->opt_enc_quality)); + if (avctx->rc_max_rate > 0) + ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonMaxBitRate, FF_VAL_VT_UI4(avctx->rc_max_rate)); + + if (avctx->gop_size > 0) + ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncMPVGOPSize, FF_VAL_VT_UI4(avctx->gop_size)); + + if(c->opt_enc_bufferSize > 0) + ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonBufferSize, FF_VAL_VT_UI4(c->opt_enc_bufferSize)); + + if(avctx->compression_level >= 0) + ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonQualityVsSpeed, FF_VAL_VT_UI4(avctx->compression_level)); + + if(c->opt_enc_encodeQP > 15) + ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncVideoEncodeQP, FF_VAL_VT_UI4(c->opt_enc_encodeQP)); + // Always set the number of b-frames. Qualcomm's HEVC encoder on SD835 // defaults this to 1, and that setting is buggy with many of the // rate control modes. (0 or 2 b-frames works fine with most rate @@ -1280,6 +1297,8 @@ static const AVOption venc_opts[] = { {"quality", "Quality", OFFSET(opt_enc_quality), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100, VE}, {"hw_encoding", "Force hardware encoding", OFFSET(opt_enc_hw), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE}, + {"buffer_size", "BufferSize", OFFSET(opt_enc_bufferSize), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE}, + {"encodeQP", "QualityQP", OFFSET(opt_enc_encodeQP), AV_OPT_TYPE_INT, {.i64 = 15}, 15, 51, VE}, {NULL} };