mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 01:36:08 -07:00
Add bitrate option
This commit is contained in:
parent
3d717fd866
commit
ef88971bcf
2 changed files with 108 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.plugin = exports.details = void 0;
|
exports.plugin = exports.details = void 0;
|
||||||
|
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||||
var details = function () { return ({
|
var details = function () { return ({
|
||||||
name: 'Ensure Audio Stream',
|
name: 'Ensure Audio Stream',
|
||||||
|
|
@ -63,6 +64,45 @@ var details = function () { return ({
|
||||||
},
|
},
|
||||||
tooltip: 'Enter the desired number of channels',
|
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: [
|
outputs: [
|
||||||
{
|
{
|
||||||
|
|
@ -80,7 +120,7 @@ var getHighest = function (first, second) {
|
||||||
return second;
|
return second;
|
||||||
};
|
};
|
||||||
var attemptMakeStream = function (_a) {
|
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 langMatch = function (stream) {
|
||||||
var _a;
|
var _a;
|
||||||
return ((langTag === 'und'
|
return ((langTag === 'und'
|
||||||
|
|
@ -131,6 +171,10 @@ var attemptMakeStream = function (_a) {
|
||||||
streamCopy.index = streams.length;
|
streamCopy.index = streams.length;
|
||||||
streamCopy.outputArgs.push('-c:{outputIndex}', audioEncoder);
|
streamCopy.outputArgs.push('-c:{outputIndex}', audioEncoder);
|
||||||
streamCopy.outputArgs.push('-ac', "".concat(targetChannels));
|
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
|
// eslint-disable-next-line no-param-reassign
|
||||||
args.variables.ffmpegCommand.shouldProcess = true;
|
args.variables.ffmpegCommand.shouldProcess = true;
|
||||||
streams.push(streamCopy);
|
streams.push(streamCopy);
|
||||||
|
|
@ -144,6 +188,8 @@ var plugin = function (args) {
|
||||||
var audioEncoder = String(args.inputs.audioEncoder);
|
var audioEncoder = String(args.inputs.audioEncoder);
|
||||||
var langTag = String(args.inputs.language).toLowerCase();
|
var langTag = String(args.inputs.language).toLowerCase();
|
||||||
var wantedChannelCount = Number(args.inputs.channels);
|
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 streams = args.variables.ffmpegCommand.streams;
|
||||||
var audioCodec = audioEncoder;
|
var audioCodec = audioEncoder;
|
||||||
if (audioEncoder === 'dca') {
|
if (audioEncoder === 'dca') {
|
||||||
|
|
@ -162,6 +208,8 @@ var plugin = function (args) {
|
||||||
audioCodec: audioCodec,
|
audioCodec: audioCodec,
|
||||||
audioEncoder: audioEncoder,
|
audioEncoder: audioEncoder,
|
||||||
wantedChannelCount: wantedChannelCount,
|
wantedChannelCount: wantedChannelCount,
|
||||||
|
enableBitrate: enableBitrate,
|
||||||
|
bitrate: bitrate,
|
||||||
});
|
});
|
||||||
if (!addedOrExists) {
|
if (!addedOrExists) {
|
||||||
attemptMakeStream({
|
attemptMakeStream({
|
||||||
|
|
@ -171,6 +219,8 @@ var plugin = function (args) {
|
||||||
audioCodec: audioCodec,
|
audioCodec: audioCodec,
|
||||||
audioEncoder: audioEncoder,
|
audioEncoder: audioEncoder,
|
||||||
wantedChannelCount: wantedChannelCount,
|
wantedChannelCount: wantedChannelCount,
|
||||||
|
enableBitrate: enableBitrate,
|
||||||
|
bitrate: bitrate,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { getFfType } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||||
import {
|
import {
|
||||||
IffmpegCommandStream,
|
IffmpegCommandStream,
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
|
|
@ -70,6 +71,47 @@ const details = (): IpluginDetails => ({
|
||||||
tooltip:
|
tooltip:
|
||||||
'Enter the desired number of channels',
|
'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: [
|
outputs: [
|
||||||
{
|
{
|
||||||
|
|
@ -94,6 +136,8 @@ const attemptMakeStream = ({
|
||||||
audioCodec,
|
audioCodec,
|
||||||
audioEncoder,
|
audioEncoder,
|
||||||
wantedChannelCount,
|
wantedChannelCount,
|
||||||
|
enableBitrate,
|
||||||
|
bitrate,
|
||||||
}: {
|
}: {
|
||||||
args: IpluginInputArgs,
|
args: IpluginInputArgs,
|
||||||
langTag: string
|
langTag: string
|
||||||
|
|
@ -101,6 +145,8 @@ const attemptMakeStream = ({
|
||||||
audioCodec: string,
|
audioCodec: string,
|
||||||
audioEncoder: string,
|
audioEncoder: string,
|
||||||
wantedChannelCount: number,
|
wantedChannelCount: number,
|
||||||
|
enableBitrate: boolean,
|
||||||
|
bitrate: string,
|
||||||
}): boolean => {
|
}): boolean => {
|
||||||
const langMatch = (stream: IffmpegCommandStream) => (
|
const langMatch = (stream: IffmpegCommandStream) => (
|
||||||
(langTag === 'und'
|
(langTag === 'und'
|
||||||
|
|
@ -166,6 +212,11 @@ const attemptMakeStream = ({
|
||||||
streamCopy.outputArgs.push('-c:{outputIndex}', audioEncoder);
|
streamCopy.outputArgs.push('-c:{outputIndex}', audioEncoder);
|
||||||
streamCopy.outputArgs.push('-ac', `${targetChannels}`);
|
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
|
// eslint-disable-next-line no-param-reassign
|
||||||
args.variables.ffmpegCommand.shouldProcess = true;
|
args.variables.ffmpegCommand.shouldProcess = true;
|
||||||
|
|
||||||
|
|
@ -183,6 +234,8 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||||
const audioEncoder = String(args.inputs.audioEncoder);
|
const audioEncoder = String(args.inputs.audioEncoder);
|
||||||
const langTag = String(args.inputs.language).toLowerCase();
|
const langTag = String(args.inputs.language).toLowerCase();
|
||||||
const wantedChannelCount = Number(args.inputs.channels);
|
const wantedChannelCount = Number(args.inputs.channels);
|
||||||
|
const enableBitrate = Boolean(args.inputs.enableBitrate);
|
||||||
|
const bitrate = String(args.inputs.bitrate);
|
||||||
|
|
||||||
const { streams } = args.variables.ffmpegCommand;
|
const { streams } = args.variables.ffmpegCommand;
|
||||||
|
|
||||||
|
|
@ -207,6 +260,8 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||||
audioCodec,
|
audioCodec,
|
||||||
audioEncoder,
|
audioEncoder,
|
||||||
wantedChannelCount,
|
wantedChannelCount,
|
||||||
|
enableBitrate,
|
||||||
|
bitrate,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!addedOrExists) {
|
if (!addedOrExists) {
|
||||||
|
|
@ -217,6 +272,8 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||||
audioCodec,
|
audioCodec,
|
||||||
audioEncoder,
|
audioEncoder,
|
||||||
wantedChannelCount,
|
wantedChannelCount,
|
||||||
|
enableBitrate,
|
||||||
|
bitrate,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue