mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-15 10:15:54 -07:00
Merge pull request #485 from HaveAGitGat/2.13.01
Add hardwareType option
This commit is contained in:
commit
5f99bcf547
8 changed files with 81 additions and 16 deletions
|
|
@ -111,6 +111,22 @@ var details = function () { return ({
|
||||||
},
|
},
|
||||||
tooltip: 'Specify whether to use hardware encoding if available',
|
tooltip: 'Specify whether to use hardware encoding if available',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'hardwareType',
|
||||||
|
type: 'string',
|
||||||
|
defaultValue: 'auto',
|
||||||
|
inputUI: {
|
||||||
|
type: 'dropdown',
|
||||||
|
options: [
|
||||||
|
'auto',
|
||||||
|
'nvenc',
|
||||||
|
'qsv',
|
||||||
|
'vaapi',
|
||||||
|
'videotoolbox',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip: 'Specify codec of the output file',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'hardwareDecoding',
|
name: 'hardwareDecoding',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
|
@ -148,7 +164,7 @@ var details = function () { return ({
|
||||||
exports.details = details;
|
exports.details = details;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
var lib, hardwareDecoding, i, stream, targetCodec, ffmpegPreset, ffmpegQuality, forceEncoding, hardwarEncoding, encoderProperties;
|
var lib, hardwareDecoding, hardwareType, i, stream, targetCodec, ffmpegPreset, ffmpegQuality, forceEncoding, hardwarEncoding, encoderProperties;
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __generator(this, function (_c) {
|
return __generator(this, function (_c) {
|
||||||
switch (_c.label) {
|
switch (_c.label) {
|
||||||
|
|
@ -157,6 +173,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
hardwareDecoding = args.inputs.hardwareDecoding === true;
|
hardwareDecoding = args.inputs.hardwareDecoding === true;
|
||||||
|
hardwareType = String(args.inputs.hardwareType);
|
||||||
args.variables.ffmpegCommand.hardwareDecoding = hardwareDecoding;
|
args.variables.ffmpegCommand.hardwareDecoding = hardwareDecoding;
|
||||||
i = 0;
|
i = 0;
|
||||||
_c.label = 1;
|
_c.label = 1;
|
||||||
|
|
@ -175,6 +192,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
return [4 /*yield*/, (0, hardwareUtils_1.getEncoder)({
|
return [4 /*yield*/, (0, hardwareUtils_1.getEncoder)({
|
||||||
targetCodec: targetCodec,
|
targetCodec: targetCodec,
|
||||||
hardwareEncoding: hardwarEncoding,
|
hardwareEncoding: hardwarEncoding,
|
||||||
|
hardwareType: hardwareType,
|
||||||
args: args,
|
args: args,
|
||||||
})];
|
})];
|
||||||
case 2:
|
case 2:
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
return [4 /*yield*/, (0, hardwareUtils_1.getEncoder)({
|
return [4 /*yield*/, (0, hardwareUtils_1.getEncoder)({
|
||||||
targetCodec: 'hevc',
|
targetCodec: 'hevc',
|
||||||
hardwareEncoding: true,
|
hardwareEncoding: true,
|
||||||
|
hardwareType: 'auto',
|
||||||
args: args,
|
args: args,
|
||||||
})];
|
})];
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
||||||
|
|
@ -160,9 +160,9 @@ var encoderFilter = function (encoder, targetCodec) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
var getEncoder = function (_a) {
|
var getEncoder = function (_a) {
|
||||||
var targetCodec = _a.targetCodec, hardwareEncoding = _a.hardwareEncoding, args = _a.args;
|
var targetCodec = _a.targetCodec, hardwareEncoding = _a.hardwareEncoding, hardwareType = _a.hardwareType, args = _a.args;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
return __awaiter(void 0, void 0, void 0, function () {
|
||||||
var gpuEncoders, filteredGpuEncoders, _i, filteredGpuEncoders_1, gpuEncoder, _b, enabledDevices, res;
|
var gpuEncoders, filteredGpuEncoders, idx, _i, filteredGpuEncoders_1, gpuEncoder, _b, enabledDevices, res;
|
||||||
return __generator(this, function (_c) {
|
return __generator(this, function (_c) {
|
||||||
switch (_c.label) {
|
switch (_c.label) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -290,6 +290,13 @@ var getEncoder = function (_a) {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
filteredGpuEncoders = gpuEncoders.filter(function (device) { return encoderFilter(device.encoder, targetCodec); });
|
filteredGpuEncoders = gpuEncoders.filter(function (device) { return encoderFilter(device.encoder, targetCodec); });
|
||||||
|
if (hardwareEncoding && hardwareType !== 'auto') {
|
||||||
|
idx = filteredGpuEncoders.findIndex(function (device) { return device.encoder.includes(hardwareType); });
|
||||||
|
if (idx === -1) {
|
||||||
|
throw new Error("Could not find encoder ".concat(targetCodec, " for hardware ").concat(hardwareType));
|
||||||
|
}
|
||||||
|
return [2 /*return*/, __assign(__assign({}, filteredGpuEncoders[idx]), { isGpu: true, enabledDevices: [] })];
|
||||||
|
}
|
||||||
args.jobLog(JSON.stringify({ filteredGpuEncoders: filteredGpuEncoders }));
|
args.jobLog(JSON.stringify({ filteredGpuEncoders: filteredGpuEncoders }));
|
||||||
_i = 0, filteredGpuEncoders_1 = filteredGpuEncoders;
|
_i = 0, filteredGpuEncoders_1 = filteredGpuEncoders;
|
||||||
_c.label = 1;
|
_c.label = 1;
|
||||||
|
|
@ -312,7 +319,7 @@ var getEncoder = function (_a) {
|
||||||
_i++;
|
_i++;
|
||||||
return [3 /*break*/, 1];
|
return [3 /*break*/, 1];
|
||||||
case 4:
|
case 4:
|
||||||
enabledDevices = gpuEncoders.filter(function (device) { return device.enabled === true; });
|
enabledDevices = filteredGpuEncoders.filter(function (device) { return device.enabled === true; });
|
||||||
args.jobLog(JSON.stringify({ enabledDevices: enabledDevices }));
|
args.jobLog(JSON.stringify({ enabledDevices: enabledDevices }));
|
||||||
if (enabledDevices.length > 0) {
|
if (enabledDevices.length > 0) {
|
||||||
if (enabledDevices[0].encoder.includes('nvenc')) {
|
if (enabledDevices[0].encoder.includes('nvenc')) {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ var run = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
case 0: return [4 /*yield*/, (0, hardwareUtils_1.getEncoder)({
|
case 0: return [4 /*yield*/, (0, hardwareUtils_1.getEncoder)({
|
||||||
targetCodec: 'h264',
|
targetCodec: 'h264',
|
||||||
hardwareEncoding: true,
|
hardwareEncoding: true,
|
||||||
|
hardwareType: 'auto',
|
||||||
// @ts-expect-error type
|
// @ts-expect-error type
|
||||||
args: {
|
args: {
|
||||||
workerType: 'transcodegpu',
|
workerType: 'transcodegpu',
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,22 @@ const details = (): IpluginDetails => ({
|
||||||
},
|
},
|
||||||
tooltip: 'Specify whether to use hardware encoding if available',
|
tooltip: 'Specify whether to use hardware encoding if available',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'hardwareType',
|
||||||
|
type: 'string',
|
||||||
|
defaultValue: 'auto',
|
||||||
|
inputUI: {
|
||||||
|
type: 'dropdown',
|
||||||
|
options: [
|
||||||
|
'auto',
|
||||||
|
'nvenc',
|
||||||
|
'qsv',
|
||||||
|
'vaapi',
|
||||||
|
'videotoolbox',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip: 'Specify codec of the output file',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'hardwareDecoding',
|
name: 'hardwareDecoding',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
|
@ -121,6 +137,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
|
||||||
const hardwareDecoding = args.inputs.hardwareDecoding === true;
|
const hardwareDecoding = args.inputs.hardwareDecoding === true;
|
||||||
|
const hardwareType = String(args.inputs.hardwareType);
|
||||||
args.variables.ffmpegCommand.hardwareDecoding = hardwareDecoding;
|
args.variables.ffmpegCommand.hardwareDecoding = hardwareDecoding;
|
||||||
|
|
||||||
for (let i = 0; i < args.variables.ffmpegCommand.streams.length; i += 1) {
|
for (let i = 0; i < args.variables.ffmpegCommand.streams.length; i += 1) {
|
||||||
|
|
@ -143,6 +160,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
const encoderProperties = await getEncoder({
|
const encoderProperties = await getEncoder({
|
||||||
targetCodec,
|
targetCodec,
|
||||||
hardwareEncoding: hardwarEncoding,
|
hardwareEncoding: hardwarEncoding,
|
||||||
|
hardwareType,
|
||||||
args,
|
args,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
const encoderProperties = await getEncoder({
|
const encoderProperties = await getEncoder({
|
||||||
targetCodec: 'hevc',
|
targetCodec: 'hevc',
|
||||||
hardwareEncoding: true,
|
hardwareEncoding: true,
|
||||||
|
hardwareType: 'auto',
|
||||||
args,
|
args,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ const run = async () => {
|
||||||
const encoderProperties = await getEncoder({
|
const encoderProperties = await getEncoder({
|
||||||
targetCodec: 'h264',
|
targetCodec: 'h264',
|
||||||
hardwareEncoding: true,
|
hardwareEncoding: true,
|
||||||
|
hardwareType: 'auto',
|
||||||
// @ts-expect-error type
|
// @ts-expect-error type
|
||||||
args: {
|
args: {
|
||||||
workerType: 'transcodegpu',
|
workerType: 'transcodegpu',
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ export const getBestNvencDevice = ({
|
||||||
return nvencDevice;
|
return nvencDevice;
|
||||||
};
|
};
|
||||||
|
|
||||||
const encoderFilter = (encoder:string, targetCodec:string) => {
|
const encoderFilter = (encoder: string, targetCodec: string) => {
|
||||||
if (targetCodec === 'hevc' && (encoder.includes('hevc') || encoder.includes('h265'))) {
|
if (targetCodec === 'hevc' && (encoder.includes('hevc') || encoder.includes('h265'))) {
|
||||||
return true;
|
return true;
|
||||||
} if (targetCodec === 'h264' && encoder.includes('h264')) {
|
} if (targetCodec === 'h264' && encoder.includes('h264')) {
|
||||||
|
|
@ -124,21 +124,25 @@ const encoderFilter = (encoder:string, targetCodec:string) => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getEncoder = async ({
|
export interface IgetEncoder {
|
||||||
targetCodec,
|
|
||||||
hardwareEncoding,
|
|
||||||
args,
|
|
||||||
}: {
|
|
||||||
targetCodec: string,
|
|
||||||
hardwareEncoding: boolean,
|
|
||||||
args: IpluginInputArgs,
|
|
||||||
}): Promise<{
|
|
||||||
encoder: string,
|
encoder: string,
|
||||||
inputArgs: string[],
|
inputArgs: string[],
|
||||||
outputArgs: string[],
|
outputArgs: string[],
|
||||||
isGpu: boolean,
|
isGpu: boolean,
|
||||||
enabledDevices: IgpuEncoder[],
|
enabledDevices: IgpuEncoder[],
|
||||||
}> => {
|
}
|
||||||
|
|
||||||
|
export const getEncoder = async ({
|
||||||
|
targetCodec,
|
||||||
|
hardwareEncoding,
|
||||||
|
hardwareType,
|
||||||
|
args,
|
||||||
|
}: {
|
||||||
|
targetCodec: string,
|
||||||
|
hardwareEncoding: boolean,
|
||||||
|
hardwareType: string,
|
||||||
|
args: IpluginInputArgs,
|
||||||
|
}): Promise<IgetEncoder> => {
|
||||||
if (
|
if (
|
||||||
args.workerType
|
args.workerType
|
||||||
&& args.workerType.includes('gpu')
|
&& args.workerType.includes('gpu')
|
||||||
|
|
@ -268,6 +272,20 @@ export const getEncoder = async ({
|
||||||
|
|
||||||
const filteredGpuEncoders = gpuEncoders.filter((device) => encoderFilter(device.encoder, targetCodec));
|
const filteredGpuEncoders = gpuEncoders.filter((device) => encoderFilter(device.encoder, targetCodec));
|
||||||
|
|
||||||
|
if (hardwareEncoding && hardwareType !== 'auto') {
|
||||||
|
const idx = filteredGpuEncoders.findIndex((device) => device.encoder.includes(hardwareType));
|
||||||
|
|
||||||
|
if (idx === -1) {
|
||||||
|
throw new Error(`Could not find encoder ${targetCodec} for hardware ${hardwareType}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...filteredGpuEncoders[idx],
|
||||||
|
isGpu: true,
|
||||||
|
enabledDevices: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
args.jobLog(JSON.stringify({ filteredGpuEncoders }));
|
args.jobLog(JSON.stringify({ filteredGpuEncoders }));
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
|
|
@ -281,7 +299,7 @@ export const getEncoder = async ({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const enabledDevices = gpuEncoders.filter((device) => device.enabled === true);
|
const enabledDevices = filteredGpuEncoders.filter((device) => device.enabled === true);
|
||||||
|
|
||||||
args.jobLog(JSON.stringify({ enabledDevices }));
|
args.jobLog(JSON.stringify({ enabledDevices }));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue