From a5dc4934eee0cb92a8bdc2e5fd7f5c36dad79bcf Mon Sep 17 00:00:00 2001 From: Boosh1 <45874141+Boosh1@users.noreply.github.com> Date: Mon, 15 Jan 2024 21:28:41 +0000 Subject: [PATCH] Corrected -vf cmd so it's added on the end better --- ...Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js | 85 ++++++++++++++++--- ...Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js | 81 ++++++++++++++++-- 2 files changed, 146 insertions(+), 20 deletions(-) diff --git a/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js b/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js index 15efbdd..bf0fbc0 100644 --- a/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js +++ b/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js @@ -166,6 +166,7 @@ const details = () => ({ \\nDefault is empty but the first example below has a suggested value. If unsure just leave empty. \\nEnsure to only use cmds valid to encoding QSV as the script handles other ffmpeg cmds relating to bitrate etc. Anything else entered here might be supported but could cause undesired results. + \\nIf you are using a "-vf" cmd, please put it at the end to avoid issues! \\nExample:\\n -look_ahead 1 -look_ahead_depth 100 -extbrc 1 -rdo 1 -mbbrc 1 -b_strategy 1 -adaptive_i 1 -adaptive_b 1 \\n Above enables look ahead, extended bitrate control, b-frames, etc.\\n @@ -664,7 +665,13 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { 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 '; + if (inputs.extra_qsv_options.search('-vf scale_qsv') >= 0) { + extraArguments += '-profile:v main10'; + // eslint-disable-next-line no-param-reassign + inputs.extra_qsv_options += ':format=p010le'; // Only add on the pixel format to existing scale_qsv cmd + } else { + extraArguments += '-profile:v main10 -vf scale_qsv=format=p010le'; + } response.infoLog += '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n'; } @@ -696,7 +703,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { break; case 'win32': // Windows - Full device, should fix child_device_type warnings response.preset += `-hwaccel qsv -hwaccel_output_format qsv - -init_hw_device qsv=qsv:MFX_IMPL_hw `; + -init_hw_device qsv:hw,child_device_type=d3d11va `; break; default: response.preset += '-hwaccel qsv -hwaccel_output_format qsv -init_hw_device qsv:hw_any '; @@ -743,34 +750,86 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { response.preset += 'hevc_qsv'; break; case 'win32': - response.preset += 'hevc_qsv -load_plugin hevc_hw'; - // Windows needs the additional -load_plugin. Tested working on a Win 10 - i5-10505 + response.preset += 'hevc_qsv'; + // Tested working on a Win 10 - i5-10505 break; default: response.preset += 'hevc_qsv'; // Default to QSV } - // If HW decode is happening add hwupload to encode - if (os.platform() !== 'darwin') { - if (high10 === false) { // Don't enable for High10 + // Check if -vf cmd has already been used on user input + if (high10 !== true) { + if (inputs.extra_qsv_options.search('-vf scale_qsv') >= 0) { + switch (file.video_codec_name) { + case 'mpeg2': + // eslint-disable-next-line no-param-reassign + inputs.extra_qsv_options += ',hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'h264': + // eslint-disable-next-line no-param-reassign + inputs.extra_qsv_options += ',hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'mjpeg': + // eslint-disable-next-line no-param-reassign + inputs.extra_qsv_options += ',hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'hevc': + // eslint-disable-next-line no-param-reassign + inputs.extra_qsv_options += ',hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'vp9': // Should be supported by 8th Gen + + // eslint-disable-next-line no-param-reassign + inputs.extra_qsv_options += ',hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'av1': // Should be supported by 11th gen + + // eslint-disable-next-line no-param-reassign + inputs.extra_qsv_options += ',hwupload=extra_hw_frames=64,format=qsv '; + break; + default: + } + } else if (extraArguments.search('-vf') === -1) { + // Check if -vf cmd has been used on the other var instead, if not add it & rest of cmd + switch (file.video_codec_name) { + case 'mpeg2': + extraArguments += '-vf hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'h264': + extraArguments += '-vf hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'mjpeg': + extraArguments += '-vf hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'hevc': + extraArguments += '-vf hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'vp9': // Should be supported by 8th Gen + + extraArguments += '-vf hwupload=extra_hw_frames=64,format=qsv '; + break; + case 'av1': // Should be supported by 11th gen + + extraArguments += '-vf hwupload=extra_hw_frames=64,format=qsv '; + break; + default: + } + } else { + // Otherwise add the cmd onto the end switch (file.video_codec_name) { case 'mpeg2': - extraArguments += '-vf "hwupload=extra_hw_frames=64,format=qsv" '; + extraArguments += ',hwupload=extra_hw_frames=64,format=qsv '; break; case 'h264': - extraArguments += '-vf "hwupload=extra_hw_frames=64,format=qsv" '; + extraArguments += ',hwupload=extra_hw_frames=64,format=qsv '; break; case 'mjpeg': - extraArguments += '-vf "hwupload=extra_hw_frames=64,format=qsv" '; + extraArguments += ',hwupload=extra_hw_frames=64,format=qsv '; break; case 'hevc': - extraArguments += '-vf "hwupload=extra_hw_frames=64,format=qsv" '; + extraArguments += ',hwupload=extra_hw_frames=64,format=qsv '; break; case 'vp9': // Should be supported by 8th Gen + - extraArguments += '-vf "hwupload=extra_hw_frames=64,format=qsv" '; + extraArguments += ',hwupload=extra_hw_frames=64,format=qsv '; break; case 'av1': // Should be supported by 11th gen + - extraArguments += '-vf "hwupload=extra_hw_frames=64,format=qsv" '; + extraArguments += ',hwupload=extra_hw_frames=64,format=qsv '; break; default: } 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 1eb92f1..f4c96ce 100644 --- a/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js +++ b/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js @@ -31,7 +31,7 @@ const tests = [ win32: { processFile: true, preset: '-fflags +genpts -hwaccel qsv -hwaccel_output_format qsv \n' - + ' -init_hw_device qsv=qsv:MFX_IMPL_hw -c:v h264_qsv -map 0 -c:v hevc_qsv -load_plugin hevc_hw -b:v 603k -minrate 452k -maxrate 754k -bufsize 1206k -preset slow -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -vf "hwupload=extra_hw_frames=64,format=qsv" ', + + ' -init_hw_device qsv:hw,child_device_type=d3d11va -c:v h264_qsv -map 0 -c:v hevc_qsv -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, @@ -96,7 +96,7 @@ const tests = [ win32: { processFile: true, preset: '-fflags +genpts -hwaccel qsv -hwaccel_output_format qsv \n' - + ' -init_hw_device qsv=qsv:MFX_IMPL_hw -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 -f mp4 -profile:v main10 -vf scale_qsv=format=p010le -vf "hwupload=extra_hw_frames=64,format=qsv" ', + + ' -init_hw_device qsv:hw,child_device_type=d3d11va -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 -f mp4 -profile:v main10 -vf scale_qsv=format=p010le', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, @@ -166,7 +166,7 @@ const tests = [ }, win32: { processFile: true, - preset: '-fflags +genpts -map 0 -c:v hevc_qsv -load_plugin hevc_hw -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 -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, @@ -243,7 +243,7 @@ const tests = [ win32: { processFile: true, preset: '-fflags +genpts -hwaccel qsv -hwaccel_output_format qsv \n' - + ' -init_hw_device qsv=qsv:MFX_IMPL_hw -c:v hevc_qsv -map 0 -c:v hevc_qsv -load_plugin hevc_hw -b:v 6000k -minrate 4500k -maxrate 7500k -bufsize 12000k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10 -vf scale_qsv=format=p010le -vf "hwupload=extra_hw_frames=64,format=qsv" ', + + ' -init_hw_device qsv:hw,child_device_type=d3d11va -c:v hevc_qsv -map 0 -c:v hevc_qsv -b:v 6000k -minrate 4500k -maxrate 7500k -bufsize 12000k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10 -vf scale_qsv=format=p010le ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, @@ -352,7 +352,7 @@ const tests = [ win32: { processFile: true, preset: '-fflags +genpts -hwaccel qsv -hwaccel_output_format qsv \n' - + ' -init_hw_device qsv=qsv:MFX_IMPL_hw -c:v h264_qsv -map 0 -c:v hevc_qsv -load_plugin hevc_hw -b:v 3227k -minrate 2420k -maxrate 4034k -bufsize 6454k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -map -0:3 -map -0:4 -map -0:5 -map -0:6 -f mp4 -vf "hwupload=extra_hw_frames=64,format=qsv" ', + + ' -init_hw_device qsv:hw,child_device_type=d3d11va -c:v h264_qsv -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 -map -0:3 -map -0:4 -map -0:5 -map -0:6 -f mp4 ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, @@ -420,7 +420,7 @@ const tests = [ win32: { processFile: true, preset: '-fflags +genpts -hwaccel qsv -hwaccel_output_format qsv \n' - + ' -init_hw_device qsv=qsv:MFX_IMPL_hw -c:v h264_qsv -map 0 -c:v hevc_qsv -load_plugin hevc_hw -b:v 3227k -minrate 2420k -maxrate 4034k -bufsize 6454k -preset fast -c:a copy -c:s copy -max_muxing_queue_size 9999 -map -0:d -map -0:3 -map -0:4 -map -0:5 -f matroska -vf "hwupload=extra_hw_frames=64,format=qsv" ', + + ' -init_hw_device qsv:hw,child_device_type=d3d11va -c:v h264_qsv -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 -map -0:d -map -0:3 -map -0:4 -map -0:5 -f matroska ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, @@ -450,6 +450,73 @@ const tests = [ }, }, }, + // Test 7 + { + input: { + file: _.cloneDeep(require('../sampleData/media/sampleH264_1.json')), + librarySettings: {}, + inputs: { + container: 'mkv', + encoder_speedpreset: 'fast', + extra_qsv_options: '-look_ahead 1 -look_ahead_depth 100 -extbrc 1 -rdo 1 -mbbrc 1 -b_strategy 1 -adaptive_i 1 -adaptive_b 1 -vf scale_qsv=1280:-1', + enable_10bit: 'true', + }, + otherArguments: {}, + }, + output: { + linux: { + processFile: true, + 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 -look_ahead 1 -look_ahead_depth 100 -extbrc 1 -rdo 1 -mbbrc 1 -b_strategy 1 -adaptive_i 1 -adaptive_b 1 -vf scale_qsv=1280:-1:format=p010le -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10', + 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' + + 'File Transcoding... \n', + container: '.mkv', + }, + win32: { + processFile: true, + preset: '-fflags +genpts -hwaccel qsv -hwaccel_output_format qsv \n' + + ' -init_hw_device qsv:hw,child_device_type=d3d11va -c:v h264_qsv -map 0 -c:v hevc_qsv -b:v 603k -minrate 452k -maxrate 754k -bufsize 1206k -preset fast -look_ahead 1 -look_ahead_depth 100 -extbrc 1 -rdo 1 -mbbrc 1 -b_strategy 1 -adaptive_i 1 -adaptive_b 1 -vf scale_qsv=1280:-1:format=p010le -c:a copy -c:s copy -max_muxing_queue_size 9999 -f matroska -profile:v main10', + 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' + + 'File Transcoding... \n', + container: '.mkv', + }, + darwin: { + processFile: true, + preset: '-fflags +genpts -hwaccel videotoolbox -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);