Skip to content

Commit

Permalink
add ability to upmix channels with a filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sipnol committed Oct 13, 2024
1 parent 71f468f commit 9b66243
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.plugin = exports.details = void 0;
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
var flowUtils_1 = require("../../../../FlowHelpers/1.0.0/interfaces/flowUtils");
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
var details = function () { return ({
Expand All @@ -17,6 +16,26 @@ var details = function () { return ({
sidebarPosition: -1,
icon: '',
inputs: [
{
label: 'Name of new audio stream',
name: 'streamName',
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
},
tooltip: 'Tdarr will add this name to the metadata title of the audio stream.',
},
{
label: 'Modify existing audio tracks Title',
name: 'enableTitleAdjust',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'switch',
},
tooltip: 'Append "(original)" to the existing audio tracks Title',
},
{
label: 'Audio Encoder',
name: 'audioEncoder',
Expand Down Expand Up @@ -135,6 +154,41 @@ var details = function () { return ({
},
tooltip: 'Specify the audio samplerate for newly added channels',
},
{
label: 'Enable Upmixing',
name: 'enableUpmixing',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'switch',
},
tooltip: 'Toggle whether to enable setting audio upmixing this will only get used if there is no higher channel count available',
},
{
label: 'Upmixing pan filter',
name: 'upmixingFilter',
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'enableUpmixing',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip: 'Specify the audio filter for upmixing to desired channels',
},
],
outputs: [
{
Expand All @@ -157,6 +211,9 @@ var attemptMakeStream = function (_a) {
var bitrate = String(args.inputs.bitrate);
var enableSamplerate = Boolean(args.inputs.enableSamplerate);
var samplerate = String(args.inputs.samplerate);
var enableUpmixing = Boolean(args.inputs.enableUpmixing);
var upmixingFilter = String(args.inputs.upmixingFilter);
var streamName = String(args.inputs.streamName);
var langMatch = function (stream) {
var _a;
return ((langTag === 'und'
Expand Down Expand Up @@ -184,6 +241,11 @@ var attemptMakeStream = function (_a) {
args.jobLog("The wanted channel count ".concat(wantedChannelCount, " is <= than the")
+ " highest available channel count (".concat(streamWithHighestChannel.channels, "). \n"));
}
else if (enableUpmixing) {
targetChannels = wantedChannelCount;
args.jobLog("The wanted channel count ".concat(wantedChannelCount, " is higher than the")
+ " highest available channel count (".concat(streamWithHighestChannel.channels, "). Will upmix audio.\n"));
}
else {
targetChannels = highestChannelCount;
args.jobLog("The wanted channel count ".concat(wantedChannelCount, " is higher than the")
Expand All @@ -206,15 +268,24 @@ var attemptMakeStream = function (_a) {
var streamCopy = JSON.parse(JSON.stringify(streamWithHighestChannel));
streamCopy.removed = false;
streamCopy.index = streams.length;
if (targetChannels > highestChannelCount && upmixingFilter !== '') {
streamCopy.outputArgs.push('-filter_complex', "[".concat(streamCopy.mapArgs[1], "]").concat(upmixingFilter, "[a_{outputIndex}]"));
streamCopy.outputArgs.push('-map', '[a_{outputIndex}]');
streamCopy.mapArgs = [];
}
else {
streamCopy.outputArgs.push('-ac', "".concat(targetChannels));
}
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));
streamCopy.outputArgs.push("-b:a:{outputTypeIndex}", "".concat(bitrate));
}
if (enableSamplerate) {
streamCopy.outputArgs.push('-ar', "".concat(samplerate));
}
if (streamName !== '') {
streamCopy.outputArgs.push('-metadata:s:a:{outputTypeIndex}', "title=".concat(streamName));
}
// eslint-disable-next-line no-param-reassign
args.variables.ffmpegCommand.shouldProcess = true;
streams.push(streamCopy);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getFfType } from '../../../../FlowHelpers/1.0.0/fileUtils';
import { checkFfmpegCommandInit } from '../../../../FlowHelpers/1.0.0/interfaces/flowUtils';
import {
IffmpegCommandStream,
Expand All @@ -21,6 +20,17 @@ const details = (): IpluginDetails => ({
sidebarPosition: -1,
icon: '',
inputs: [
{
label: 'Name of new audio stream',
name: 'streamName',
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
},
tooltip:
'Tdarr will add this name to the metadata title of the audio stream.',
},
{
label: 'Audio Encoder',
name: 'audioEncoder',
Expand Down Expand Up @@ -146,6 +156,44 @@ const details = (): IpluginDetails => ({
tooltip:
'Specify the audio samplerate for newly added channels',
},
{
label: 'Enable Upmixing',
name: 'enableUpmixing',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'switch',
},
tooltip:
'Toggle whether to enable setting audio upmixing this'
+ 'will only get used if there is no higher channel count available',
},
{
label: 'Upmixing pan filter',
name: 'upmixingFilter',
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'enableUpmixing',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip:
'Specify the audio filter for upmixing to desired channels',
},
],
outputs: [
{
Expand Down Expand Up @@ -182,6 +230,9 @@ const attemptMakeStream = ({
const bitrate = String(args.inputs.bitrate);
const enableSamplerate = Boolean(args.inputs.enableSamplerate);
const samplerate = String(args.inputs.samplerate);
const enableUpmixing = Boolean(args.inputs.enableUpmixing);
const upmixingFilter = String(args.inputs.upmixingFilter);
const streamName = String(args.inputs.streamName);

const langMatch = (stream: IffmpegCommandStream) => (
(langTag === 'und'
Expand Down Expand Up @@ -216,6 +267,10 @@ const attemptMakeStream = ({
targetChannels = wantedChannelCount;
args.jobLog(`The wanted channel count ${wantedChannelCount} is <= than the`
+ ` highest available channel count (${streamWithHighestChannel.channels}). \n`);
} else if (enableUpmixing) {
targetChannels = wantedChannelCount;
args.jobLog(`The wanted channel count ${wantedChannelCount} is higher than the`
+ ` highest available channel count (${streamWithHighestChannel.channels}). Will upmix audio.\n`);
} else {
targetChannels = highestChannelCount;
args.jobLog(`The wanted channel count ${wantedChannelCount} is higher than the`
Expand Down Expand Up @@ -245,18 +300,27 @@ const attemptMakeStream = ({
const streamCopy: IffmpegCommandStream = JSON.parse(JSON.stringify(streamWithHighestChannel));
streamCopy.removed = false;
streamCopy.index = streams.length;
if (targetChannels > highestChannelCount && upmixingFilter !== '') {
streamCopy.outputArgs.push('-filter_complex', `[${streamCopy.mapArgs[1]}]${upmixingFilter}[a_{outputIndex}]`);
streamCopy.outputArgs.push('-map', '[a_{outputIndex}]');
streamCopy.mapArgs = [];
} else {
streamCopy.outputArgs.push('-ac', `${targetChannels}`);
}
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}`);
streamCopy.outputArgs.push('-b:a:{outputTypeIndex}', `${bitrate}`);
}

if (enableSamplerate) {
streamCopy.outputArgs.push('-ar', `${samplerate}`);
}

if (streamName !== '') {
streamCopy.outputArgs.push('-metadata:s:a:{outputTypeIndex}', `title=${streamName}`);
}

// eslint-disable-next-line no-param-reassign
args.variables.ffmpegCommand.shouldProcess = true;

Expand Down

0 comments on commit 9b66243

Please sign in to comment.