Tdarr_Plugins_Custom/Tdarr_Plugin_0000_FFMPEG_NVENC_HEVC_Custom.js
2024-03-02 18:37:08 +13:00

100 lines
3.9 KiB
JavaScript

const details = () => ({
id: 'Tdarr_Plugin_0000_FFMPEG_NVENC_HEVC_Custom',
Stage: 'Pre-processing',
Name: 'FFMPEG NVENC HEVC Custom',
Type: 'Video',
Operation: 'Transcode',
Description:
'[Contains built-in filter] This plugin transcodes non HEVC files into HEVC mkv using ffmpeg and hevc_nvenc. Basic customization options have been provided. Generic HDR Passthrough is also included by default (may not work on all HDR videos). Audio/subtitles not affected. \n\n',
Version: '1.2',
Tags: 'pre-processing,ffmpeg,hevc,video only',
Inputs: [
{
name: 'cq',
type: 'string',
defaultValue: '22',
inputUI: {
type: 'dropdown',
options: ['0', '4', '8', '12', '14', '16', '18', '20', '22', '24', '26', '28', '30', '34', '38', '42', '50'],
},
tooltip: 'Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control (from 0 to 51)',
},
{
name: 'preset',
type: 'string',
defaultValue: 'p7',
inputUI: {
type: 'dropdown',
options: ['p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'hq', 'fast', 'medium', 'slow', 'lossless'],
},
tooltip: 'hevc_nvenc has nineteen predefined --preset options that optimize the trade-off between encoding speed (encoded frames per second) and compression efficiency (quality per bit in the bitstream). When you use faster presets, the encoder takes shortcuts to improve performance at the expense of quality and compression efficiency. When you use slower presets, nvenc_hevc tests more encoding options, using more computations to achieve the best quality at your selected bit rate. "p1" through "p7" are the standard fastest to slowest presets ("p7" being the slowest); "hq" is High Quality, and "slow" to "lossless" are self explanitory',
},
{
name: 'tune',
type: 'string',
defaultValue: 'hq',
inputUI: {
type: 'dropdown',
options: ['hq', 'll', 'ull', 'lossless'],
},
tooltip: '"hq" High quality. "ll" Low latency. "ull" Ultra low latency. "lossless" Lossless.',
},
{
name: 'profile',
type: 'string',
defaultValue: 'main10',
inputUI: {
type: 'dropdown',
options: ['main', 'main10', 'main12'],
},
tooltip: '"main" = 8bit; "main10" = 10bit; "main12" = 12bit encoding. Choose 10bit or higher to retain HDR content.',
},
],
});
const plugin = async (file, librarySettings, inputs, otherArguments) => {
const lib = require('../methods/lib')();
inputs = lib.loadDefaultValues(inputs, details);
const { cq, preset, tune, profile } = inputs;
const response = {
processFile: false,
preset: '',
container: '.mkv',
handBrakeMode: false,
FFmpegMode: false,
reQueueAfter: false,
infoLog: '',
};
if (file.fileMedium !== 'video') {
response.processFile = false;
response.infoLog += '☒File is not a video! \n';
return response;
}
response.infoLog += '☑File is a video! \n';
if (file.ffProbeData.streams[0].codec_name === 'av1') {
response.processFile = false;
response.infoLog += '☑File is already in AV1! \n';
return response;
}
response.processFile = true;
response.preset = `,-map 0:v -map 0:a -c:v:0 hevc_nvenc -preset ${preset} -tune ${tune} -profile:v ${profile} -cq:v ${cq} -rc:v vbr -rc-lookahead:v 8 -bf 3 \
-metadata:s:v:0 "chroma_location=topleft:color_primaries=bt2020:transfer_characteristics=smpte2084:color_trc=bt2020:colorspace=bt2020nc" \
-metadata:s:v:0 "master_display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(40000000,50)" \
-metadata:s:v:0 "max_cll=1600,300"`;
response.container = '.mkv';
response.handBrakeMode = false;
response.FFmpegMode = true;
response.reQueueAfter = true;
response.infoLog += '☒File is not AV1! \n';
return response;
};
module.exports.details = details;
module.exports.plugin = plugin;