From 9ce8ec27135e1c3b0045707064d1f62c498252d2 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:30:24 +0300 Subject: [PATCH] Add toggles for preset and quality --- .../1.0.0/index.ts | 67 +++++++++++++++++-- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetVideoEncoder/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetVideoEncoder/1.0.0/index.ts index 920ece68c..97ef6f3a2 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetVideoEncoder/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetVideoEncoder/1.0.0/index.ts @@ -38,6 +38,16 @@ const details = (): IpluginDetails => ({ }, tooltip: 'Specify codec of the output file', }, + { + label: 'Enable FFmpeg Preset', + name: 'ffmpegPresetEnabled', + type: 'boolean', + defaultValue: 'true', + inputUI: { + type: 'switch', + }, + tooltip: 'Specify whether to use an FFmpeg preset', + }, { label: 'FFmpeg Preset', name: 'ffmpegPreset', @@ -56,9 +66,34 @@ const details = (): IpluginDetails => ({ 'superfast', 'ultrafast', ], + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'ffmpegPresetEnabled', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, }, tooltip: 'Specify ffmpeg preset', }, + { + label: 'Enable FFmpeg CRF', + name: 'ffmpegQualityEnabled', + type: 'boolean', + defaultValue: 'true', + inputUI: { + type: 'switch', + }, + tooltip: 'Specify whether to set crf (or qp for GPU encoding)', + }, { label: 'FFmpeg Quality', name: 'ffmpegQuality', @@ -66,6 +101,21 @@ const details = (): IpluginDetails => ({ defaultValue: '25', inputUI: { type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'ffmpegQualityEnabled', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, }, tooltip: 'Specify ffmpeg quality', }, @@ -140,6 +190,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { if (stream.codec_type === 'video') { const targetCodec = String(args.inputs.outputCodec); + const { ffmpegPresetEnabled, ffmpegQualityEnabled } = args.inputs; const ffmpegPreset = String(args.inputs.ffmpegPreset); const ffmpegQuality = String(args.inputs.ffmpegQuality); const forceEncoding = args.inputs.forceEncoding === true; @@ -161,14 +212,18 @@ const plugin = async (args: IpluginInputArgs): Promise => { stream.outputArgs.push('-c:{outputIndex}', encoderProperties.encoder); - if (encoderProperties.isGpu) { - stream.outputArgs.push('-qp', ffmpegQuality); - } else { - stream.outputArgs.push('-crf', ffmpegQuality); + if (ffmpegQualityEnabled) { + if (encoderProperties.isGpu) { + stream.outputArgs.push('-qp', ffmpegQuality); + } else { + stream.outputArgs.push('-crf', ffmpegQuality); + } } - if (targetCodec !== 'av1' && ffmpegPreset) { - stream.outputArgs.push('-preset', ffmpegPreset); + if (ffmpegPresetEnabled) { + if (targetCodec !== 'av1' && ffmpegPreset) { + stream.outputArgs.push('-preset', ffmpegPreset); + } } if (hardwareDecoding) {