Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands with commas #718

Open
ManuXD32 opened this issue Nov 24, 2024 · 0 comments
Open

Commands with commas #718

ManuXD32 opened this issue Nov 24, 2024 · 0 comments

Comments

@ManuXD32
Copy link

Hi, I am trying to build a plugin for tdarr to work with AMD GPU, but I encountered a problem, the final command needs to use -vf "format=nv12,hwupload" argument, but it seems like only format=nv12 goes through.

This is the code
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = () => ({
id: 'Tdarr_Plugin_MC93_Migz1FFMPEG',
Stage: 'Pre-processing',
Name: 'MANU AMD Migz Transcode Using AMD GPU & FFMPEG',
Type: 'Video',
Operation: 'Transcode',
Description: Files not in H265 will be transcoded into H265 using AMD GPU with ffmpeg via VAAPI. Settings are dependant on file bitrate Working by the logic that H265 can support the same amount of data at half the bitrate of H264. This plugin will skip any files that are in the VP9 codec.,
Version: '3.1',
Tags: 'pre-processing,ffmpeg,video only,amd vaapi h265,configurable',
Inputs: [{
name: 'container',
type: 'string',
defaultValue: 'mkv',
inputUI: {
type: 'text',
},
tooltip: Specify output container of file. Use 'original' without quotes to keep original container. \\n Ensure that all stream types you may have are supported by your chosen container. \\n mkv is recommended.,
},
{
name: 'bitrate_cutoff',
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
},
tooltip: Specify bitrate cutoff, files with a current bitrate lower than this will not be transcoded. \\n Rate is in kbps. \\n Leave empty to disable.,
},
{
name: 'enable_10bit',
type: 'boolean',
defaultValue: false,
inputUI: {
type: 'dropdown',
options: [
'false',
'true',
],
},
tooltip: Specify if output file should be 10bit. Default is false.,
},
{
name: 'enable_bframes',
type: 'boolean',
defaultValue: false,
inputUI: {
type: 'dropdown',
options: [
'false',
'true',
],
},
tooltip: Specify if b frames should be used. \\n Using B frames should decrease file sizes but are only supported on newer GPUs. \\n Default is false.,
},
{
name: 'force_conform',
type: 'boolean',
defaultValue: false,
inputUI: {
type: 'dropdown',
options: [
'false',
'true',
],
},
tooltip: Make the file conform to output containers' requirements.,
},
],
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const plugin = (file, librarySettings, inputs, otherArguments) => {
const lib = require('../methods/lib')();
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
inputs = lib.loadDefaultValues(inputs, details);
const response = {
processFile: false,
preset: '',
handBrakeMode: false,
FFmpegMode: true,
reQueueAfter: true,
infoLog: '',
};

let duration = '';

if (inputs.container === '') {
response.infoLog += 'Plugin has not been configured, skipping this plugin. \n';
response.processFile = false;
return response;
}

if (inputs.container === 'original') {
inputs.container = ${file.container};
response.container = .${file.container};
} else {
response.container = .${inputs.container};
}

if (file.fileMedium !== 'video') {
response.processFile = false;
response.infoLog += 'File is not a video. \n';
return response;
}

// Calculate video duration
if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration) * 0.0166667;
} else if (typeof file.meta.Duration !== 'undefined') {
duration = file.meta.Duration * 0.0166667;
} else {
duration = file.ffProbeData.streams[0].duration * 0.0166667;
}

let videoIdx = 0;
let CPU10 = false;
let extraArguments = '';
let genpts = '';
let bitrateSettings = '';
const currentBitrate = ~~(file.file_size / (duration * 0.0075));
const targetBitrate = ~~(file.file_size / (duration * 0.0075) / 2);
const minimumBitrate = ~~(targetBitrate * 0.7);
const maximumBitrate = ~~(targetBitrate * 1.3);

if (inputs.container.toLowerCase() === 'ts' || inputs.container.toLowerCase() === 'avi') {
genpts = '-fflags +genpts';
}

if (targetBitrate === 0) {
response.processFile = false;
response.infoLog += 'Target bitrate could not be calculated. Skipping this plugin. \n';
return response;
}

if (inputs.bitrate_cutoff !== '') {
if (currentBitrate <= inputs.bitrate_cutoff) {
response.processFile = false;
response.infoLog += Current bitrate is below set cutoff of ${inputs.bitrate_cutoff}. Cancelling plugin. \n;
return response;
}
}

if (inputs.force_conform === true) {
if (inputs.container.toLowerCase() === 'mkv') {
extraArguments += '-map -0:d ';
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
try {
if (
file.ffProbeData.streams[i].codec_name
.toLowerCase() === 'mov_text'
|| file.ffProbeData.streams[i].codec_name
.toLowerCase() === 'eia_608'
|| file.ffProbeData.streams[i].codec_name
.toLowerCase() === 'timed_id3'
) {
extraArguments += -map -0:${i} ;
}
} catch (err) {}
}
}
if (inputs.container.toLowerCase() === 'mp4') {
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
try {
if (
file.ffProbeData.streams[i].codec_name
.toLowerCase() === 'hdmv_pgs_subtitle'
|| file.ffProbeData.streams[i].codec_name
.toLowerCase() === 'eia_608'
|| file.ffProbeData.streams[i].codec_name
.toLowerCase() === 'subrip'
|| file.ffProbeData.streams[i].codec_name
.toLowerCase() === 'timed_id3'
) {
extraArguments += -map -0:${i} ;
}
} catch (err) {}
}
}
}

if (inputs.enable_10bit === true) {
extraArguments += '-pix_fmt p010le ';
}

if (inputs.enable_bframes === true) {
extraArguments += '-bf 5 ';
}

for (let i = 0; i < file.ffProbeData.streams.length; i++) {
let codec_type = '';
try {
codec_type = file.ffProbeData.streams[i].codec_type.toLowerCase();
} catch (err) {}
if (codec_type === 'video') {
if (file.ffProbeData.streams[i].codec_name === 'mjpeg' || file.ffProbeData.streams[i].codec_name === 'png') {
extraArguments += -map -v:${videoIdx} ;
}
if (
(file.ffProbeData.streams[i].codec_name === 'hevc' || file.ffProbeData.streams[i].codec_name === 'vp9')
&& file.container === inputs.container
) {
response.processFile = false;
response.infoLog += File is already hevc or vp9 & in ${inputs.container}. \n;
return response;
}

  if (
    (file.ffProbeData.streams[i].codec_name === 'hevc' || file.ffProbeData.streams[i].codec_name === 'vp9')
            && file.container !== inputs.container
  ) {
    response.infoLog += `File is hevc or vp9 but is not in ${inputs.container} container. Remuxing. \n`;
    response.preset = `, -map 0 -c:v copy -c:a copy -c:s copy ${extraArguments} ${genpts}`;
    response.processFile = true;
    return response;
  }

  if (
    file.ffProbeData.streams[i].codec_name !== 'hevc' && file.ffProbeData.streams[i].codec_name !== 'vp9'
  ) {
    response.preset = `, -map 0 -c:v hevc_vaapi -vaapi_device /dev/dri/renderD128 -b:v ${targetBitrate}k -maxrate ${maximumBitrate}k -minrate ${minimumBitrate}k -vf "hwupload" -c:a copy -c:s copy ${extraArguments} ${genpts}`;
    response.processFile = true;
    return response;
  }
}

}

return response;
};
module.exports.details = details;
module.exports.plugin = plugin;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant