scripts-video/plugins_tdarr/Tdarr_Plugin_Alex_DownmixStereo.js
Alexandre Blanco Gomez 0d358fccce Migrate from gitea
2025-09-12 11:13:14 +02:00

106 lines
3.9 KiB
JavaScript

/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = () => ({
id: 'Tdarr_Plugin_Alex_DownmixStereo',
Stage: 'Pre-processing',
Name: 'Alex-DownmixStereo',
Type: 'Audio',
Operation: 'Transcode',
Description: 'Todos los streams de audio que no sean 2.0, les hago downmix \n\n',
Version: '2.4',
Tags: 'pre-processing,ffmpeg,audio only,configurable',
Inputs: [],
});
// eslint-disable-next-line no-unused-vars
const plugin = (file, librarySettings, inputs, otherArguments) => {
const lib = require('../methods/lib')();
// eslint-disable-next-line no-unused-vars,no-param-reassign
inputs = lib.loadDefaultValues(inputs, details);
const response = {
processFile: false,
container: `.${file.container}`,
handBrakeMode: false,
FFmpegMode: true,
reQueueAfter: true,
infoLog: '',
};
// Check if file is a video. If it isn't then exit plugin.
if (file.fileMedium !== 'video') {
// eslint-disable-next-line no-console
console.log('File is not video');
response.infoLog += '☒File is not video. \n';
response.processFile = false;
return response;
}
// Set up required variables.
let ffmpegCommandInsert = '';
let audioIdx = 0;
let convert = false;
let already_converted = false;
let only_convert_dts = false;
//if (file.video_resolution.includes("1080p")){
// only_convert_dts = true;
//}
only_convert_dts = true;
// Go through each stream in the file.
if ("comment" in file.ffProbeData.format.tags){
if (file.ffProbeData.format.tags.comment.includes("2.0 tdarr")){
already_converted = true;
}
}
if ("COMMENT" in file.ffProbeData.format.tags){
if (file.ffProbeData.format.tags.COMMENT.includes("2.0 tdarr")){
already_converted = true;
}
}
// for (let i = 0; i < file.ffProbeData.streams.length; i++) {
// try {
// // Go through all audio streams and check if 2 is already converted.
// if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio') {
// if (file.ffProbeData.streams[i].channels === 2 && file.ffProbeData.streams[i].tags.title.includes("2.0 tdarr")) {
// already_converted = true;
// }
// }
// } catch (err) {
// // Error
// }
// }
// Go through each stream in the file.
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
// Check if stream is audio.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio') {
if (only_convert_dts === true){
//si la pista no es dts: continue;
if (!file.ffProbeData.streams[i].codec_long_name.includes("DCA")){
continue;
}
}
if (file.ffProbeData.streams[i].channels !== 2) {
//ffmpegCommandInsert += `-map 0:${i} -c:a:${audioIdx} libmp3lame -q:a 2 -ac 2 -metadata:s:a:${audioIdx} title="2.0 tdarr" `;
ffmpegCommandInsert += `-map 0:${i} -c:a:${audioIdx} libfdk_aac -vbr 5 -af "volume=1.66,pan=stereo|c0=0.5*c2+0.707*c0+0.707*c4+0.5*c3|c1=0.5*c2+0.707*c1+0.707*c5+0.5*c3" -metadata:s:a:${audioIdx} title="2.0 tdarr" `;
//ffmpegCommandInsert += `-map 0:${i} -c:a:${audioIdx} aac -ac 2 -metadata:s:a:${audioIdx} title="2.0 tdarr" `;
response.infoLog += `Creating 2 channel from audio stream ${audioIdx}. \n`;
convert = true;
}
audioIdx += 1;
}
}
// Convert file if convert variable is set to true.
if (convert === false || already_converted === true) {
response.infoLog += '☑File contains all required audio formats. \n';
response.processFile = false;
} else {
response.processFile = true;
response.preset = `, -map 0 -c:v copy -c:a copy ${ffmpegCommandInsert} `
+ '-strict -2 -c:s copy -metadata comment="2.0 tdarr" -max_muxing_queue_size 9999 ';
}
return response;
};
module.exports.details = details;
module.exports.plugin = plugin;