From ef88971bcf46d33c77c9ba6cfc5e367b70ba838d Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 28 Nov 2023 07:01:12 +0000 Subject: [PATCH] Add bitrate option --- .../1.0.0/index.js | 52 ++++++++++++++++- .../1.0.0/index.ts | 57 +++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandEnsureAudioStream/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandEnsureAudioStream/1.0.0/index.js index b6a679551..5ad1eae80 100644 --- a/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandEnsureAudioStream/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandEnsureAudioStream/1.0.0/index.js @@ -1,6 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.plugin = exports.details = void 0; +var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils"); /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ var details = function () { return ({ name: 'Ensure Audio Stream', @@ -63,6 +64,45 @@ var details = function () { return ({ }, tooltip: 'Enter the desired number of channels', }, + { + label: 'Enable Bitrate', + name: 'enableBitrate', + type: 'boolean', + defaultValue: 'false', + inputUI: { + type: 'dropdown', + options: [ + 'false', + 'true', + ], + }, + tooltip: 'Toggle whether to enable setting audio bitrate', + }, + { + label: 'Bitrate', + name: 'bitrate', + type: 'string', + defaultValue: '128k', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'enableBitrate', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: 'Specify the audio bitrate for newly added channels', + }, ], outputs: [ { @@ -80,7 +120,7 @@ var getHighest = function (first, second) { return second; }; var attemptMakeStream = function (_a) { - var args = _a.args, langTag = _a.langTag, streams = _a.streams, audioCodec = _a.audioCodec, audioEncoder = _a.audioEncoder, wantedChannelCount = _a.wantedChannelCount; + var args = _a.args, langTag = _a.langTag, streams = _a.streams, audioCodec = _a.audioCodec, audioEncoder = _a.audioEncoder, wantedChannelCount = _a.wantedChannelCount, enableBitrate = _a.enableBitrate, bitrate = _a.bitrate; var langMatch = function (stream) { var _a; return ((langTag === 'und' @@ -131,6 +171,10 @@ var attemptMakeStream = function (_a) { streamCopy.index = streams.length; streamCopy.outputArgs.push('-c:{outputIndex}', audioEncoder); streamCopy.outputArgs.push('-ac', "".concat(targetChannels)); + if (enableBitrate) { + var ffType = (0, fileUtils_1.getFfType)(streamCopy.codec_type); + streamCopy.outputArgs.push("-b:".concat(ffType, ":{outputTypeIndex}"), "".concat(bitrate)); + } // eslint-disable-next-line no-param-reassign args.variables.ffmpegCommand.shouldProcess = true; streams.push(streamCopy); @@ -144,6 +188,8 @@ var plugin = function (args) { var audioEncoder = String(args.inputs.audioEncoder); var langTag = String(args.inputs.language).toLowerCase(); var wantedChannelCount = Number(args.inputs.channels); + var enableBitrate = Boolean(args.inputs.enableBitrate); + var bitrate = String(args.inputs.bitrate); var streams = args.variables.ffmpegCommand.streams; var audioCodec = audioEncoder; if (audioEncoder === 'dca') { @@ -162,6 +208,8 @@ var plugin = function (args) { audioCodec: audioCodec, audioEncoder: audioEncoder, wantedChannelCount: wantedChannelCount, + enableBitrate: enableBitrate, + bitrate: bitrate, }); if (!addedOrExists) { attemptMakeStream({ @@ -171,6 +219,8 @@ var plugin = function (args) { audioCodec: audioCodec, audioEncoder: audioEncoder, wantedChannelCount: wantedChannelCount, + enableBitrate: enableBitrate, + bitrate: bitrate, }); } return { diff --git a/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandEnsureAudioStream/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandEnsureAudioStream/1.0.0/index.ts index 0dece7c2d..8b8521c5b 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandEnsureAudioStream/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandEnsureAudioStream/1.0.0/index.ts @@ -1,3 +1,4 @@ +import { getFfType } from '../../../../FlowHelpers/1.0.0/fileUtils'; import { IffmpegCommandStream, IpluginDetails, @@ -70,6 +71,47 @@ const details = (): IpluginDetails => ({ tooltip: 'Enter the desired number of channels', }, + { + label: 'Enable Bitrate', + name: 'enableBitrate', + type: 'boolean', + defaultValue: 'false', + inputUI: { + type: 'dropdown', + options: [ + 'false', + 'true', + ], + }, + tooltip: + 'Toggle whether to enable setting audio bitrate', + }, + { + label: 'Bitrate', + name: 'bitrate', + type: 'string', + defaultValue: '128k', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'enableBitrate', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: + 'Specify the audio bitrate for newly added channels', + }, ], outputs: [ { @@ -94,6 +136,8 @@ const attemptMakeStream = ({ audioCodec, audioEncoder, wantedChannelCount, + enableBitrate, + bitrate, }: { args: IpluginInputArgs, langTag: string @@ -101,6 +145,8 @@ const attemptMakeStream = ({ audioCodec: string, audioEncoder: string, wantedChannelCount: number, + enableBitrate: boolean, + bitrate: string, }): boolean => { const langMatch = (stream: IffmpegCommandStream) => ( (langTag === 'und' @@ -166,6 +212,11 @@ const attemptMakeStream = ({ streamCopy.outputArgs.push('-c:{outputIndex}', audioEncoder); streamCopy.outputArgs.push('-ac', `${targetChannels}`); + if (enableBitrate) { + const ffType = getFfType(streamCopy.codec_type); + streamCopy.outputArgs.push(`-b:${ffType}:{outputTypeIndex}`, `${bitrate}`); + } + // eslint-disable-next-line no-param-reassign args.variables.ffmpegCommand.shouldProcess = true; @@ -183,6 +234,8 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { const audioEncoder = String(args.inputs.audioEncoder); const langTag = String(args.inputs.language).toLowerCase(); const wantedChannelCount = Number(args.inputs.channels); + const enableBitrate = Boolean(args.inputs.enableBitrate); + const bitrate = String(args.inputs.bitrate); const { streams } = args.variables.ffmpegCommand; @@ -207,6 +260,8 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { audioCodec, audioEncoder, wantedChannelCount, + enableBitrate, + bitrate, }); if (!addedOrExists) { @@ -217,6 +272,8 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { audioCodec, audioEncoder, wantedChannelCount, + enableBitrate, + bitrate, }); }