mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-15 10:15:54 -07:00
lint
This commit is contained in:
parent
93217a09a9
commit
3b63f8a5b6
1 changed files with 201 additions and 195 deletions
|
|
@ -1,4 +1,10 @@
|
||||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||||
|
/* eslint max-len: 0 */
|
||||||
|
/* eslint no-bitwise: 0 */
|
||||||
|
/* eslint no-mixed-operators: 0 */
|
||||||
|
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
function details() {
|
function details() {
|
||||||
return {
|
return {
|
||||||
id: 'Tdarr_Plugin_ER01_Transcode audio and video with HW (PC and Mac)',
|
id: 'Tdarr_Plugin_ER01_Transcode audio and video with HW (PC and Mac)',
|
||||||
|
|
@ -7,10 +13,10 @@ function details() {
|
||||||
Type: 'Video',
|
Type: 'Video',
|
||||||
Operation: 'Transcode',
|
Operation: 'Transcode',
|
||||||
Description: `Files not in H265 will be transcoded into H265 using hw with ffmpeg, assuming mkv container. Plugin uses QS if the node runs on a PC, or Videotoolbox if run on a Mac.
|
Description: `Files not in H265 will be transcoded into H265 using hw with ffmpeg, assuming mkv container. Plugin uses QS if the node runs on a PC, or Videotoolbox if run on a Mac.
|
||||||
Much thanks to Migz for bulk of the important code.
|
Much thanks to Migz for bulk of the important code.
|
||||||
Quality is controlled via bitrate adjustments - H264 to H265 assumes 0.5x bitrate. Resolution change from 1080p to 720p assumes 0.7x bitrate.
|
Quality is controlled via bitrate adjustments - H264 to H265 assumes 0.5x bitrate. Resolution change from 1080p to 720p assumes 0.7x bitrate.
|
||||||
Audio conversion is either 2 channel ac3 or 6 channel ac3, for maximal compatibility and small file size. All subtitles removed.
|
Audio conversion is either 2 channel ac3 or 6 channel ac3, for maximal compatibility and small file size. All subtitles removed.
|
||||||
The idea is to homogenize your collection to 1080p or higher movies with 5.1 audio, or 720p TV shows with 2.0 audio.`,
|
The idea is to homogenize your collection to 1080p or higher movies with 5.1 audio, or 720p TV shows with 2.0 audio.`,
|
||||||
|
|
||||||
Tags: 'pre-processing,ffmpeg,video only,configurable,h265',
|
Tags: 'pre-processing,ffmpeg,video only,configurable,h265',
|
||||||
Inputs: [{
|
Inputs: [{
|
||||||
|
|
@ -32,7 +38,7 @@ function details() {
|
||||||
\\nExample:\\n
|
\\nExample:\\n
|
||||||
no`,
|
no`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'bitrate_cutoff',
|
name: 'bitrate_cutoff',
|
||||||
tooltip: `Specify bitrate cutoff, files with a current bitrate lower then this will not be transcoded.
|
tooltip: `Specify bitrate cutoff, files with a current bitrate lower then this will not be transcoded.
|
||||||
\\n Rate is in kbps.
|
\\n Rate is in kbps.
|
||||||
|
|
@ -64,7 +70,7 @@ function plugin(file, librarySettings, inputs) {
|
||||||
let convertAudio = false;
|
let convertAudio = false;
|
||||||
let convertVideo = false;
|
let convertVideo = false;
|
||||||
let extraArguments = '';
|
let extraArguments = '';
|
||||||
|
|
||||||
// Check if inputs.container has been configured. If it hasn't then exit plugin.
|
// Check if inputs.container has been configured. If it hasn't then exit plugin.
|
||||||
if (inputs.container === '') {
|
if (inputs.container === '') {
|
||||||
response.infoLog += 'Plugin has not been configured, please configure required options. Skipping this plugin. \n';
|
response.infoLog += 'Plugin has not been configured, please configure required options. Skipping this plugin. \n';
|
||||||
|
|
@ -79,23 +85,20 @@ function plugin(file, librarySettings, inputs) {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
const os = require('os');
|
// VIDEO SECTION
|
||||||
|
|
||||||
|
let bitRateMultiplier = 1.00;
|
||||||
|
let videoIdx = -1;
|
||||||
|
let willBeResized = false;
|
||||||
|
let videoOptions = '-map 0:v -c:v copy ';
|
||||||
|
|
||||||
// VIDEO SECTION
|
// video options
|
||||||
|
// hevc, 1080, false - do nothing
|
||||||
let bitRateMultiplier = 1.00;
|
// hevc, not 1080 - do nothing
|
||||||
let videoIdx = -1;
|
// hevc, 1080, true - resize, mult 0.5
|
||||||
let willBeResized = false;
|
// not hevc, 1080, true - resize, mult 0.25
|
||||||
let videoOptions = `-map 0:v -c:v copy `;
|
// not hevc, 1080, false - no resize, mult 0.5
|
||||||
|
// not hevc, not 1080 - no resize, mult 0.5
|
||||||
// video options
|
|
||||||
// hevc, 1080, false - do nothing
|
|
||||||
// hevc, not 1080 - do nothing
|
|
||||||
// hevc, 1080, true - resize, mult 0.5
|
|
||||||
// not hevc, 1080, true - resize, mult 0.25
|
|
||||||
// not hevc, 1080, false - no resize, mult 0.5
|
|
||||||
// not hevc, not 1080 - no resize, mult 0.5
|
|
||||||
|
|
||||||
// Go through each stream in the file.
|
// Go through each stream in the file.
|
||||||
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||||
|
|
@ -103,44 +106,50 @@ let videoOptions = `-map 0:v -c:v copy `;
|
||||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'video') {
|
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'video') {
|
||||||
// Check if codec of stream is mjpeg/png. If so then remove this "video" stream.
|
// Check if codec of stream is mjpeg/png. If so then remove this "video" stream.
|
||||||
// mjpeg/png are usually embedded pictures that can cause havoc with plugins.
|
// mjpeg/png are usually embedded pictures that can cause havoc with plugins.
|
||||||
if (file.ffProbeData.streams[i].codec_name === 'mjpeg' || file.ffProbeData.streams[i].codec_name === 'png' ) {
|
if (file.ffProbeData.streams[i].codec_name === 'mjpeg' || file.ffProbeData.streams[i].codec_name === 'png') {
|
||||||
extraArguments += `-map -v:${videoIdx} `;
|
extraArguments += `-map -v:${videoIdx} `;
|
||||||
convertVideo = true; }
|
convertVideo = true;
|
||||||
/* // no video conversion if: hevc, 1080, false OR hevc, not 1080
|
}
|
||||||
if (file.ffProbeData.streams[i].codec_name === 'hevc'
|
/* // no video conversion if: hevc, 1080, false OR hevc, not 1080
|
||||||
&& ((file.video_resolution === '1080p' && inputs.resize === 'no' ) || (file.video_resolution !== '1080p' ))) {
|
if (file.ffProbeData.streams[i].codec_name === 'hevc'
|
||||||
|
&& ((file.video_resolution === '1080p' && inputs.resize === 'no' ) || (file.video_resolution !== '1080p' ))) {
|
||||||
convertVideo = false; } */
|
convertVideo = false; } */
|
||||||
// no video conversion if: hevc, 1080, false
|
// no video conversion if: hevc, 1080, false
|
||||||
if (file.ffProbeData.streams[i].codec_name === 'hevc' && file.ffProbeData.streams[i].width > 1800 && file.ffProbeData.streams[i].width < 2000 && inputs.resize === 'no' ) {
|
if (file.ffProbeData.streams[i].codec_name === 'hevc' && file.ffProbeData.streams[i].width > 1800 && file.ffProbeData.streams[i].width < 2000 && inputs.resize === 'no') {
|
||||||
convertVideo = false; }
|
convertVideo = false;
|
||||||
// no video conversion if: hevc, not 1080
|
}
|
||||||
if (file.ffProbeData.streams[i].codec_name === 'hevc' && (file.ffProbeData.streams[i].width < 1800 || file.ffProbeData.streams[i].width > 2000)) {
|
// no video conversion if: hevc, not 1080
|
||||||
convertVideo = false; }
|
if (file.ffProbeData.streams[i].codec_name === 'hevc' && (file.ffProbeData.streams[i].width < 1800 || file.ffProbeData.streams[i].width > 2000)) {
|
||||||
// resize video if: hevc, 1080, true
|
convertVideo = false;
|
||||||
if (file.ffProbeData.streams[i].codec_name === 'hevc' && file.ffProbeData.streams[i].width > 1800 && file.ffProbeData.streams[i].width < 2000 && inputs.resize === 'yes' ) {
|
}
|
||||||
convertVideo = true;
|
// resize video if: hevc, 1080, true
|
||||||
willBeResized = true;
|
if (file.ffProbeData.streams[i].codec_name === 'hevc' && file.ffProbeData.streams[i].width > 1800 && file.ffProbeData.streams[i].width < 2000 && inputs.resize === 'yes') {
|
||||||
bitRateMultiplier = 0.7; }
|
convertVideo = true;
|
||||||
// resize video if: not hevc, 1080, true
|
willBeResized = true;
|
||||||
if (file.ffProbeData.streams[i].codec_name !== 'hevc' && file.ffProbeData.streams[i].width > 1800 && file.ffProbeData.streams[i].width < 2000 && inputs.resize === 'yes' ) {
|
bitRateMultiplier = 0.7;
|
||||||
convertVideo = true;
|
}
|
||||||
willBeResized = true;
|
// resize video if: not hevc, 1080, true
|
||||||
bitRateMultiplier = 0.4; }
|
if (file.ffProbeData.streams[i].codec_name !== 'hevc' && file.ffProbeData.streams[i].width > 1800 && file.ffProbeData.streams[i].width < 2000 && inputs.resize === 'yes') {
|
||||||
// no resize video if: not hevc, 1080, false
|
convertVideo = true;
|
||||||
if (file.ffProbeData.streams[i].codec_name !== 'hevc' && file.ffProbeData.streams[i].width > 1800 && file.ffProbeData.streams[i].width < 2000 && inputs.resize === 'no' ) {
|
willBeResized = true;
|
||||||
convertVideo = true;
|
bitRateMultiplier = 0.4;
|
||||||
bitRateMultiplier = 0.5; }
|
}
|
||||||
// no resize video if: not hevc, not 1080
|
// no resize video if: not hevc, 1080, false
|
||||||
if (file.ffProbeData.streams[i].codec_name !== 'hevc' && file.ffProbeData.streams[i].width < 1800 ) {
|
if (file.ffProbeData.streams[i].codec_name !== 'hevc' && file.ffProbeData.streams[i].width > 1800 && file.ffProbeData.streams[i].width < 2000 && inputs.resize === 'no') {
|
||||||
convertVideo = true;
|
convertVideo = true;
|
||||||
bitRateMultiplier = 0.5; }
|
bitRateMultiplier = 0.5;
|
||||||
|
}
|
||||||
|
// no resize video if: not hevc, not 1080
|
||||||
|
if (file.ffProbeData.streams[i].codec_name !== 'hevc' && file.ffProbeData.streams[i].width < 1800) {
|
||||||
|
convertVideo = true;
|
||||||
|
bitRateMultiplier = 0.5;
|
||||||
}
|
}
|
||||||
// Increment videoIdx.
|
|
||||||
videoIdx += 1;
|
|
||||||
}
|
}
|
||||||
|
// Increment videoIdx.
|
||||||
|
videoIdx += 1;
|
||||||
|
}
|
||||||
|
|
||||||
// figure out final bitrate
|
// figure out final bitrate
|
||||||
// Check if duration info is filled, if so times it by 0.0166667 to get time in minutes.
|
// Check if duration info is filled, if so times it by 0.0166667 to get time in minutes.
|
||||||
// If not filled then get duration of stream 0 and do the same.
|
// If not filled then get duration of stream 0 and do the same.
|
||||||
if (typeof file.meta.Duration !== 'undefined') {
|
if (typeof file.meta.Duration !== 'undefined') {
|
||||||
|
|
@ -168,21 +177,21 @@ let videoOptions = `-map 0:v -c:v copy `;
|
||||||
response.infoLog += 'Target bitrate could not be calculated. Skipping this plugin. \n';
|
response.infoLog += 'Target bitrate could not be calculated. Skipping this plugin. \n';
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if inputs.bitrate cutoff has something entered.
|
// Check if inputs.bitrate cutoff has something entered.
|
||||||
// (Entered means user actually wants something to happen, empty would disable this).
|
// (Entered means user actually wants something to happen, empty would disable this).
|
||||||
if (inputs.bitrate_cutoff !== '') {
|
if (inputs.bitrate_cutoff !== '') {
|
||||||
// Checks if currentBitrate is below inputs.bitrate_cutoff
|
// Checks if currentBitrate is below inputs.bitrate_cutoff
|
||||||
// If so then don't convert video.
|
// If so then don't convert video.
|
||||||
if (currentBitrate <= inputs.bitrate_cutoff) {
|
if (currentBitrate <= inputs.bitrate_cutoff) {
|
||||||
convertVideo = false; }
|
convertVideo = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AUDIO SECTION
|
||||||
|
|
||||||
// AUDIO SECTION
|
// Set up required variables.
|
||||||
|
let audioOptions = '-map 0:a -c:a copy ';
|
||||||
// Set up required variables.
|
|
||||||
let audioOptions = `-map 0:a -c:a copy `;
|
|
||||||
let audioIdx = 0;
|
let audioIdx = 0;
|
||||||
let numberofAudioChannels = 0;
|
let numberofAudioChannels = 0;
|
||||||
let has2Channels = false;
|
let has2Channels = false;
|
||||||
|
|
@ -196,197 +205,194 @@ let videoOptions = `-map 0:v -c:v copy `;
|
||||||
let type8Channels = '';
|
let type8Channels = '';
|
||||||
|
|
||||||
let keepAudioIdx = -1;
|
let keepAudioIdx = -1;
|
||||||
let keepIGuessAudioIdx = -1;
|
// const keepIGuessAudioIdx = -1;
|
||||||
let encodeAudioIdx = -1;
|
let encodeAudioIdx = -1;
|
||||||
let keepAudioStream = -1;
|
let keepAudioStream = -1;
|
||||||
let encodeAudioStream = -1;
|
let encodeAudioStream = -1;
|
||||||
let originalAudio = '';
|
let originalAudio = '';
|
||||||
|
|
||||||
// Go through each stream in the file.
|
// Go through each stream in the file.
|
||||||
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||||
try {
|
try {
|
||||||
// Go through all audio streams and check if 2,6 & 8 channel tracks exist or not.
|
// Go through all audio streams and check if 2,6 & 8 channel tracks exist or not.
|
||||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio') {
|
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio') {
|
||||||
numberofAudioChannels += 1;
|
numberofAudioChannels += 1;
|
||||||
if (file.ffProbeData.streams[i].channels === 2 && has2Channels === false) {
|
if (file.ffProbeData.streams[i].channels === 2 && has2Channels === false) {
|
||||||
has2Channels = true;
|
has2Channels = true;
|
||||||
lang2Channels = file.ffProbeData.streams[i].tags.language.toLowerCase();
|
lang2Channels = file.ffProbeData.streams[i].tags.language.toLowerCase();
|
||||||
type2Channels = file.ffProbeData.streams[i].codec_name.toLowerCase();
|
type2Channels = file.ffProbeData.streams[i].codec_name.toLowerCase();
|
||||||
}
|
}
|
||||||
if (file.ffProbeData.streams[i].channels === 6 && has6Channels === false) {
|
if (file.ffProbeData.streams[i].channels === 6 && has6Channels === false) {
|
||||||
has6Channels = true;
|
has6Channels = true;
|
||||||
lang6Channels = file.ffProbeData.streams[i].tags.language.toLowerCase();
|
lang6Channels = file.ffProbeData.streams[i].tags.language.toLowerCase();
|
||||||
type6Channels = file.ffProbeData.streams[i].codec_name.toLowerCase();
|
type6Channels = file.ffProbeData.streams[i].codec_name.toLowerCase();
|
||||||
}
|
}
|
||||||
if (file.ffProbeData.streams[i].channels === 8 && has8Channels === false) {
|
if (file.ffProbeData.streams[i].channels === 8 && has8Channels === false) {
|
||||||
has8Channels = true;
|
has8Channels = true;
|
||||||
lang8Channels = file.ffProbeData.streams[i].tags.language.toLowerCase();
|
lang8Channels = file.ffProbeData.streams[i].tags.language.toLowerCase();
|
||||||
type8Channels = file.ffProbeData.streams[i].codec_name.toLowerCase();
|
type8Channels = file.ffProbeData.streams[i].codec_name.toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Error
|
// Error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Are we processing for 6 channels?
|
||||||
// Are we processing for 6 channels?
|
if (inputs.audio_channels === 6) {
|
||||||
if (inputs.audio_channels == 6) {
|
audioIdx = -1;
|
||||||
audioIdx = -1;
|
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||||
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
try {
|
||||||
try {
|
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio') {
|
||||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio') {
|
audioIdx += 1;
|
||||||
audioIdx += 1;
|
if (file.ffProbeData.streams[i].tags.language.toLowerCase() === 'eng' || file.ffProbeData.streams[i].tags.language.toLowerCase() === 'und') {
|
||||||
if (file.ffProbeData.streams[i].tags.language.toLowerCase() === 'eng' || file.ffProbeData.streams[i].tags.language.toLowerCase() === 'und') {
|
if (file.ffProbeData.streams[i].channels === 6) {
|
||||||
if (file.ffProbeData.streams[i].channels == 6 ) {
|
if (file.ffProbeData.streams[i].codec_name.toLowerCase() === 'ac3') {
|
||||||
if (file.ffProbeData.streams[i].codec_name.toLowerCase() === 'ac3') {
|
// response.infoLog += `Found 6 channel audio in proper language and codec, audio stream ${audioIdx}\n`;
|
||||||
//response.infoLog += `Found 6 channel audio in proper language and codec, audio stream ${audioIdx}\n`;
|
if (keepAudioIdx === -1) {
|
||||||
if (keepAudioIdx === -1) {
|
keepAudioIdx = audioIdx;
|
||||||
keepAudioIdx = audioIdx;
|
keepAudioStream = i;
|
||||||
keepAudioStream = i;}
|
}
|
||||||
} else {
|
} else if (encodeAudioIdx === -1) {
|
||||||
//response.infoLog += `Found 6 channel audio in proper language, need to re-encode, audio stream ${audioIdx}\n`;
|
// response.infoLog += `Found 6 channel audio in proper language, need to re-encode, audio stream ${audioIdx}\n`;
|
||||||
if (encodeAudioIdx === -1) {
|
encodeAudioIdx = audioIdx;
|
||||||
encodeAudioIdx = audioIdx;
|
encodeAudioStream = i;
|
||||||
encodeAudioStream = i;}
|
}
|
||||||
}}
|
}
|
||||||
if (file.ffProbeData.streams[i].channels > 6 ) {
|
if (file.ffProbeData.streams[i].channels > 6) {
|
||||||
//response.infoLog += `Found existing multi-channel audio in proper language, need to re-encode, audio stream ${audioIdx}\n`;
|
// response.infoLog += `Found existing multi-channel audio in proper language, need to re-encode, audio stream ${audioIdx}\n`;
|
||||||
if (encodeAudioIdx === -1) {
|
if (encodeAudioIdx === -1) {
|
||||||
encodeAudioIdx = audioIdx;
|
encodeAudioIdx = audioIdx;
|
||||||
encodeAudioStream = i;}
|
encodeAudioStream = i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Error
|
// Error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (keepAudioIdx === -1 && encodeAudioIdx === -1) { // didn't find any 5.1 or better audio streams in proper language, defaulting to using 2 channels
|
||||||
if (keepAudioIdx === -1 && encodeAudioIdx === -1) { // didn't find any 5.1 or better audio streams in proper language, defaulting to using 2 channels
|
// eslint-disable-next-line no-param-reassign
|
||||||
inputs.audio_channels = '2';}
|
inputs.audio_channels = '2';
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Are we processing for 2 channels?
|
|
||||||
if (inputs.audio_channels == 2) {
|
|
||||||
audioIdx = -1;
|
|
||||||
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
|
||||||
try {
|
|
||||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio') {
|
|
||||||
audioIdx += 1;
|
|
||||||
if (file.ffProbeData.streams[i].tags.language.toLowerCase() === 'eng' || file.ffProbeData.streams[i].tags.language.toLowerCase() === 'und') {
|
|
||||||
if (file.ffProbeData.streams[i].channels == 2 ) {
|
|
||||||
if (file.ffProbeData.streams[i].codec_name.toLowerCase() === 'aac' || file.ffProbeData.streams[i].codec_name.toLowerCase() === 'ac3') {
|
|
||||||
//response.infoLog += `Found 2 channel audio in proper language and codec, audio stream ${audioIdx}\n`;
|
|
||||||
if (keepAudioIdx === -1) {
|
|
||||||
keepAudioIdx = audioIdx;
|
|
||||||
keepAudioStream = i;}
|
|
||||||
} else {
|
|
||||||
//response.infoLog += `Found 2 channel audio in proper language, need to re-encode, audio stream ${audioIdx}\n`;
|
|
||||||
if (encodeAudioIdx === -1) {
|
|
||||||
encodeAudioIdx = audioIdx;
|
|
||||||
encodeAudioStream = i;}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//response.infoLog += `Found existing multi-channel audio in proper language, need to re-encode, audio stream ${audioIdx}\n`;
|
|
||||||
if (encodeAudioIdx === -1) {
|
|
||||||
encodeAudioIdx = audioIdx;
|
|
||||||
encodeAudioStream = i;}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// response.infoLog += `a ${audioIdx}. k ${keepAudioIdx}. e ${encodeAudioIdx}\n `;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// Error
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// Are we processing for 2 channels?
|
||||||
|
if (inputs.audio_channels === 2) {
|
||||||
|
audioIdx = -1;
|
||||||
|
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||||
|
try {
|
||||||
|
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio') {
|
||||||
|
audioIdx += 1;
|
||||||
|
if (file.ffProbeData.streams[i].tags.language.toLowerCase() === 'eng' || file.ffProbeData.streams[i].tags.language.toLowerCase() === 'und') {
|
||||||
|
if (file.ffProbeData.streams[i].channels === 2) {
|
||||||
|
if (file.ffProbeData.streams[i].codec_name.toLowerCase() === 'aac' || file.ffProbeData.streams[i].codec_name.toLowerCase() === 'ac3') {
|
||||||
|
// response.infoLog += `Found 2 channel audio in proper language and codec, audio stream ${audioIdx}\n`;
|
||||||
|
if (keepAudioIdx === -1) {
|
||||||
|
keepAudioIdx = audioIdx;
|
||||||
|
keepAudioStream = i;
|
||||||
|
}
|
||||||
|
} else if (encodeAudioIdx === -1) {
|
||||||
|
// response.infoLog += `Found 2 channel audio in proper language, need to re-encode, audio stream ${audioIdx}\n`;
|
||||||
|
encodeAudioIdx = audioIdx;
|
||||||
|
encodeAudioStream = i;
|
||||||
|
}
|
||||||
|
} else if (encodeAudioIdx === -1) {
|
||||||
|
// response.infoLog += `Found existing multi-channel audio in proper language, need to re-encode, audio stream ${audioIdx}\n`;
|
||||||
|
encodeAudioIdx = audioIdx;
|
||||||
|
encodeAudioStream = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// response.infoLog += `a ${audioIdx}. k ${keepAudioIdx}. e ${encodeAudioIdx}\n `;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// Error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let audioMessage = '';
|
let audioMessage = '';
|
||||||
|
|
||||||
// selecting channels to keep, only if 2 or 6 channels processed
|
// selecting channels to keep, only if 2 or 6 channels processed
|
||||||
|
|
||||||
if (keepAudioIdx !== -1) {
|
if (keepAudioIdx !== -1) {
|
||||||
//keep audio, exclude everything else
|
// keep audio, exclude everything else
|
||||||
if (numberofAudioChannels !== 1) {
|
if (numberofAudioChannels !== 1) {
|
||||||
convertAudio = true;
|
convertAudio = true;
|
||||||
audioMessage += `keeping audio stream ${keepAudioIdx}.`;
|
audioMessage += `keeping audio stream ${keepAudioIdx}.`;
|
||||||
audioOptions = `-map 0:a:${keepAudioIdx} -c:a copy `;
|
audioOptions = `-map 0:a:${keepAudioIdx} -c:a copy `;
|
||||||
originalAudio += `${file.ffProbeData.streams[keepAudioStream].channels} channel ${file.ffProbeData.streams[keepAudioStream].codec_name} --> ${inputs.audio_channels} channel ac3`;}
|
originalAudio += `${file.ffProbeData.streams[keepAudioStream].channels} channel ${file.ffProbeData.streams[keepAudioStream].codec_name} --> ${inputs.audio_channels} channel ac3`;
|
||||||
|
}
|
||||||
|
} else if (encodeAudioIdx !== -1) {
|
||||||
|
// encode this audio
|
||||||
|
convertAudio = true;
|
||||||
|
audioMessage += `encoding audio stream ${encodeAudioIdx}. `;
|
||||||
|
audioOptions = `-map 0:a:${encodeAudioIdx} -c:a ac3 -ac ${inputs.audio_channels} `; // 2 or 6 channels encoding
|
||||||
|
originalAudio += `${file.ffProbeData.streams[encodeAudioStream].channels} channel ${file.ffProbeData.streams[encodeAudioStream].codec_name} --> ${inputs.audio_channels} channel ac3`;
|
||||||
} else {
|
} else {
|
||||||
if (encodeAudioIdx !== -1) {
|
// do not encode audio
|
||||||
// encode this audio
|
convertAudio = false;
|
||||||
convertAudio = true;
|
audioMessage += 'no audio to encode.';
|
||||||
audioMessage += `encoding audio stream ${encodeAudioIdx}. `;
|
|
||||||
audioOptions = `-map 0:a:${encodeAudioIdx} -c:a ac3 -ac ${inputs.audio_channels} `; // 2 or 6 channels encoding
|
|
||||||
originalAudio += `${file.ffProbeData.streams[encodeAudioStream].channels} channel ${file.ffProbeData.streams[encodeAudioStream].codec_name} --> ${inputs.audio_channels} channel ac3`;
|
|
||||||
} else {
|
|
||||||
// do not encode audio
|
|
||||||
convertAudio = false;
|
|
||||||
audioMessage += `no audio to encode.`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test for whether the file needs to be processed - separate for video and audio convertAudio, convertVideo
|
||||||
|
|
||||||
|
|
||||||
// test for whether the file needs to be processed - separate for video and audio convertAudio, convertVideo
|
|
||||||
|
|
||||||
if (convertAudio === false && convertVideo === false) { // if nothing to do, exit
|
if (convertAudio === false && convertVideo === false) { // if nothing to do, exit
|
||||||
response.infoLog += `File is processed already, nothing to do`;
|
response.infoLog += 'File is processed already, nothing to do';
|
||||||
response.processFile = false;
|
response.processFile = false;
|
||||||
return response; }
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
// Generate ffmpeg command line arguments in total
|
// Generate ffmpeg command line arguments in total
|
||||||
|
|
||||||
// few defaults
|
// few defaults
|
||||||
|
|
||||||
response.preset = `, -sn `;
|
response.preset = ', -sn ';
|
||||||
|
|
||||||
|
|
||||||
if (convertVideo === true) {
|
if (convertVideo === true) {
|
||||||
// Set bitrateSettings variable using bitrate information calculated earlier.
|
// Set bitrateSettings variable using bitrate information calculated earlier.
|
||||||
bitrateSettings = `-b:v ${targetBitrate}k -minrate ${minimumBitrate}k `
|
bitrateSettings = `-b:v ${targetBitrate}k -minrate ${minimumBitrate}k `
|
||||||
+ `-maxrate ${maximumBitrate}k -bufsize ${currentBitrate}k`;
|
+ `-maxrate ${maximumBitrate}k -bufsize ${currentBitrate}k`;
|
||||||
|
|
||||||
if (willBeResized === true) {
|
if (willBeResized === true) {
|
||||||
extraArguments += `-filter:v scale=1280:-1 `; }
|
extraArguments += '-filter:v scale=1280:-1 ';
|
||||||
|
}
|
||||||
|
|
||||||
if (os.platform() === 'darwin') {
|
if (os.platform() === 'darwin') {
|
||||||
videoOptions = `-map 0:v -c:v hevc_videotoolbox -profile main `;
|
videoOptions = '-map 0:v -c:v hevc_videotoolbox -profile main ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os.platform() === 'win32') {
|
if (os.platform() === 'win32') {
|
||||||
videoOptions = `-map 0:v -c:v hevc_qsv -load_plugin hevc_hw `;
|
videoOptions = '-map 0:v -c:v hevc_qsv -load_plugin hevc_hw ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.preset += `${videoOptions} ${bitrateSettings} ${extraArguments} ${audioOptions} `;
|
response.preset += `${videoOptions} ${bitrateSettings} ${extraArguments} ${audioOptions} `;
|
||||||
|
|
||||||
|
|
||||||
let outputResolution = file.video_resolution;
|
let outputResolution = file.video_resolution;
|
||||||
if (willBeResized === true) {
|
if (willBeResized === true) {
|
||||||
outputResolution = '720p';}
|
outputResolution = '720p';
|
||||||
|
|
||||||
if (convertVideo === false) {
|
|
||||||
response.infoLog += `NOT converting video ${file.video_resolution}, ${file.video_codec_name}, bitrate = ${currentBitrate} \n`;
|
|
||||||
} else {
|
|
||||||
response.infoLog += `Converting video, `;
|
|
||||||
if (willBeResized === false ) { response.infoLog += `NOT `; }
|
|
||||||
response.infoLog += `resizing. ${file.video_resolution}, ${file.video_codec_name} --> ${outputResolution}, hevc. bitrate = ${currentBitrate} --> ${targetBitrate}, multiplier ${bitRateMultiplier}. \n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (convertAudio === true) {
|
if (convertVideo === false) {
|
||||||
response.infoLog += `Converting audio, ${audioMessage} ${originalAudio}. \n`;
|
response.infoLog += `NOT converting video ${file.video_resolution}, ${file.video_codec_name}, bitrate = ${currentBitrate} \n`;
|
||||||
} else {
|
} else {
|
||||||
response.infoLog += `Not converting audio. \n`;}
|
response.infoLog += 'Converting video, ';
|
||||||
|
if (willBeResized === false) { response.infoLog += 'NOT '; }
|
||||||
|
response.infoLog += `resizing. ${file.video_resolution}, ${file.video_codec_name} --> ${outputResolution}, hevc. bitrate = ${currentBitrate} --> ${targetBitrate}, multiplier ${bitRateMultiplier}. \n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertAudio === true) {
|
||||||
|
response.infoLog += `Converting audio, ${audioMessage} ${originalAudio}. \n`;
|
||||||
|
} else {
|
||||||
|
response.infoLog += 'Not converting audio. \n';
|
||||||
|
}
|
||||||
|
|
||||||
response.infoLog += `2 channels - ${lang2Channels} ${type2Channels} \n`;
|
response.infoLog += `2 channels - ${lang2Channels} ${type2Channels} \n`;
|
||||||
response.infoLog += `6 channels - ${lang6Channels} ${type6Channels} \n`;
|
response.infoLog += `6 channels - ${lang6Channels} ${type6Channels} \n`;
|
||||||
response.infoLog += `8 channels - ${lang8Channels} ${type8Channels} `;
|
response.infoLog += `8 channels - ${lang8Channels} ${type8Channels} `;
|
||||||
|
|
||||||
response.processFile = true;
|
response.processFile = true;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue