From a190a8023879f7c18c32cc59bc89ec67e9aa7d51 Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Mon, 30 Mar 2026 13:21:14 +0200 Subject: [PATCH] Add custom params text field to software encoders It allows to specify some specific encoding parameters. An example is being able to disable open gop on x265 for Youtube export --- encoder_info.h | 1 + ffmpeg_encoder.cpp | 4 ++++ svt_av1_encoder.cpp | 1 + uisettings_controller.cpp | 17 +++++++++++++++++ uisettings_controller.h | 3 +++ x264_encoder.cpp | 1 + x265_encoder.cpp | 1 + 7 files changed, 28 insertions(+) diff --git a/encoder_info.h b/encoder_info.h index 9ce0daa..39154cf 100644 --- a/encoder_info.h +++ b/encoder_info.h @@ -25,6 +25,7 @@ struct EncoderInfo { uint8_t qp[3]{}; std::map presets{}; int defaultPreset{}; + const char* customParamsKey{}; }; } diff --git a/ffmpeg_encoder.cpp b/ffmpeg_encoder.cpp index 4447bc3..d0cb703 100644 --- a/ffmpeg_encoder.cpp +++ b/ffmpeg_encoder.cpp @@ -229,6 +229,10 @@ void FFmpegEncoder::ApplyOptions(AVCodecContext* ctx, UISettingsController& sett av_opt_set(ctx->priv_data, "preset", preset->second.c_str(), 0); } } + + if (encoderInfo.customParamsKey != nullptr && !settings.GetCustomParams().empty()) { + av_opt_set(ctx->priv_data, encoderInfo.customParamsKey, settings.GetCustomParams().c_str(), 0); + } } StatusCode FFmpegEncoder::DoProcess(HostBufferRef* p_pBuff) { diff --git a/svt_av1_encoder.cpp b/svt_av1_encoder.cpp index c960b34..0a8b470 100644 --- a/svt_av1_encoder.cpp +++ b/svt_av1_encoder.cpp @@ -30,6 +30,7 @@ const EncoderInfo SvtAv1Encoder::encoderInfo = { {12, "12"}, }, .defaultPreset = 8, + .customParamsKey = "svtav1-params", }; SvtAv1Encoder::SvtAv1Encoder() { FFmpegEncoder::encoderInfo = encoderInfo; } diff --git a/uisettings_controller.cpp b/uisettings_controller.cpp index f04d3be..702a3f1 100644 --- a/uisettings_controller.cpp +++ b/uisettings_controller.cpp @@ -25,6 +25,11 @@ void UISettingsController::Load(IPropertyProvider* values) { values->GetINT32(qpId.c_str(), qp); values->GetINT32(bitrateId.c_str(), bitRate); values->GetINT32(presetId.c_str(), preset); + + std::string customParamsStr; + if (values->GetString(customParamsId.c_str(), customParamsStr)) { + customParams = customParamsStr; + } } StatusCode UISettingsController::Render(HostListRef* settingsList) const { @@ -59,6 +64,7 @@ void UISettingsController::InitDefaults() { qpId = prefix + "qp"; bitrateId = prefix + "bitrate"; presetId = prefix + "preset"; + customParamsId = prefix + "custom_params"; } void UISettingsController::SetFirstSupportedQualityMode() { @@ -91,6 +97,15 @@ StatusCode UISettingsController::RenderQuality(HostListRef* settingsList) const } } + if (encoderInfo.customParamsKey != nullptr) { + HostUIConfigEntryRef item(customParamsId); + item.MakeTextBox("Encoder Params", customParams, ""); + if (!item.IsSuccess() || !settingsList->Append(&item)) { + g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate custom params UI entry"); + return errFail; + } + } + { HostUIConfigEntryRef item(qualityModeId); @@ -163,3 +178,5 @@ int32_t UISettingsController::GetQP() const { return std::max(0, qp); } int32_t UISettingsController::GetBitRate() const { return bitRate * 1000; } int32_t UISettingsController::GetPreset() const { return preset; } + +const std::string& UISettingsController::GetCustomParams() const { return customParams; } diff --git a/uisettings_controller.h b/uisettings_controller.h index e02fd5a..8710b82 100644 --- a/uisettings_controller.h +++ b/uisettings_controller.h @@ -28,6 +28,7 @@ class UISettingsController final { int32_t GetQP() const; int32_t GetBitRate() const; int32_t GetPreset() const; + const std::string& GetCustomParams() const; private: HostCodecConfigCommon commonProps; @@ -37,11 +38,13 @@ class UISettingsController final { int32_t qp{}; int32_t bitRate{}; int32_t preset{}; + std::string customParams; std::string qualityModeId; std::string qpId; std::string bitrateId; std::string presetId; + std::string customParamsId; }; } diff --git a/x264_encoder.cpp b/x264_encoder.cpp index f537ef1..7d6e6d5 100644 --- a/x264_encoder.cpp +++ b/x264_encoder.cpp @@ -26,6 +26,7 @@ const EncoderInfo X264Encoder::encoderInfo = { {8, "veryslow"}, }, .defaultPreset = 5, + .customParamsKey = "x264-params", }; X264Encoder::X264Encoder() { FFmpegEncoder::encoderInfo = encoderInfo; } diff --git a/x265_encoder.cpp b/x265_encoder.cpp index def71fe..45a7be2 100644 --- a/x265_encoder.cpp +++ b/x265_encoder.cpp @@ -26,6 +26,7 @@ const EncoderInfo X265Encoder::encoderInfo = { {8, "veryslow"}, }, .defaultPreset = 5, + .customParamsKey = "x265-params", }; X265Encoder::X265Encoder() { FFmpegEncoder::encoderInfo = encoderInfo; }