From 3ac61410a04ce00070e4dfdd634c04e065af27cb Mon Sep 17 00:00:00 2001 From: Boosh1 <45874141+Boosh1@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:19:43 +0100 Subject: [PATCH 1/2] Update Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js New fix for HW decode. H264 High10 is the problem. Enable SW decode for that and normal HW decode on the rest. --- ...Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js b/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js index affed14f3..c21d1ee11 100644 --- a/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js +++ b/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js @@ -329,6 +329,7 @@ let extraArguments = ''; let bitrateSettings = ''; let inflatedCutoff = 0; let main10 = false; +let high10 = false; let videoBR = 0; // Finds the first video stream and get video bitrate @@ -602,14 +603,6 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { } } - // Are we encoding to 10 bit? If so enable correct profile & pixel format. - // With this set we also disable hardware decode for compatibility later - if (inputs.enable_10bit === true) { - main10 = true; - extraArguments += '-profile:v main10 -vf scale_qsv=format=p010le '; - response.infoLog += '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n'; - } - // Go through each stream in the file. for (let i = 0; i < file.ffProbeData.streams.length; i += 1) { // Check if stream is a video. @@ -700,13 +693,15 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { } } - // If files are already 10bit then disable hardware decode to avoid problems with encode - // 10 bit from source file should be retained without extra arguments. - if (file.ffProbeData.streams[i].profile === 'High 10' - || file.ffProbeData.streams[i].profile === 'Main 10' - || file.ffProbeData.streams[i].bits_per_raw_sample === '10') { + // On testing I've found files in the High10 profile don't play nice with hw decoding so mark these + 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; - response.infoLog += 'Input file is 10bit. Disabling hardware decoding to avoid problems. \n'; } // Increment video index. Needed to keep track of video id in case there is more than one video track. @@ -715,6 +710,15 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { } } + // Are we encoding to 10 bit? If so enable correct profile & pixel format. + if (high10 === true) { // This is used if we have High10 files. SW decode and use standard -pix_fmt p010le + extraArguments += '-profile:v main10 -pix_fmt p010le '; + response.infoLog += '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n'; + } else if (main10 === true) { // Pixel formate method when using HW decode + extraArguments += '-profile:v main10 -vf scale_qsv=format=p010le '; + response.infoLog += '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n'; + } + // Set bitrateSettings variable using bitrate information calculated earlier. bitrateSettings = `-b:v ${targetBitrate}k -minrate ${minimumBitrate}k ` + `-maxrate ${maximumBitrate}k -bufsize ${currentBitrate}k`; @@ -729,10 +733,10 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { // -fflags +genpts should regenerate timestamps if they end up missing... response.preset = '-fflags +genpts '; - // HW ACCEL FLAGS + // HW ACCEL FLAGS - I think these are good practice but are they necessary? // Account for different OS - if (main10 === false) { - // On testing it seems the below will automatically enable hardware decoding which causes issues... + if (high10 === false) { + // Seems incoming High10 files don't play nice decoding so use software decode switch (os.platform()) { case 'darwin': // Mac OS - Enable videotoolbox instead of QSV response.preset += '-hwaccel videotoolbox'; @@ -752,7 +756,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { // DECODE FLAGS if (os.platform() !== 'darwin') { - if (main10 === false) { // Don't enable if 10bit is on - Seems to cause issues, may need different decode flags + if (high10 === false) { // Don't enable for High10 switch (file.video_codec_name) { case 'mpeg2': response.preset += '-c:v mpeg2_qsv'; From 3dac2ff50a06f0137df902f932059a97cf45951c Mon Sep 17 00:00:00 2001 From: Boosh1 <45874141+Boosh1@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:39:07 +0100 Subject: [PATCH 2/2] 1st pass fixes for tests --- .../Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 4ce99d26e..14c773435 100644 --- a/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js +++ b/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js @@ -79,7 +79,8 @@ const tests = [ output: { linux: { processFile: true, - preset: '-fflags +genpts -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 -profile:v main10 -vf scale_qsv=format=p010le ', + preset: '-fflags +genpts -hwaccel qsv -hwaccel_output_format qsv \n' + + ' -init_hw_device qsv:hw_any,child_device_type=vaapi -c:v h264_qsv -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 -profile:v main10 -vf scale_qsv=format=p010le ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, @@ -96,7 +97,8 @@ const tests = [ }, win32: { processFile: true, - preset: '-fflags +genpts -map 0 -c:v hevc_qsv -load_plugin hevc_hw -b:v 603k -minrate 452k -maxrate 754k -bufsize 1206k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -profile:v main10 -vf scale_qsv=format=p010le ', + preset: '-fflags +genpts -hwaccel qsv -hwaccel_output_format qsv \n' + + ' -init_hw_device qsv:hw_any,child_device_type=d3d11va -c:v h264_qsv -map 0 -c:v hevc_qsv -load_plugin hevc_hw -b:v 603k -minrate 452k -maxrate 754k -bufsize 1206k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -profile:v main10 -vf scale_qsv=format=p010le ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, @@ -113,7 +115,7 @@ const tests = [ }, darwin: { processFile: true, - preset: '-fflags +genpts -map 0 -c:v hevc_videotoolbox -b:v 603k -minrate 452k -maxrate 754k -bufsize 1206k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -profile:v main10 -vf scale_qsv=format=p010le ', + preset: '-fflags +genpts -hwaccel videotoolbox -map 0 -c:v hevc_videotoolbox -b:v 603k -minrate 452k -maxrate 754k -bufsize 1206k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -profile:v main10 -vf scale_qsv=format=p010le ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true,