parent
658857fdf4
commit
25c4fab8d9
@ -0,0 +1,139 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
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: 'Run Classic Filter Plugin',
|
||||
description: 'Run one of Tdarr\'s classic plugins that has Operation: Filter',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'pluginSourceId',
|
||||
type: 'string',
|
||||
defaultValue: 'Community:Tdarr_Plugin_00td_filter_by_codec',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [],
|
||||
},
|
||||
tooltip: 'Specify the classic plugin ID',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File met conditions, would traditionally continue to next plugin in plugin stack',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File did not meet conditions, would traditionally break out of plugin stack',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var path, lib, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, res, container, cacheFilePath, otherArguments, result, outputNumber;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
path = require('path');
|
||||
lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
pluginSourceId = String(args.inputs.pluginSourceId);
|
||||
parts = pluginSourceId.split(':');
|
||||
pluginSource = parts[0];
|
||||
pluginId = parts[1];
|
||||
relativePluginPath = "../../../../../".concat(pluginSource, "/").concat(pluginId, ".js");
|
||||
absolutePath = path.resolve(__dirname, relativePluginPath);
|
||||
if (!(pluginSource === 'Community')) return [3 /*break*/, 1];
|
||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||
return [3 /*break*/, 3];
|
||||
case 1: return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
plugin: {
|
||||
id: pluginId,
|
||||
source: pluginSource,
|
||||
},
|
||||
})];
|
||||
case 2:
|
||||
res = _a.sent();
|
||||
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
if (classicPlugin.details().Operation !== 'Filter') {
|
||||
throw new Error("".concat('This plugin is meant for classic plugins that have '
|
||||
+ 'Operation: Filter. This classic plugin has Operation: ').concat(classicPlugin.details().Operation)
|
||||
+ 'Please use the Run Classic Transcode Flow Plugin plugin instead.');
|
||||
}
|
||||
container = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||
cacheFilePath = "".concat(args.workDir, "/tempFile_").concat(new Date().getTime(), ".").concat(container);
|
||||
otherArguments = {
|
||||
handbrakePath: args.handbrakePath,
|
||||
ffmpegPath: args.ffmpegPath,
|
||||
mkvpropeditPath: args.mkvpropeditPath,
|
||||
originalLibraryFile: args.originalLibraryFile,
|
||||
nodeHardwareType: args.nodeHardwareType,
|
||||
pluginCycle: 0,
|
||||
workerType: args.workerType,
|
||||
version: args.config.version,
|
||||
platform_arch_isdocker: args.platform_arch_isdocker,
|
||||
cacheFilePath: cacheFilePath,
|
||||
job: args.job,
|
||||
};
|
||||
return [4 /*yield*/, classicPlugin.plugin(args.inputFileObj, args.librarySettings, args.inputs, otherArguments)];
|
||||
case 4:
|
||||
result = _a.sent();
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
outputNumber = result.processFile ? 1 : 2;
|
||||
return [2 /*return*/, {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: outputNumber,
|
||||
variables: args.variables,
|
||||
}];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,262 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
var cliUtils_1 = require("../../../../FlowHelpers/1.0.0/cliUtils");
|
||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Run Classic Transcode Plugin',
|
||||
description: 'Run one of Tdarr\'s classic plugins that has Operation: Transcode',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [
|
||||
{
|
||||
name: 'pluginSourceId',
|
||||
type: 'string',
|
||||
defaultValue: 'Community:Tdarr_Plugin_MC93_Migz1FFMPEG',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [],
|
||||
},
|
||||
tooltip: 'Specify the classic plugin ID',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
var replaceContainer = function (filePath, container) {
|
||||
var parts = filePath.split('.');
|
||||
parts[parts.length - 1] = container.split('.').join('');
|
||||
return parts.join('.');
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var path, lib, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, res_1, container, cacheFilePath, otherArguments, result, cliPath_1, customArgs, isCustomConfig, presetSplit, workerCommand, cliPath, cli, res;
|
||||
var _a, _b, _c;
|
||||
return __generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
case 0:
|
||||
path = require('path');
|
||||
lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
pluginSourceId = String(args.inputs.pluginSourceId);
|
||||
parts = pluginSourceId.split(':');
|
||||
pluginSource = parts[0];
|
||||
pluginId = parts[1];
|
||||
relativePluginPath = "../../../../../".concat(pluginSource, "/").concat(pluginId, ".js");
|
||||
absolutePath = path.resolve(__dirname, relativePluginPath);
|
||||
if (!(pluginSource === 'Community')) return [3 /*break*/, 1];
|
||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||
return [3 /*break*/, 3];
|
||||
case 1: return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
plugin: {
|
||||
id: pluginId,
|
||||
source: pluginSource,
|
||||
},
|
||||
})];
|
||||
case 2:
|
||||
res_1 = _d.sent();
|
||||
classicPlugin = args.deps.requireFromString(res_1.pluginRaw, absolutePath);
|
||||
_d.label = 3;
|
||||
case 3:
|
||||
if (classicPlugin.details().Operation === 'Filter') {
|
||||
throw new Error("".concat('This plugin is meant for classic plugins that have '
|
||||
+ 'Operation: Transcode. This classic plugin has Operation: ').concat(classicPlugin.details().Operation)
|
||||
+ 'Please use the Run Classic Filter Flow Plugin plugin instead.');
|
||||
}
|
||||
container = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||
cacheFilePath = "".concat(args.workDir, "/tempFile_").concat(new Date().getTime(), ".").concat(container);
|
||||
otherArguments = {
|
||||
handbrakePath: args.handbrakePath,
|
||||
ffmpegPath: args.ffmpegPath,
|
||||
mkvpropeditPath: args.mkvpropeditPath,
|
||||
originalLibraryFile: args.originalLibraryFile,
|
||||
nodeHardwareType: args.nodeHardwareType,
|
||||
pluginCycle: 0,
|
||||
workerType: args.workerType,
|
||||
version: args.config.version,
|
||||
platform_arch_isdocker: args.platform_arch_isdocker,
|
||||
cacheFilePath: cacheFilePath,
|
||||
job: args.job,
|
||||
};
|
||||
return [4 /*yield*/, classicPlugin.plugin(args.inputFileObj, args.librarySettings, args.inputs, otherArguments)];
|
||||
case 4:
|
||||
result = _d.sent();
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
// --- Backwards compatibility------------
|
||||
if (result.handBrakeMode) {
|
||||
result.handbrakeMode = result.handBrakeMode;
|
||||
}
|
||||
if (result.FFmpegMode) {
|
||||
result.ffmpegMode = result.FFmpegMode;
|
||||
}
|
||||
//----------------------------------------
|
||||
if (result.ffmpegMode) {
|
||||
result.cliToUse = 'ffmpeg';
|
||||
}
|
||||
else if (result.handbrakeMode) {
|
||||
result.cliToUse = 'handbrake';
|
||||
}
|
||||
else if (typeof ((_a = result === null || result === void 0 ? void 0 : result.custom) === null || _a === void 0 ? void 0 : _a.cliPath) === 'string') {
|
||||
cliPath_1 = result.custom.cliPath;
|
||||
if (cliPath_1.toLowerCase().includes('ffmpeg')) {
|
||||
result.cliToUse = 'ffmpeg';
|
||||
}
|
||||
else if (cliPath_1.toLowerCase().includes('handbrake')) {
|
||||
result.cliToUse = 'handbrake';
|
||||
}
|
||||
else if (cliPath_1.toLowerCase().includes('editready')) {
|
||||
result.cliToUse = 'editready';
|
||||
}
|
||||
else if (cliPath_1.toLowerCase().includes('av1an')) {
|
||||
result.cliToUse = 'av1an';
|
||||
}
|
||||
}
|
||||
result.workerLog = result.transcodeSettingsLog;
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
if (result.error) {
|
||||
throw new Error("Plugin ".concat(absolutePath, " failed: ").concat(result.error));
|
||||
}
|
||||
if (result.processFile !== true) {
|
||||
return [2 /*return*/, {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
}];
|
||||
}
|
||||
customArgs = (_b = result === null || result === void 0 ? void 0 : result.custom) === null || _b === void 0 ? void 0 : _b.args;
|
||||
isCustomConfig = (Array.isArray(customArgs) && customArgs.length > 0)
|
||||
|| (typeof customArgs === 'string' && customArgs.length > 0);
|
||||
if (!isCustomConfig) {
|
||||
cacheFilePath = replaceContainer(cacheFilePath, result.container);
|
||||
}
|
||||
else {
|
||||
cacheFilePath = result.custom.outputPath;
|
||||
}
|
||||
if (result.preset.includes('<io>')) {
|
||||
presetSplit = result.preset.split('<io>');
|
||||
}
|
||||
else {
|
||||
presetSplit = result.preset.split(',');
|
||||
}
|
||||
workerCommand = [];
|
||||
cliPath = '';
|
||||
if (isCustomConfig) {
|
||||
cliPath = (_c = result === null || result === void 0 ? void 0 : result.custom) === null || _c === void 0 ? void 0 : _c.cliPath;
|
||||
if (Array.isArray(customArgs)) {
|
||||
workerCommand = customArgs;
|
||||
}
|
||||
else {
|
||||
workerCommand = __spreadArray([], args.deps.parseArgsStringToArgv(customArgs, '', ''), true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// working on windows with '` and spaces
|
||||
// working on unix with '
|
||||
switch (true) {
|
||||
case result.cliToUse === 'handbrake':
|
||||
workerCommand = __spreadArray([
|
||||
'-i',
|
||||
"".concat(args.inputFileObj._id),
|
||||
'-o',
|
||||
"".concat(cacheFilePath)
|
||||
], args.deps.parseArgsStringToArgv(result.preset, '', ''), true);
|
||||
cliPath = "".concat(args.handbrakePath);
|
||||
break;
|
||||
case result.cliToUse === 'ffmpeg':
|
||||
workerCommand = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], args.deps.parseArgsStringToArgv(presetSplit[0], '', ''), true), [
|
||||
'-i',
|
||||
"".concat(args.inputFileObj._id)
|
||||
], false), args.deps.parseArgsStringToArgv(presetSplit[1], '', ''), true), [
|
||||
"".concat(cacheFilePath),
|
||||
], false);
|
||||
cliPath = "".concat(args.ffmpegPath);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
cli = new cliUtils_1.CLI({
|
||||
cli: cliPath,
|
||||
spawnArgs: workerCommand,
|
||||
spawnOpts: {},
|
||||
jobLog: args.jobLog,
|
||||
outputFilePath: cacheFilePath,
|
||||
inputFileObj: args.inputFileObj,
|
||||
logFullCliOutput: args.logFullCliOutput,
|
||||
updateWorker: args.updateWorker,
|
||||
});
|
||||
return [4 /*yield*/, cli.runCli()];
|
||||
case 5:
|
||||
res = _d.sent();
|
||||
if (res.cliExitCode !== 0) {
|
||||
args.jobLog("Running ".concat(cliPath, " failed"));
|
||||
throw new Error("Running ".concat(cliPath, " failed"));
|
||||
}
|
||||
args.logOutcome('tSuc');
|
||||
return [2 /*return*/, {
|
||||
outputFileObj: {
|
||||
_id: cacheFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
}];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Set Video Resolution',
|
||||
description: 'Change video resolution',
|
||||
style: {
|
||||
borderColor: '#6efefc',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [
|
||||
{
|
||||
name: 'targetResolution',
|
||||
type: 'string',
|
||||
defaultValue: '1080p',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'480p',
|
||||
'720p',
|
||||
'1080p',
|
||||
'1440p',
|
||||
'4KUHD',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify the codec to use',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
var getVfScale = function (targetResolution) {
|
||||
switch (targetResolution) {
|
||||
case '480p':
|
||||
return ['-vf', 'scale=720:-2'];
|
||||
case '576p':
|
||||
return ['-vf', 'scale=720:-2'];
|
||||
case '720p':
|
||||
return ['-vf', 'scale=1280:-2'];
|
||||
case '1080p':
|
||||
return ['-vf', 'scale=1920:-2'];
|
||||
case '1440p':
|
||||
return ['-vf', 'scale=2560:-2'];
|
||||
case '4KUHD':
|
||||
return ['-vf', 'scale=3840:-2'];
|
||||
default:
|
||||
return ['-vf', 'scale=1920:-2'];
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) {
|
||||
var _a;
|
||||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
for (var i = 0; i < args.variables.ffmpegCommand.streams.length; i += 1) {
|
||||
var stream = args.variables.ffmpegCommand.streams[i];
|
||||
if (stream.codec_type === 'video') {
|
||||
var targetResolution = String(args.inputs.targetResolution);
|
||||
if (targetResolution !== args.inputFileObj.video_resolution) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
args.variables.ffmpegCommand.shouldProcess = true;
|
||||
var scaleArgs = getVfScale(targetResolution);
|
||||
(_a = stream.outputArgs).push.apply(_a, scaleArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,57 @@
|
||||
"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: 'Check File Extension',
|
||||
description: 'Check file extension',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'extensions',
|
||||
type: 'string',
|
||||
defaultValue: 'mkv,mp4',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'A comma separated list of extensions to check',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File is one of extensions',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File is not one of extensions',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) {
|
||||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
var extensions = String(args.inputs.extensions);
|
||||
var extensionArray = extensions.trim().split(',');
|
||||
var extension = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||
var extensionMatch = false;
|
||||
if (extensionArray.includes(extension)) {
|
||||
extensionMatch = true;
|
||||
}
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: extensionMatch ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,92 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Check File Size',
|
||||
description: 'Check size of working file',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'unit',
|
||||
type: 'string',
|
||||
defaultValue: 'GB',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'B',
|
||||
'KB',
|
||||
'MB',
|
||||
'GB',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify the unit to use',
|
||||
},
|
||||
{
|
||||
name: 'greaterThan',
|
||||
type: 'number',
|
||||
defaultValue: '0',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify lower bound',
|
||||
},
|
||||
{
|
||||
name: 'lessThan',
|
||||
type: 'number',
|
||||
defaultValue: '10000',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify upper bound',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File within range',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File not within range',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) {
|
||||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
var isWithinRange = false;
|
||||
var greaterThanBytes = Number(args.inputs.greaterThan);
|
||||
var lessThanBytes = Number(args.inputs.lessThan);
|
||||
var fileSizeBytes = args.inputFileObj.file_size * 1000 * 1000;
|
||||
if (args.inputs.unit === 'KB') {
|
||||
greaterThanBytes *= 1000;
|
||||
lessThanBytes *= 1000;
|
||||
}
|
||||
else if (args.inputs.unit === 'MB') {
|
||||
greaterThanBytes *= 1000000;
|
||||
lessThanBytes *= 1000000;
|
||||
}
|
||||
else if (args.inputs.unit === 'GB') {
|
||||
greaterThanBytes *= 1000000000;
|
||||
lessThanBytes *= 1000000000;
|
||||
}
|
||||
if (fileSizeBytes >= greaterThanBytes && fileSizeBytes <= lessThanBytes) {
|
||||
isWithinRange = true;
|
||||
}
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: isWithinRange ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Compare File Size',
|
||||
description: 'Compare file size of working file compared to original file',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Working file is smaller than original file',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'Working file is same size as original file',
|
||||
},
|
||||
{
|
||||
number: 3,
|
||||
tooltip: 'Working file is larger than original file',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) {
|
||||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
var outputNumber = 1;
|
||||
if (args.inputFileObj.file_size < args.originalLibraryFile.file_size) {
|
||||
outputNumber = 1;
|
||||
}
|
||||
else if (args.inputFileObj.file_size === args.originalLibraryFile.file_size) {
|
||||
outputNumber = 2;
|
||||
}
|
||||
else if (args.inputFileObj.file_size > args.originalLibraryFile.file_size) {
|
||||
outputNumber = 3;
|
||||
}
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: outputNumber,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Set Original File',
|
||||
description: 'Set the working file to the original file',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) {
|
||||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: args.originalLibraryFile._id,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,165 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
var fs_1 = require("fs");
|
||||
var cliUtils_1 = require("../../../../FlowHelpers/1.0.0/cliUtils");
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'HandBrake Custom Arguments',
|
||||
description: 'HandBrake Custom Arguments',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [
|
||||
{
|
||||
name: 'customArguments',
|
||||
type: 'string',
|
||||
defaultValue: '-Z "Fast 1080p30" --all-subtitles',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify HandBrake arguments',
|
||||
},
|
||||
{
|
||||
name: 'jsonPreset',
|
||||
type: 'string',
|
||||
defaultValue: '',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Paste a HandBrake JSON preset here. Leave blank to disable.',
|
||||
},
|
||||
{
|
||||
name: 'container',
|
||||
type: 'string',
|
||||
defaultValue: 'mkv',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'mkv',
|
||||
'mp4',
|
||||
'm4v',
|
||||
'avi',
|
||||
'mov',
|
||||
'mpg',
|
||||
'mpeg',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify HandBrake arguments',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var lib, customArguments, container, outputFilePath, presetString, cliArgs, presetPath, preset, cli, res;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
customArguments = String(args.inputs.customArguments);
|
||||
container = String(args.inputs.container);
|
||||
outputFilePath = "".concat(args.workDir, "/tempFile_").concat(new Date().getTime(), ".").concat(container);
|
||||
presetString = String(args.inputs.jsonPreset);
|
||||
cliArgs = [
|
||||
'-i',
|
||||
"".concat(args.inputFileObj._id),
|
||||
'-o',
|
||||
"".concat(outputFilePath),
|
||||
];
|
||||
presetPath = "".concat(args.workDir, "/preset.json");
|
||||
if (!(presetString.trim() !== '')) return [3 /*break*/, 2];
|
||||
preset = JSON.parse(presetString);
|
||||
return [4 /*yield*/, fs_1.promises.writeFile(presetPath, JSON.stringify(preset, null, 2))];
|
||||
case 1:
|
||||
_a.sent();
|
||||
cliArgs.push('--preset-import-file');
|
||||
cliArgs.push(presetPath);
|
||||
cliArgs.push('-Z');
|
||||
cliArgs.push(preset.PresetList[0].PresetName);
|
||||
return [3 /*break*/, 3];
|
||||
case 2:
|
||||
cliArgs.push.apply(cliArgs, args.deps.parseArgsStringToArgv(customArguments, '', ''));
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
args.updateWorker({
|
||||
CLIType: args.handbrakePath,
|
||||
preset: cliArgs.join(' '),
|
||||
});
|
||||
cli = new cliUtils_1.CLI({
|
||||
cli: args.handbrakePath,
|
||||
spawnArgs: cliArgs,
|
||||
spawnOpts: {},
|
||||
jobLog: args.jobLog,
|
||||
outputFilePath: outputFilePath,
|
||||
inputFileObj: args.inputFileObj,
|
||||
logFullCliOutput: args.logFullCliOutput,
|
||||
updateWorker: args.updateWorker,
|
||||
});
|
||||
return [4 /*yield*/, cli.runCli()];
|
||||
case 4:
|
||||
res = _a.sent();
|
||||
if (res.cliExitCode !== 0) {
|
||||
args.jobLog('Running HandBrake failed');
|
||||
throw new Error('Running HandBrake failed');
|
||||
}
|
||||
args.logOutcome('tSuc');
|
||||
return [2 /*return*/, {
|
||||
outputFileObj: {
|
||||
_id: outputFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
}];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Fail Flow',
|
||||
description: 'Force the flow to fail and be move to the error table',
|
||||
style: {
|
||||
borderColor: 'red',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faExclamationTriangle',
|
||||
inputs: [],
|
||||
outputs: [],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) {
|
||||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
throw new Error('Forcing flow to fail!');
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Go To Flow',
|
||||
description: 'Go to a different flow',
|
||||
style: {
|
||||
borderColor: 'red',
|
||||
opacity: 0.5,
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faArrowRight',
|
||||
inputs: [],
|
||||
outputs: [],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) {
|
||||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Check 10 Bit Video',
|
||||
description: 'Check if a file is 10 bit video',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File is 10 bit video',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File is not 10 bit video',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) {
|
||||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
var is10Bit = false;
|
||||
for (var i = 0; i < args.variables.ffmpegCommand.streams.length; i += 1) {
|
||||
var stream = args.variables.ffmpegCommand.streams[i];
|
||||
if (stream.codec_type === 'video' && stream.bits_per_raw_sample === 10) {
|
||||
is10Bit = true;
|
||||
}
|
||||
}
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: is10Bit ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Check Video Bitrate',
|
||||
description: 'Check if video bitrate is within a specific range',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'unit',
|
||||
type: 'string',
|
||||
defaultValue: 'kbps',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'bps',
|
||||
'kbps',
|
||||
'mbps',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify the unit to use',
|
||||
},
|
||||
{
|
||||
name: 'greaterThan',
|
||||
type: 'number',
|
||||
defaultValue: '0',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify lower bound',
|
||||
},
|
||||
{
|
||||
name: 'lessThan',
|
||||
type: 'number',
|
||||
defaultValue: '10000',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify upper bound',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File within range',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File not within range',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) {
|
||||
var _a, _b;
|
||||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
var isWithinRange = false;
|
||||
var greaterThanBits = Number(args.inputs.greaterThan);
|
||||
var lessThanBits = Number(args.inputs.lessThan);
|
||||
if (args.inputs.unit === 'kbps') {
|
||||
greaterThanBits *= 1000;
|
||||
lessThanBits *= 1000;
|
||||
}
|
||||
else if (args.inputs.unit === 'mbps') {
|
||||
greaterThanBits *= 1000000;
|
||||
lessThanBits *= 1000000;
|
||||
}
|
||||
if ((_b = (_a = args.inputFileObj) === null || _a === void 0 ? void 0 : _a.mediaInfo) === null || _b === void 0 ? void 0 : _b.track) {
|
||||
args.inputFileObj.mediaInfo.track.forEach(function (stream) {
|
||||
if (stream['@type'] === 'video') {
|
||||
if (stream.BitRate >= greaterThanBits && stream.BitRate <= lessThanBits) {
|
||||
isWithinRange = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: isWithinRange ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getFfType = exports.getFileName = exports.getContainer = void 0;
|
||||
var getContainer = function (filePath) {
|
||||
var parts = filePath.split('.');
|
||||
return parts[parts.length - 1];
|
||||
};
|
||||
exports.getContainer = getContainer;
|
||||
var getFileName = function (filePath) {
|
||||
var parts = filePath.split('/');
|
||||
var fileNameAndContainer = parts[parts.length - 1];
|
||||
var parts2 = fileNameAndContainer.split('.');
|
||||
return parts2[0];
|
||||
};
|
||||
exports.getFileName = getFileName;
|
||||
var getFfType = function (codecType) { return (codecType === 'video' ? 'v' : 'a'); };
|
||||
exports.getFfType = getFfType;
|
||||
@ -0,0 +1,325 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getEncoder = exports.getBestNvencDevice = exports.hasEncoder = void 0;
|
||||
var hasEncoder = function (_a) {
|
||||
var ffmpegPath = _a.ffmpegPath, encoder = _a.encoder, inputArgs = _a.inputArgs, filter = _a.filter;
|
||||
return __awaiter(void 0, void 0, void 0, function () {
|
||||
var exec, isEnabled, err_1;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
exec = require('child_process').exec;
|
||||
isEnabled = false;
|
||||
_b.label = 1;
|
||||
case 1:
|
||||
_b.trys.push([1, 3, , 4]);
|
||||
return [4 /*yield*/, new Promise(function (resolve) {
|
||||
var command = "".concat(ffmpegPath, " ").concat(inputArgs.join(' ') || '', " -f lavfi -i color=c=black:s=256x256:d=1:r=30")
|
||||
+ " ".concat(filter || '')
|
||||
+ " -c:v ".concat(encoder, " -f null /dev/null");
|
||||
exec(command, function (
|
||||
// eslint-disable-next-line
|
||||
error) {
|
||||
if (error) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
resolve(true);
|
||||
});
|
||||
})];
|
||||
case 2:
|
||||
isEnabled = _b.sent();
|
||||
return [3 /*break*/, 4];
|
||||
case 3:
|
||||
err_1 = _b.sent();
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(err_1);
|
||||
return [3 /*break*/, 4];
|
||||
case 4: return [2 /*return*/, isEnabled];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
exports.hasEncoder = hasEncoder;
|
||||
// credit to UNCode101 for this
|
||||
var getBestNvencDevice = function (_a) {
|
||||
var args = _a.args, nvencDevice = _a.nvencDevice;
|
||||
var execSync = require('child_process').execSync;
|
||||
var gpu_num = -1;
|
||||
var lowest_gpu_util = 100000;
|
||||
var result_util = 0;
|
||||
var gpu_count = -1;
|
||||
var gpu_names = '';
|
||||
var gpus_to_exclude = [];
|
||||
// inputs.exclude_gpus === '' ? [] : inputs.exclude_gpus.split(',').map(Number);
|
||||
try {
|
||||
gpu_names = execSync('nvidia-smi --query-gpu=name --format=csv,noheader');
|
||||
gpu_names = gpu_names.toString().trim();
|
||||
var gpu_namesArr = gpu_names.split(/\r?\n/);
|
||||
/* When nvidia-smi returns an error it contains 'nvidia-smi' in the error
|
||||
Example: Linux: nvidia-smi: command not found
|
||||
Windows: 'nvidia-smi' is not recognized as an internal or external command,
|
||||
operable program or batch file. */
|
||||
if (!gpu_namesArr[0].includes('nvidia-smi')) {
|
||||
gpu_count = gpu_namesArr.length;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
args.jobLog('Error in reading nvidia-smi output! \n');
|
||||
}
|
||||
if (gpu_count > 0) {
|
||||
for (var gpui = 0; gpui < gpu_count; gpui += 1) {
|
||||
// Check if GPU # is in GPUs to exclude
|
||||
if (gpus_to_exclude.includes(String(gpui))) {
|
||||
args.jobLog("GPU ".concat(gpui, ": ").concat(gpu_names[gpui], " is in exclusion list, will not be used!\n"));
|
||||
}
|
||||
else {
|
||||
try {
|
||||
var cmd_gpu = "nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ".concat(gpui);
|
||||
result_util = parseInt(execSync(cmd_gpu), 10);
|
||||
if (!Number.isNaN(result_util)) { // != "No devices were found") {
|
||||
args.jobLog("GPU ".concat(gpui, " : Utilization ").concat(result_util, "%\n"));
|
||||
if (result_util < lowest_gpu_util) {
|
||||
gpu_num = gpui;
|
||||
lowest_gpu_util = result_util;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
args.jobLog("Error in reading GPU ".concat(gpui, " Utilization\nError: ").concat(error, "\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gpu_num >= 0) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
nvencDevice.inputArgs.push('-hwaccel_device', "".concat(gpu_num));
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
nvencDevice.outputArgs.push('-gpu', "".concat(gpu_num));
|
||||
}
|
||||
return nvencDevice;
|
||||
};
|
||||
exports.getBestNvencDevice = getBestNvencDevice;
|
||||
var encoderFilter = function (encoder, targetCodec) {
|
||||
if (targetCodec === 'hevc' && (encoder.includes('hevc') || encoder.includes('h265'))) {
|
||||
return true;
|
||||
}
|
||||
if (targetCodec === 'h264' && encoder.includes('h264')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
var getEncoder = function (_a) {
|
||||
var targetCodec = _a.targetCodec, hardwareEncoding = _a.hardwareEncoding, args = _a.args;
|
||||
return __awaiter(void 0, void 0, void 0, function () {
|
||||
var gpuEncoders, filteredGpuEncoders, _i, filteredGpuEncoders_1, gpuEncoder, _b, enabledDevices, res;
|
||||
return __generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0:
|
||||
if (!(args.workerType
|
||||
&& args.workerType.includes('gpu')
|
||||
&& hardwareEncoding && (targetCodec === 'hevc' || targetCodec === 'h264'))) return [3 /*break*/, 5];
|
||||
gpuEncoders = [
|
||||
{
|
||||
encoder: 'hevc_nvenc',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'cuda',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'hevc_amf',
|
||||
enabled: false,
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'hevc_vaapi',
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'vaapi',
|
||||
'-hwaccel_device',
|
||||
'/dev/dri/renderD128',
|
||||
'-hwaccel_output_format',
|
||||
'vaapi',
|
||||
],
|
||||
outputArgs: [],
|
||||
enabled: false,
|
||||
filter: '-vf format=nv12,hwupload',
|
||||
},
|
||||
{
|
||||
encoder: 'hevc_qsv',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'qsv',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'hevc_videotoolbox',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'videotoolbox',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'h264_nvenc',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'cuda',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'h264_amf',
|
||||
enabled: false,
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'h264_qsv',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'qsv',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'h264_videotoolbox',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'videotoolbox',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
];
|
||||
filteredGpuEncoders = gpuEncoders.filter(function (device) { return encoderFilter(device.encoder, targetCodec); });
|
||||
_i = 0, filteredGpuEncoders_1 = filteredGpuEncoders;
|
||||
_c.label = 1;
|
||||
case 1:
|
||||
if (!(_i < filteredGpuEncoders_1.length)) return [3 /*break*/, 4];
|
||||
gpuEncoder = filteredGpuEncoders_1[_i];
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
_b = gpuEncoder;
|
||||
return [4 /*yield*/, (0, exports.hasEncoder)({
|
||||
ffmpegPath: args.ffmpegPath,
|
||||
encoder: gpuEncoder.encoder,
|
||||
inputArgs: gpuEncoder.inputArgs,
|
||||
filter: gpuEncoder.filter,
|
||||
})];
|
||||
case 2:
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
_b.enabled = _c.sent();
|
||||
_c.label = 3;
|
||||
case 3:
|
||||
_i++;
|
||||
return [3 /*break*/, 1];
|
||||
case 4:
|
||||
enabledDevices = gpuEncoders.filter(function (device) { return device.enabled === true; });
|
||||
if (enabledDevices.length > 0) {
|
||||
if (enabledDevices[0].encoder.includes('nvenc')) {
|
||||
res = (0, exports.getBestNvencDevice)({
|
||||
args: args,
|
||||
nvencDevice: enabledDevices[0],
|
||||
});
|
||||
return [2 /*return*/, __assign(__assign({}, res), { isGpu: true })];
|
||||
}
|
||||
return [2 /*return*/, {
|
||||
encoder: enabledDevices[0].encoder,
|
||||
inputArgs: enabledDevices[0].inputArgs,
|
||||
outputArgs: enabledDevices[0].outputArgs,
|
||||
isGpu: true,
|
||||
}];
|
||||
}
|
||||
_c.label = 5;
|
||||
case 5:
|
||||
if (targetCodec === 'hevc') {
|
||||
return [2 /*return*/, {
|
||||
encoder: 'libx265',
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
isGpu: false,
|
||||
}];
|
||||
}
|
||||
if (targetCodec === 'h264') {
|
||||
return [2 /*return*/, {
|
||||
encoder: 'libx264',
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
isGpu: false,
|
||||
}];
|
||||
}
|
||||
return [2 /*return*/, {
|
||||
encoder: targetCodec,
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
isGpu: false,
|
||||
}];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
exports.getEncoder = getEncoder;
|
||||
@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var hardwareUtils_1 = require("./hardwareUtils");
|
||||
var run = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var encoderProperties;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, (0, hardwareUtils_1.getEncoder)({
|
||||
targetCodec: 'h264',
|
||||
hardwareEncoding: true,
|
||||
// @ts-expect-error type
|
||||
args: {
|
||||
workerType: 'transcodegpu',
|
||||
ffmpegPath: 'ffmpeg',
|
||||
jobLog: function (t) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(t);
|
||||
},
|
||||
},
|
||||
})];
|
||||
case 1:
|
||||
encoderProperties = _a.sent();
|
||||
// eslint-disable-next-line no-console
|
||||
console.log({
|
||||
encoderProperties: encoderProperties,
|
||||
});
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
void run();
|
||||
@ -0,0 +1,115 @@
|
||||
import { getContainer } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Run Classic Filter Plugin',
|
||||
description: 'Run one of Tdarr\'s classic plugins that has Operation: Filter',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'pluginSourceId',
|
||||
type: 'string',
|
||||
defaultValue: 'Community:Tdarr_Plugin_00td_filter_by_codec',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [],
|
||||
},
|
||||
tooltip: 'Specify the classic plugin ID',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File met conditions, would traditionally continue to next plugin in plugin stack',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File did not meet conditions, would traditionally break out of plugin stack',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||
const path = require('path');
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const pluginSourceId = String(args.inputs.pluginSourceId);
|
||||
const parts = pluginSourceId.split(':');
|
||||
const pluginSource = parts[0];
|
||||
const pluginId = parts[1];
|
||||
|
||||
const relativePluginPath = `../../../../../${pluginSource}/${pluginId}.js`;
|
||||
const absolutePath = path.resolve(__dirname, relativePluginPath);
|
||||
|
||||
let classicPlugin;
|
||||
if (pluginSource === 'Community') {
|
||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||
} else {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
plugin: {
|
||||
id: pluginId,
|
||||
source: pluginSource,
|
||||
},
|
||||
});
|
||||
|
||||
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
|
||||
}
|
||||
|
||||
if (classicPlugin.details().Operation !== 'Filter') {
|
||||
throw new Error(
|
||||
`${'This plugin is meant for classic plugins that have '
|
||||
+ 'Operation: Filter. This classic plugin has Operation: '}${classicPlugin.details().Operation}`
|
||||
+ 'Please use the Run Classic Transcode Flow Plugin plugin instead.'
|
||||
,
|
||||
);
|
||||
}
|
||||
|
||||
const container = getContainer(args.inputFileObj._id);
|
||||
const cacheFilePath = `${args.workDir}/tempFile_${new Date().getTime()}.${container}`;
|
||||
|
||||
const otherArguments = {
|
||||
handbrakePath: args.handbrakePath,
|
||||
ffmpegPath: args.ffmpegPath,
|
||||
mkvpropeditPath: args.mkvpropeditPath,
|
||||
originalLibraryFile: args.originalLibraryFile,
|
||||
nodeHardwareType: args.nodeHardwareType,
|
||||
pluginCycle: 0,
|
||||
workerType: args.workerType,
|
||||
version: args.config.version,
|
||||
platform_arch_isdocker: args.platform_arch_isdocker,
|
||||
cacheFilePath,
|
||||
job: args.job,
|
||||
};
|
||||
|
||||
const result = await classicPlugin.plugin(args.inputFileObj, args.librarySettings, args.inputs, otherArguments);
|
||||
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
|
||||
const outputNumber = result.processFile ? 1 : 2;
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,237 @@
|
||||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import { getContainer } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Run Classic Transcode Plugin',
|
||||
description: 'Run one of Tdarr\'s classic plugins that has Operation: Transcode',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [
|
||||
{
|
||||
name: 'pluginSourceId',
|
||||
type: 'string',
|
||||
defaultValue: 'Community:Tdarr_Plugin_MC93_Migz1FFMPEG',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [],
|
||||
},
|
||||
tooltip: 'Specify the classic plugin ID',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const replaceContainer = (filePath:string, container:string): string => {
|
||||
const parts = filePath.split('.');
|
||||
parts[parts.length - 1] = container.split('.').join('');
|
||||
return parts.join('.');
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||
const path = require('path');
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const pluginSourceId = String(args.inputs.pluginSourceId);
|
||||
const parts = pluginSourceId.split(':');
|
||||
const pluginSource = parts[0];
|
||||
const pluginId = parts[1];
|
||||
|
||||
const relativePluginPath = `../../../../../${pluginSource}/${pluginId}.js`;
|
||||
const absolutePath = path.resolve(__dirname, relativePluginPath);
|
||||
|
||||
let classicPlugin;
|
||||
if (pluginSource === 'Community') {
|
||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||
} else {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
plugin: {
|
||||
id: pluginId,
|
||||
source: pluginSource,
|
||||
},
|
||||
});
|
||||
|
||||
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
|
||||
}
|
||||
|
||||
if (classicPlugin.details().Operation === 'Filter') {
|
||||
throw new Error(
|
||||
`${'This plugin is meant for classic plugins that have '
|
||||
+ 'Operation: Transcode. This classic plugin has Operation: '}${classicPlugin.details().Operation}`
|
||||
+ 'Please use the Run Classic Filter Flow Plugin plugin instead.'
|
||||
,
|
||||
);
|
||||
}
|
||||
|
||||
const container = getContainer(args.inputFileObj._id);
|
||||
let cacheFilePath = `${args.workDir}/tempFile_${new Date().getTime()}.${container}`;
|
||||
|
||||
const otherArguments = {
|
||||
handbrakePath: args.handbrakePath,
|
||||
ffmpegPath: args.ffmpegPath,
|
||||
mkvpropeditPath: args.mkvpropeditPath,
|
||||
originalLibraryFile: args.originalLibraryFile,
|
||||
nodeHardwareType: args.nodeHardwareType,
|
||||
pluginCycle: 0,
|
||||
workerType: args.workerType,
|
||||
version: args.config.version,
|
||||
platform_arch_isdocker: args.platform_arch_isdocker,
|
||||
cacheFilePath,
|
||||
job: args.job,
|
||||
};
|
||||
|
||||
const result = await classicPlugin.plugin(args.inputFileObj, args.librarySettings, args.inputs, otherArguments);
|
||||
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
|
||||
// --- Backwards compatibility------------
|
||||
if (result.handBrakeMode) {
|
||||
result.handbrakeMode = result.handBrakeMode;
|
||||
}
|
||||
|
||||
if (result.FFmpegMode) {
|
||||
result.ffmpegMode = result.FFmpegMode;
|
||||
}
|
||||
//----------------------------------------
|
||||
|
||||
if (result.ffmpegMode) {
|
||||
result.cliToUse = 'ffmpeg';
|
||||
} else if (result.handbrakeMode) {
|
||||
result.cliToUse = 'handbrake';
|
||||
} else if (typeof result?.custom?.cliPath === 'string') {
|
||||
const { cliPath } = result.custom;
|
||||
if (cliPath.toLowerCase().includes('ffmpeg')) {
|
||||
result.cliToUse = 'ffmpeg';
|
||||
} else if (cliPath.toLowerCase().includes('handbrake')) {
|
||||
result.cliToUse = 'handbrake';
|
||||
} else if (cliPath.toLowerCase().includes('editready')) {
|
||||
result.cliToUse = 'editready';
|
||||
} else if (cliPath.toLowerCase().includes('av1an')) {
|
||||
result.cliToUse = 'av1an';
|
||||
}
|
||||
}
|
||||
|
||||
result.workerLog = result.transcodeSettingsLog;
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
|
||||
if (result.error) {
|
||||
throw new Error(`Plugin ${absolutePath} failed: ${result.error}`);
|
||||
} if (result.processFile !== true) {
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
}
|
||||
|
||||
const customArgs = result?.custom?.args;
|
||||
const isCustomConfig = (Array.isArray(customArgs) && customArgs.length > 0)
|
||||
|| (typeof customArgs === 'string' && customArgs.length > 0);
|
||||
|
||||
if (!isCustomConfig) {
|
||||
cacheFilePath = replaceContainer(cacheFilePath, result.container);
|
||||
} else {
|
||||
cacheFilePath = result.custom.outputPath;
|
||||
}
|
||||
|
||||
let presetSplit;
|
||||
if (result.preset.includes('<io>')) {
|
||||
presetSplit = result.preset.split('<io>');
|
||||
} else {
|
||||
presetSplit = result.preset.split(',');
|
||||
}
|
||||
|
||||
let workerCommand: string[] = [];
|
||||
let cliPath = '';
|
||||
|
||||
if (isCustomConfig) {
|
||||
cliPath = result?.custom?.cliPath;
|
||||
|
||||
if (Array.isArray(customArgs)) {
|
||||
workerCommand = customArgs;
|
||||
} else {
|
||||
workerCommand = [
|
||||
...args.deps.parseArgsStringToArgv(customArgs, '', ''),
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// working on windows with '` and spaces
|
||||
// working on unix with '
|
||||
switch (true) {
|
||||
case result.cliToUse === 'handbrake':
|
||||
workerCommand = [
|
||||
'-i',
|
||||
`${args.inputFileObj._id}`,
|
||||
'-o',
|
||||
`${cacheFilePath}`,
|
||||
...args.deps.parseArgsStringToArgv(result.preset, '', ''),
|
||||
];
|
||||
|
||||
cliPath = `${args.handbrakePath}`;
|
||||
break;
|
||||
|
||||
case result.cliToUse === 'ffmpeg':
|
||||
workerCommand = [
|
||||
...args.deps.parseArgsStringToArgv(presetSplit[0], '', ''),
|
||||
'-i',
|
||||
`${args.inputFileObj._id}`,
|
||||
...args.deps.parseArgsStringToArgv(presetSplit[1], '', ''),
|
||||
`${cacheFilePath}`,
|
||||
];
|
||||
cliPath = `${args.ffmpegPath}`;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
const cli = new CLI({
|
||||
cli: cliPath,
|
||||
spawnArgs: workerCommand,
|
||||
spawnOpts: {},
|
||||
jobLog: args.jobLog,
|
||||
outputFilePath: cacheFilePath,
|
||||
inputFileObj: args.inputFileObj,
|
||||
logFullCliOutput: args.logFullCliOutput,
|
||||
updateWorker: args.updateWorker,
|
||||
});
|
||||
|
||||
const res = await cli.runCli();
|
||||
|
||||
if (res.cliExitCode !== 0) {
|
||||
args.jobLog(`Running ${cliPath} failed`);
|
||||
throw new Error(`Running ${cliPath} failed`);
|
||||
}
|
||||
|
||||
args.logOutcome('tSuc');
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: cacheFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,103 @@
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = () :IpluginDetails => ({
|
||||
name: 'Set Video Resolution',
|
||||
description: 'Change video resolution',
|
||||
style: {
|
||||
borderColor: '#6efefc',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [
|
||||
{
|
||||
name: 'targetResolution',
|
||||
type: 'string',
|
||||
defaultValue: '1080p',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'480p',
|
||||
'720p',
|
||||
'1080p',
|
||||
'1440p',
|
||||
'4KUHD',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify the codec to use',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const getVfScale = (
|
||||
targetResolution: string,
|
||||
):string[] => {
|
||||
switch (targetResolution) {
|
||||
case '480p':
|
||||
return ['-vf', 'scale=720:-2'];
|
||||
|
||||
case '576p':
|
||||
return ['-vf', 'scale=720:-2'];
|
||||
|
||||
case '720p':
|
||||
return ['-vf', 'scale=1280:-2'];
|
||||
|
||||
case '1080p':
|
||||
return ['-vf', 'scale=1920:-2'];
|
||||
|
||||
case '1440p':
|
||||
return ['-vf', 'scale=2560:-2'];
|
||||
|
||||
case '4KUHD':
|
||||
return ['-vf', 'scale=3840:-2'];
|
||||
|
||||
default:
|
||||
return ['-vf', 'scale=1920:-2'];
|
||||
}
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
for (let i = 0; i < args.variables.ffmpegCommand.streams.length; i += 1) {
|
||||
const stream = args.variables.ffmpegCommand.streams[i];
|
||||
|
||||
if (stream.codec_type === 'video') {
|
||||
const targetResolution = String(args.inputs.targetResolution);
|
||||
|
||||
if (
|
||||
targetResolution !== args.inputFileObj.video_resolution
|
||||
) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
args.variables.ffmpegCommand.shouldProcess = true;
|
||||
const scaleArgs = getVfScale(targetResolution);
|
||||
stream.outputArgs.push(...scaleArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,68 @@
|
||||
import { getContainer } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Check File Extension',
|
||||
description: 'Check file extension',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'extensions',
|
||||
type: 'string',
|
||||
defaultValue: 'mkv,mp4',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'A comma separated list of extensions to check',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File is one of extensions',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File is not one of extensions',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const extensions = String(args.inputs.extensions);
|
||||
const extensionArray = extensions.trim().split(',');
|
||||
|
||||
const extension = getContainer(args.inputFileObj._id);
|
||||
|
||||
let extensionMatch = false;
|
||||
|
||||
if (extensionArray.includes(extension)) {
|
||||
extensionMatch = true;
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: extensionMatch ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,100 @@
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Check File Size',
|
||||
description: 'Check size of working file',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'unit',
|
||||
type: 'string',
|
||||
defaultValue: 'GB',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'B',
|
||||
'KB',
|
||||
'MB',
|
||||
'GB',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify the unit to use',
|
||||
},
|
||||
{
|
||||
name: 'greaterThan',
|
||||
type: 'number',
|
||||
defaultValue: '0',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify lower bound',
|
||||
},
|
||||
{
|
||||
name: 'lessThan',
|
||||
type: 'number',
|
||||
defaultValue: '10000',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify upper bound',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File within range',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File not within range',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
let isWithinRange = false;
|
||||
let greaterThanBytes = Number(args.inputs.greaterThan);
|
||||
let lessThanBytes = Number(args.inputs.lessThan);
|
||||
const fileSizeBytes = args.inputFileObj.file_size * 1000 * 1000;
|
||||
|
||||
if (args.inputs.unit === 'KB') {
|
||||
greaterThanBytes *= 1000;
|
||||
lessThanBytes *= 1000;
|
||||
} else if (args.inputs.unit === 'MB') {
|
||||
greaterThanBytes *= 1000000;
|
||||
lessThanBytes *= 1000000;
|
||||
} else if (args.inputs.unit === 'GB') {
|
||||
greaterThanBytes *= 1000000000;
|
||||
lessThanBytes *= 1000000000;
|
||||
}
|
||||
|
||||
if (fileSizeBytes >= greaterThanBytes && fileSizeBytes <= lessThanBytes) {
|
||||
isWithinRange = true;
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: isWithinRange ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,62 @@
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Compare File Size',
|
||||
description: 'Compare file size of working file compared to original file',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: '',
|
||||
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Working file is smaller than original file',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'Working file is same size as original file',
|
||||
},
|
||||
|
||||
{
|
||||
number: 3,
|
||||
tooltip: 'Working file is larger than original file',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
let outputNumber = 1;
|
||||
|
||||
if (args.inputFileObj.file_size < args.originalLibraryFile.file_size) {
|
||||
outputNumber = 1;
|
||||
} else if (args.inputFileObj.file_size === args.originalLibraryFile.file_size) {
|
||||
outputNumber = 2;
|
||||
} else if (args.inputFileObj.file_size > args.originalLibraryFile.file_size) {
|
||||
outputNumber = 3;
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,44 @@
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = ():IpluginDetails => ({
|
||||
name: 'Set Original File',
|
||||
description: 'Set the working file to the original file',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: args.originalLibraryFile._id,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,135 @@
|
||||
import { promises as fs } from 'fs';
|
||||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = ():IpluginDetails => ({
|
||||
name: 'HandBrake Custom Arguments',
|
||||
description: 'HandBrake Custom Arguments',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [
|
||||
{
|
||||
name: 'customArguments',
|
||||
type: 'string',
|
||||
defaultValue: '-Z "Fast 1080p30" --all-subtitles',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify HandBrake arguments',
|
||||
},
|
||||
{
|
||||
name: 'jsonPreset',
|
||||
type: 'string',
|
||||
defaultValue: '',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Paste a HandBrake JSON preset here. Leave blank to disable.',
|
||||
},
|
||||
{
|
||||
name: 'container',
|
||||
type: 'string',
|
||||
defaultValue: 'mkv',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'mkv',
|
||||
'mp4',
|
||||
'm4v',
|
||||
'avi',
|
||||
'mov',
|
||||
'mpg',
|
||||
'mpeg',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify HandBrake arguments',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const customArguments = String(args.inputs.customArguments);
|
||||
const container = String(args.inputs.container);
|
||||
|
||||
const outputFilePath = `${args.workDir}/tempFile_${new Date().getTime()}.${container}`;
|
||||
|
||||
const presetString = String(args.inputs.jsonPreset);
|
||||
|
||||
const cliArgs = [
|
||||
'-i',
|
||||
`${args.inputFileObj._id}`,
|
||||
'-o',
|
||||
`${outputFilePath}`,
|
||||
];
|
||||
|
||||
const presetPath = `${args.workDir}/preset.json`;
|
||||
|
||||
if (presetString.trim() !== '') {
|
||||
const preset = JSON.parse(presetString);
|
||||
await fs.writeFile(presetPath, JSON.stringify(preset, null, 2));
|
||||
cliArgs.push('--preset-import-file');
|
||||
cliArgs.push(presetPath);
|
||||
cliArgs.push('-Z');
|
||||
cliArgs.push(preset.PresetList[0].PresetName);
|
||||
} else {
|
||||
cliArgs.push(...args.deps.parseArgsStringToArgv(customArguments, '', ''));
|
||||
}
|
||||
|
||||
args.updateWorker({
|
||||
CLIType: args.handbrakePath,
|
||||
preset: cliArgs.join(' '),
|
||||
});
|
||||
|
||||
const cli = new CLI({
|
||||
cli: args.handbrakePath,
|
||||
spawnArgs: cliArgs,
|
||||
spawnOpts: {},
|
||||
jobLog: args.jobLog,
|
||||
outputFilePath,
|
||||
inputFileObj: args.inputFileObj,
|
||||
logFullCliOutput: args.logFullCliOutput,
|
||||
updateWorker: args.updateWorker,
|
||||
});
|
||||
|
||||
const res = await cli.runCli();
|
||||
|
||||
if (res.cliExitCode !== 0) {
|
||||
args.jobLog('Running HandBrake failed');
|
||||
throw new Error('Running HandBrake failed');
|
||||
}
|
||||
|
||||
args.logOutcome('tSuc');
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: outputFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,39 @@
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = ():IpluginDetails => ({
|
||||
name: 'Fail Flow',
|
||||
description: 'Force the flow to fail and be move to the error table',
|
||||
style: {
|
||||
borderColor: 'red',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faExclamationTriangle',
|
||||
inputs: [],
|
||||
outputs: [],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
throw new Error('Forcing flow to fail!');
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,38 @@
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = ():IpluginDetails => ({
|
||||
name: 'Go To Flow',
|
||||
description: 'Go to a different flow',
|
||||
style: {
|
||||
borderColor: 'red',
|
||||
opacity: 0.5,
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faArrowRight',
|
||||
inputs: [],
|
||||
outputs: [],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,67 @@
|
||||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = ():IpluginDetails => ({
|
||||
name: 'Run MKVPropEdit',
|
||||
description: 'Run MKVPropEdit on a file to update metadata which'
|
||||
+ ' FFmpeg doesn\'t typically update such as stream bitrate.',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const cliArgs = [
|
||||
'--add-track-statistics-tags',
|
||||
args.inputFileObj._id,
|
||||
];
|
||||
|
||||
const cli = new CLI({
|
||||
cli: args.mkvpropeditPath,
|
||||
spawnArgs: cliArgs,
|
||||
spawnOpts: {},
|
||||
jobLog: args.jobLog,
|
||||
outputFilePath: '',
|
||||
inputFileObj: args.inputFileObj,
|
||||
logFullCliOutput: args.logFullCliOutput,
|
||||
updateWorker: args.updateWorker,
|
||||
});
|
||||
|
||||
const res = await cli.runCli();
|
||||
|
||||
if (res.cliExitCode !== 0) {
|
||||
args.jobLog('Running MKVPropEdit failed');
|
||||
throw new Error('Running MKVPropEdit failed');
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -1,94 +0,0 @@
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = ():IpluginDetails => ({
|
||||
name: 'Unpack File',
|
||||
description: 'Unpack a file',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
opacity: 0.5,
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faArrowRight',
|
||||
inputs: [
|
||||
{
|
||||
name: 'target_codec',
|
||||
type: 'string',
|
||||
defaultValue: 'hevc',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'hevc',
|
||||
// 'vp9',
|
||||
'h264',
|
||||
// 'vp8',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify the codec to use',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const getNewPath = (originalPath:string, tempPath:string) => {
|
||||
const tempPathParts = tempPath.split('.');
|
||||
const container = tempPathParts[tempPathParts.length - 1];
|
||||
|
||||
const originalPathParts = originalPath.split('.');
|
||||
|
||||
originalPathParts[originalPathParts.length - 1] = container;
|
||||
|
||||
return originalPathParts.join('.');
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
||||
const fs = require('fs');
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const currentPath = args.inputFileObj._id;
|
||||
const newPath = getNewPath(args.originalLibraryFile._id, currentPath);
|
||||
const newPathTmp = `${newPath}.tmp`;
|
||||
|
||||
args.jobLog(JSON.stringify({
|
||||
currentPath,
|
||||
newPath,
|
||||
newPathTmp,
|
||||
}));
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
|
||||
fs.renameSync(currentPath, newPathTmp);
|
||||
|
||||
if (fs.existsSync(newPath)) {
|
||||
fs.unlinkSync(newPath);
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
fs.renameSync(newPathTmp, newPath);
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: newPath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,55 @@
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Check 10 Bit Video',
|
||||
description: 'Check if a file is 10 bit video',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File is 10 bit video',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File is not 10 bit video',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
let is10Bit = false;
|
||||
|
||||
for (let i = 0; i < args.variables.ffmpegCommand.streams.length; i += 1) {
|
||||
const stream = args.variables.ffmpegCommand.streams[i];
|
||||
if (stream.codec_type === 'video' && stream.bits_per_raw_sample === 10) {
|
||||
is10Bit = true;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: is10Bit ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,102 @@
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Check Video Bitrate',
|
||||
description: 'Check if video bitrate is within a specific range',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'unit',
|
||||
type: 'string',
|
||||
defaultValue: 'kbps',
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'bps',
|
||||
'kbps',
|
||||
'mbps',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify the unit to use',
|
||||
},
|
||||
{
|
||||
name: 'greaterThan',
|
||||
type: 'number',
|
||||
defaultValue: '0',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify lower bound',
|
||||
},
|
||||
{
|
||||
name: 'lessThan',
|
||||
type: 'number',
|
||||
defaultValue: '10000',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify upper bound',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File within range',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File not within range',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
let isWithinRange = false;
|
||||
|
||||
let greaterThanBits = Number(args.inputs.greaterThan);
|
||||
let lessThanBits = Number(args.inputs.lessThan);
|
||||
|
||||
if (args.inputs.unit === 'kbps') {
|
||||
greaterThanBits *= 1000;
|
||||
lessThanBits *= 1000;
|
||||
} else if (args.inputs.unit === 'mbps') {
|
||||
greaterThanBits *= 1000000;
|
||||
lessThanBits *= 1000000;
|
||||
}
|
||||
|
||||
if (args.inputFileObj?.mediaInfo?.track) {
|
||||
args.inputFileObj.mediaInfo.track.forEach((stream) => {
|
||||
if (stream['@type'] === 'video') {
|
||||
if (stream.BitRate >= greaterThanBits && stream.BitRate <= lessThanBits) {
|
||||
isWithinRange = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: isWithinRange ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
@ -0,0 +1,13 @@
|
||||
export const getContainer = (filePath: string):string => {
|
||||
const parts = filePath.split('.');
|
||||
return parts[parts.length - 1];
|
||||
};
|
||||
|
||||
export const getFileName = (filePath: string):string => {
|
||||
const parts = filePath.split('/');
|
||||
const fileNameAndContainer = parts[parts.length - 1];
|
||||
const parts2 = fileNameAndContainer.split('.');
|
||||
return parts2[0];
|
||||
};
|
||||
|
||||
export const getFfType = (codecType:string):string => (codecType === 'video' ? 'v' : 'a');
|
||||
@ -0,0 +1,24 @@
|
||||
import { getEncoder } from './hardwareUtils';
|
||||
|
||||
const run = async () => {
|
||||
const encoderProperties = await getEncoder({
|
||||
targetCodec: 'h264',
|
||||
hardwareEncoding: true,
|
||||
// @ts-expect-error type
|
||||
args: {
|
||||
workerType: 'transcodegpu',
|
||||
ffmpegPath: 'ffmpeg',
|
||||
jobLog: (t:string) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(t);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log({
|
||||
encoderProperties,
|
||||
});
|
||||
};
|
||||
|
||||
void run();
|
||||
@ -0,0 +1,293 @@
|
||||
import { IpluginInputArgs } from './interfaces/interfaces';
|
||||
|
||||
export const hasEncoder = async ({
|
||||
ffmpegPath,
|
||||
encoder,
|
||||
inputArgs,
|
||||
filter,
|
||||
}: {
|
||||
ffmpegPath: string,
|
||||
encoder: string,
|
||||
inputArgs: string[],
|
||||
filter: string,
|
||||
}): Promise<boolean> => {
|
||||
const { exec } = require('child_process');
|
||||
let isEnabled = false;
|
||||
try {
|
||||
isEnabled = await new Promise((resolve) => {
|
||||
const command = `${ffmpegPath} ${inputArgs.join(' ') || ''} -f lavfi -i color=c=black:s=256x256:d=1:r=30`
|
||||
+ ` ${filter || ''}`
|
||||
+ ` -c:v ${encoder} -f null /dev/null`;
|
||||
exec(command, (
|
||||
// eslint-disable-next-line
|
||||
error: any,
|
||||
// stdout,
|
||||
// stderr,
|
||||
) => {
|
||||
if (error) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
return isEnabled;
|
||||
};
|
||||
|
||||
interface IgpuEncoder {
|
||||
encoder: string,
|
||||
enabled: boolean,
|
||||
|
||||
inputArgs: string[],
|
||||
outputArgs: string[],
|
||||
filter: string,
|
||||
}
|
||||
|
||||
// credit to UNCode101 for this
|
||||
export const getBestNvencDevice = ({
|
||||
args,
|
||||
nvencDevice,
|
||||
}: {
|
||||
args: IpluginInputArgs
|
||||
nvencDevice: IgpuEncoder,
|
||||
}): IgpuEncoder => {
|
||||
const { execSync } = require('child_process');
|
||||
let gpu_num = -1;
|
||||
let lowest_gpu_util = 100000;
|
||||
let result_util = 0;
|
||||
let gpu_count = -1;
|
||||
let gpu_names = '';
|
||||
const gpus_to_exclude: string[] = [];
|
||||
// inputs.exclude_gpus === '' ? [] : inputs.exclude_gpus.split(',').map(Number);
|
||||
try {
|
||||
gpu_names = execSync('nvidia-smi --query-gpu=name --format=csv,noheader');
|
||||
gpu_names = gpu_names.toString().trim();
|
||||
const gpu_namesArr = gpu_names.split(/\r?\n/);
|
||||
/* When nvidia-smi returns an error it contains 'nvidia-smi' in the error
|
||||
Example: Linux: nvidia-smi: command not found
|
||||
Windows: 'nvidia-smi' is not recognized as an internal or external command,
|
||||
operable program or batch file. */
|
||||
if (!gpu_namesArr[0].includes('nvidia-smi')) {
|
||||
gpu_count = gpu_namesArr.length;
|
||||
}
|
||||
} catch (error) {
|
||||
args.jobLog('Error in reading nvidia-smi output! \n');
|
||||
}
|
||||
|
||||
if (gpu_count > 0) {
|
||||
for (let gpui = 0; gpui < gpu_count; gpui += 1) {
|
||||
// Check if GPU # is in GPUs to exclude
|
||||
if (gpus_to_exclude.includes(String(gpui))) {
|
||||
args.jobLog(`GPU ${gpui}: ${gpu_names[gpui]} is in exclusion list, will not be used!\n`);
|
||||
} else {
|
||||
try {
|
||||
const cmd_gpu = `nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${gpui}`;
|
||||
result_util = parseInt(execSync(cmd_gpu), 10);
|
||||
if (!Number.isNaN(result_util)) { // != "No devices were found") {
|
||||
args.jobLog(`GPU ${gpui} : Utilization ${result_util}%\n`);
|
||||
|
||||
if (result_util < lowest_gpu_util) {
|
||||
gpu_num = gpui;
|
||||
lowest_gpu_util = result_util;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
args.jobLog(`Error in reading GPU ${gpui} Utilization\nError: ${error}\n`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gpu_num >= 0) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
nvencDevice.inputArgs.push('-hwaccel_device', `${gpu_num}`);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
nvencDevice.outputArgs.push('-gpu', `${gpu_num}`);
|
||||
}
|
||||
|
||||
return nvencDevice;
|
||||
};
|
||||
|
||||
const encoderFilter = (encoder:string, targetCodec:string) => {
|
||||
if (targetCodec === 'hevc' && (encoder.includes('hevc') || encoder.includes('h265'))) {
|
||||
return true;
|
||||
} if (targetCodec === 'h264' && encoder.includes('h264')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
export const getEncoder = async ({
|
||||
targetCodec,
|
||||
hardwareEncoding,
|
||||
args,
|
||||
}: {
|
||||
targetCodec: string,
|
||||
hardwareEncoding: boolean,
|
||||
args: IpluginInputArgs,
|
||||
}): Promise<{
|
||||
encoder: string,
|
||||
inputArgs: string[],
|
||||
outputArgs: string[],
|
||||
isGpu: boolean,
|
||||
}> => {
|
||||
if (
|
||||
args.workerType
|
||||
&& args.workerType.includes('gpu')
|
||||
&& hardwareEncoding && (targetCodec === 'hevc' || targetCodec === 'h264')) {
|
||||
const gpuEncoders: IgpuEncoder[] = [
|
||||
{
|
||||
encoder: 'hevc_nvenc',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'cuda',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'hevc_amf',
|
||||
enabled: false,
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'hevc_vaapi',
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'vaapi',
|
||||
'-hwaccel_device',
|
||||
'/dev/dri/renderD128',
|
||||
'-hwaccel_output_format',
|
||||
'vaapi',
|
||||
],
|
||||
outputArgs: [],
|
||||
enabled: false,
|
||||
filter: '-vf format=nv12,hwupload',
|
||||
},
|
||||
{
|
||||
encoder: 'hevc_qsv',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'qsv',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'hevc_videotoolbox',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'videotoolbox',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
|
||||
{
|
||||
encoder: 'h264_nvenc',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'cuda',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'h264_amf',
|
||||
enabled: false,
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'h264_qsv',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'qsv',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
{
|
||||
encoder: 'h264_videotoolbox',
|
||||
enabled: false,
|
||||
inputArgs: [
|
||||
'-hwaccel',
|
||||
'videotoolbox',
|
||||
],
|
||||
outputArgs: [],
|
||||
filter: '',
|
||||
},
|
||||
];
|
||||
|
||||
const filteredGpuEncoders = gpuEncoders.filter((device) => encoderFilter(device.encoder, targetCodec));
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const gpuEncoder of filteredGpuEncoders) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
gpuEncoder.enabled = await hasEncoder({
|
||||
ffmpegPath: args.ffmpegPath,
|
||||
encoder: gpuEncoder.encoder,
|
||||
inputArgs: gpuEncoder.inputArgs,
|
||||
filter: gpuEncoder.filter,
|
||||
});
|
||||
}
|
||||
|
||||
const enabledDevices = gpuEncoders.filter((device) => device.enabled === true);
|
||||
|
||||
if (enabledDevices.length > 0) {
|
||||
if (enabledDevices[0].encoder.includes('nvenc')) {
|
||||
const res = getBestNvencDevice({
|
||||
args,
|
||||
nvencDevice: enabledDevices[0],
|
||||
});
|
||||
|
||||
return {
|
||||
...res,
|
||||
isGpu: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
encoder: enabledDevices[0].encoder,
|
||||
inputArgs: enabledDevices[0].inputArgs,
|
||||
outputArgs: enabledDevices[0].outputArgs,
|
||||
isGpu: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (targetCodec === 'hevc') {
|
||||
return {
|
||||
encoder: 'libx265',
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
isGpu: false,
|
||||
};
|
||||
} if (targetCodec === 'h264') {
|
||||
return {
|
||||
encoder: 'libx264',
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
isGpu: false,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
encoder: targetCodec,
|
||||
inputArgs: [],
|
||||
outputArgs: [],
|
||||
isGpu: false,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in new issue