diff --git a/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js b/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js index 3d2d2c6..450595e 100644 --- a/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js +++ b/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js @@ -326,7 +326,7 @@ let bitrateSettings = ''; let inflatedCutoff = 0; let main10 = false; let high10 = false; -let oldFormat = false; +let swDecode = false; let videoBR = 0; // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -609,14 +609,13 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { } } - // On testing I've found files in the High10 profile don't play nice with hw decoding so mark these + // Files in the High10 profile are not supported for HW Decode if (file.ffProbeData.streams[i].profile === 'High 10') { high10 = true; - response.infoLog += 'Input file is 10bit using High10. Disabling hardware decoding to avoid problems. \n'; - } - // If files are 10 bit or the enable_10bit setting is used mark to enable Main10. - if (file.ffProbeData.streams[i].profile === 'Main 10' || file.ffProbeData.streams[i].bits_per_raw_sample === '10' - || inputs.enable_10bit === true) { + main10 = true; + // If files are 10 bit or the enable_10bit setting is used mark to enable Main10. + } else if (file.ffProbeData.streams[i].profile === 'Main 10' + || file.ffProbeData.streams[i].bits_per_raw_sample === '10' || inputs.enable_10bit === true) { main10 = true; } @@ -637,26 +636,32 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { default: } - // Some video codecs won't play nice with 10 bit via QSV, whitelist safe ones here + // Some video codecs don't support HW decode so mark these + // VC1 & VP8 are no longer supported on new HW, add cases here if your HW does support switch (file.video_codec_name) { case 'mpeg2': break; case 'h264': + if (high10 === true) { + response.infoLog += `Input file is ${file.video_codec_name} High10. Hardware Decode not supported. \n`; + swDecode = true; + } break; case 'mjpeg': break; case 'hevc': break; - case 'vp9': + case 'vp9':// Should be supported by 8th Gen + break; - case 'av1': + case 'av1':// Should be supported by 11th gen + break; default: - oldFormat = true; + swDecode = true; + response.infoLog += `Input file is ${file.video_codec_name}. Hardware Decode not supported. \n`; } // Are we encoding to 10 bit? If so enable correct profile & pixel format. - if (high10 === true || (oldFormat === true && main10 === true)) { + if (swDecode === true && main10 === true) { // This is used if we have High10 or Main10 is enabled & odd format files. // SW decode and use standard -pix_fmt p010le extraArguments += '-profile:v main10 -pix_fmt p010le '; @@ -686,10 +691,10 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { // -fflags +genpts should regenerate timestamps if they end up missing... response.preset = '-fflags +genpts '; - // HW ACCEL FLAGS - I think these are good practice but are they necessary? + // HW ACCEL FLAGS // Account for different OS - if (high10 === false) { - // Seems incoming High10 files don't play nice decoding so use software decode + if (swDecode !== true) { + // Only enable hw decode for accepted formats switch (os.platform()) { case 'darwin': // Mac OS - Enable videotoolbox instead of QSV response.preset += '-hwaccel videotoolbox'; @@ -705,38 +710,51 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { default: response.preset += '-hwaccel qsv -hwaccel_output_format qsv -init_hw_device qsv:hw_any '; } + } else { + switch (os.platform()) { + case 'linux': // Linux - Full device, should fix child_device_type warnings + response.preset += `-hwaccel_output_format qsv + -init_hw_device qsv:hw_any,child_device_type=vaapi `; + break; + case 'win32': // Windows - Full device, should fix child_device_type warnings + response.preset += `-hwaccel_output_format qsv + -init_hw_device qsv:hw,child_device_type=d3d11va `; + break; + default: + // Default to enabling hwaccel for output only + response.preset += '-hwaccel_output_format qsv -init_hw_device qsv:hw_any '; + } } // DECODE FLAGS + // VC1 & VP8 are no longer supported on new HW, add cases here if your HW does support if (os.platform() !== 'darwin') { - if (high10 === false) { // Don't enable for High10 - switch (file.video_codec_name) { - case 'mpeg2': - response.preset += '-c:v mpeg2_qsv'; - break; - case 'h264': + switch (file.video_codec_name) { + case 'mpeg2': + response.preset += '-c:v mpeg2_qsv'; + break; + case 'h264': + if (high10 !== true) { // Don't enable for High10 response.preset += '-c:v h264_qsv'; - break; - case 'vc1': // VC1 no longer supported on latest intel HW - // response.preset += '-c:v vc1_qsv'; - break; - case 'mjpeg': - response.preset += '-c:v mjpeg_qsv'; - break; - case 'vp8': // VP8 no longer supported on latest intel HW - // response.preset += '-c:v vp8_qsv'; - break; - case 'hevc': - response.preset += '-c:v hevc_qsv'; - break; - case 'vp9': // Should be supported by 8th Gen + - response.preset += '-c:v vp9_qsv'; - break; - case 'av1': // Should be supported by 11th gen + - response.preset += '-c:v av1_qsv'; - break; - default: - } + } else { + response.preset += `-c:v ${file.video_codec_name}`; + } + break; + case 'mjpeg': + response.preset += '-c:v mjpeg_qsv'; + break; + case 'hevc': + response.preset += '-c:v hevc_qsv'; + break; + case 'vp9': // Should be supported by 8th Gen + + response.preset += '-c:v vp9_qsv'; + break; + case 'av1': // Should be supported by 11th gen + + response.preset += '-c:v av1_qsv'; + break; + default: + // Use incoming format for software decode + response.preset += `-c:v ${file.video_codec_name}`; } } @@ -760,8 +778,10 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { response.preset += 'hevc_qsv'; // Default to QSV } - // Check if -vf cmd has already been used on user input - if (high10 !== true) { + // Only add on for HW decoded formats + // VC1 & VP8 are no longer supported on new HW, add cases here if your HW does support + if (swDecode !== true) { + // Check if -vf cmd has already been used on user input if (inputs.extra_qsv_options.search('-vf scale_qsv') >= 0) { switch (file.video_codec_name) { case 'mpeg2': diff --git a/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js b/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js index 6350ce1..afcc6ac 100644 --- a/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js +++ b/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js @@ -149,12 +149,13 @@ const tests = [ output: { linux: { processFile: true, - preset: '-fflags +genpts -map 0 -c:v hevc_qsv -b:v 3227k -minrate 2420k -maxrate 4034k -bufsize 6454k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10 -pix_fmt p010le ', + preset: '-fflags +genpts -hwaccel_output_format qsv \n' + + ' -init_hw_device qsv:hw,child_device_type=vaapi -c:v h264 -map 0 -c:v hevc_qsv -b:v 3227k -minrate 2420k -maxrate 4034k -bufsize 6454k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10 -pix_fmt p010le ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, infoLog: '☑ It looks like the current video bitrate is 6454kbps. \n' - + 'Input file is 10bit using High10. Disabling hardware decoding to avoid problems. \n' + + 'Input file is h264 High10. Hardware Decode not supported. \n' + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n' + 'Container for output selected as mkv. \n' + 'Encode variable bitrate settings: \n' @@ -166,12 +167,13 @@ const tests = [ }, win32: { processFile: true, - preset: '-fflags +genpts -map 0 -c:v hevc_qsv -b:v 3227k -minrate 2420k -maxrate 4034k -bufsize 6454k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10 -pix_fmt p010le ', + preset: '-fflags +genpts -hwaccel_output_format qsv \n' + + ' -init_hw_device qsv:hw,child_device_type=d3d11va -c:v h264 -map 0 -c:v hevc_qsv -b:v 3227k -minrate 2420k -maxrate 4034k -bufsize 6454k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10 -pix_fmt p010le ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, infoLog: '☑ It looks like the current video bitrate is 6454kbps. \n' - + 'Input file is 10bit using High10. Disabling hardware decoding to avoid problems. \n' + + 'Input file is h264 High10. Hardware Decode not supported. \n' + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n' + 'Container for output selected as mkv. \n' + 'Encode variable bitrate settings: \n' @@ -183,7 +185,7 @@ const tests = [ }, darwin: { processFile: true, - preset: '-fflags +genpts -map 0 -c:v hevc_videotoolbox -b:v 3227k -minrate 2420k -maxrate 4034k -bufsize 6454k -preset fast -c:a copy -c:s copy -f matroska -profile:v main10 -pix_fmt p010le ', + preset: '-fflags +genpts -c:v h264 -map 0 -c:v hevc_videotoolbox -b:v 3227k -minrate 2420k -maxrate 4034k -bufsize 6454k -preset fast -c:a copy -c:s copy -f matroska -profile:v main10 -pix_fmt p010le ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, @@ -518,5 +520,77 @@ const tests = [ }, }, }, + // Test 8 + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_1.json')); + file.ffProbeData.streams[0].bits_per_raw_sample = '10'; + file.video_codec_name = 'vc1'; + return file; + })(), + librarySettings: {}, + inputs: { + container: 'mkv', + encoder_speedpreset: 'fast', + }, + otherArguments: {}, + }, + output: { + linux: { + processFile: true, + preset: '-fflags +genpts -hwaccel_output_format qsv \n' + + ' -init_hw_device qsv:hw_any,child_device_type=vaapi -c:v vc1 -map 0 -c:v hevc_qsv -b:v 603k -minrate 452k -maxrate 754k -bufsize 1206k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10 -pix_fmt p010le ', + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☑ It looks like the current video bitrate is 1206kbps. \n' + + 'Input file is vc1. Hardware Decode not supported. \n' + + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n' + + 'Container for output selected as mkv. \n' + + 'Encode variable bitrate settings: \n' + + 'Target = 603k \n' + + 'Minimum = 452k \n' + + 'Maximum = 754k \n' + + 'File Transcoding... \n', + container: '.mkv', + }, + win32: { + processFile: true, + preset: '-fflags +genpts -hwaccel_output_format qsv \n' + + ' -init_hw_device qsv:hw,child_device_type=d3d11va -c:v vc1 -map 0 -c:v hevc_qsv -b:v 603k -minrate 452k -maxrate 754k -bufsize 1206k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10 -pix_fmt p010le ', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☑ It looks like the current video bitrate is 1206kbps. \n' + + 'Input file is vc1. Hardware Decode not supported. \n' + + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n' + + 'Container for output selected as mkv. \n' + + 'Encode variable bitrate settings: \n' + + 'Target = 603k \n' + + 'Minimum = 452k \n' + + 'Maximum = 754k \n' + + 'File Transcoding... \n', + container: '.mkv', + }, + darwin: { + processFile: true, + preset: '-fflags +genpts -c:v vc1 -map 0 -c:v hevc_videotoolbox -b:v 603k -minrate 452k -maxrate 754k -bufsize 1206k -preset slow -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska ', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☑ It looks like the current video bitrate is 1206kbps. \n' + + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n' + + 'Container for output selected as mkv. \n' + + 'Encode variable bitrate settings: \n' + + 'Target = 603k \n' + + 'Minimum = 452k \n' + + 'Maximum = 754k \n' + + '==ALERT== OS detected as MAC - This will use VIDEOTOOLBOX to encode which is NOT QSV\n' + + 'cmds set in extra_qsv_options will be IGNORED!\n' + + 'File Transcoding... \n', + container: '.mkv', + }, + }, + }, ]; void run(tests);