Skip to content

Commit

Permalink
Merge pull request #558 from HaveAGitGat/bitrate
Browse files Browse the repository at this point in the history
Add bitrate option
  • Loading branch information
HaveAGitGat authored Nov 28, 2023
2 parents 3d717fd + ef88971 commit 9c96adc
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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: [
{
Expand All @@ -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'
Expand Down Expand Up @@ -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);
Expand All @@ -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') {
Expand All @@ -162,6 +208,8 @@ var plugin = function (args) {
audioCodec: audioCodec,
audioEncoder: audioEncoder,
wantedChannelCount: wantedChannelCount,
enableBitrate: enableBitrate,
bitrate: bitrate,
});
if (!addedOrExists) {
attemptMakeStream({
Expand All @@ -171,6 +219,8 @@ var plugin = function (args) {
audioCodec: audioCodec,
audioEncoder: audioEncoder,
wantedChannelCount: wantedChannelCount,
enableBitrate: enableBitrate,
bitrate: bitrate,
});
}
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getFfType } from '../../../../FlowHelpers/1.0.0/fileUtils';
import {
IffmpegCommandStream,
IpluginDetails,
Expand Down Expand Up @@ -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: [
{
Expand All @@ -94,13 +136,17 @@ const attemptMakeStream = ({
audioCodec,
audioEncoder,
wantedChannelCount,
enableBitrate,
bitrate,
}: {
args: IpluginInputArgs,
langTag: string
streams: IffmpegCommandStream[],
audioCodec: string,
audioEncoder: string,
wantedChannelCount: number,
enableBitrate: boolean,
bitrate: string,
}): boolean => {
const langMatch = (stream: IffmpegCommandStream) => (
(langTag === 'und'
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -207,6 +260,8 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
audioCodec,
audioEncoder,
wantedChannelCount,
enableBitrate,
bitrate,
});

if (!addedOrExists) {
Expand All @@ -217,6 +272,8 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
audioCodec,
audioEncoder,
wantedChannelCount,
enableBitrate,
bitrate,
});
}

Expand Down

0 comments on commit 9c96adc

Please sign in to comment.