Found new edge cases so changed how HW decode is triggered

Ended up finding more cases where errors would pop up and looks to all to do with HW decode.
- Now ensured that unless the incoming format is in the white list then sw decode is done instead
- Correctly removed -hwaccel cmd when sw decode happens preventing accidental hwdecode
- Specify the format to decode when using sw
- renamed oldformat var to match its use case (now swDecode)
- Info log updated with when SW decode happens and will report which incoming format caused it
make-only-subtitle-default
Boosh1 2 years ago
parent 23bef4c778
commit f4c02bc997

@ -326,7 +326,7 @@ let bitrateSettings = '';
let inflatedCutoff = 0; let inflatedCutoff = 0;
let main10 = false; let main10 = false;
let high10 = false; let high10 = false;
let oldFormat = false; let swDecode = false;
let videoBR = 0; let videoBR = 0;
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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') { if (file.ffProbeData.streams[i].profile === 'High 10') {
high10 = true; high10 = true;
response.infoLog += 'Input file is 10bit using High10. Disabling hardware decoding to avoid problems. \n'; main10 = true;
} // If files are 10 bit or the enable_10bit setting is used mark to enable Main10.
// 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'
if (file.ffProbeData.streams[i].profile === 'Main 10' || file.ffProbeData.streams[i].bits_per_raw_sample === '10' || file.ffProbeData.streams[i].bits_per_raw_sample === '10' || inputs.enable_10bit === true) {
|| inputs.enable_10bit === true) {
main10 = true; main10 = true;
} }
@ -637,26 +636,32 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
default: 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) { switch (file.video_codec_name) {
case 'mpeg2': case 'mpeg2':
break; break;
case 'h264': case 'h264':
if (high10 === true) {
response.infoLog += `Input file is ${file.video_codec_name} High10. Hardware Decode not supported. \n`;
swDecode = true;
}
break; break;
case 'mjpeg': case 'mjpeg':
break; break;
case 'hevc': case 'hevc':
break; break;
case 'vp9': case 'vp9':// Should be supported by 8th Gen +
break; break;
case 'av1': case 'av1':// Should be supported by 11th gen +
break; break;
default: 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. // 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. // This is used if we have High10 or Main10 is enabled & odd format files.
// SW decode and use standard -pix_fmt p010le // SW decode and use standard -pix_fmt p010le
extraArguments += '-profile:v main10 -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... // -fflags +genpts should regenerate timestamps if they end up missing...
response.preset = '-fflags +genpts '; response.preset = '-fflags +genpts ';
// HW ACCEL FLAGS - I think these are good practice but are they necessary? // HW ACCEL FLAGS
// Account for different OS // Account for different OS
if (high10 === false) { if (swDecode !== true) {
// Seems incoming High10 files don't play nice decoding so use software decode // Only enable hw decode for accepted formats
switch (os.platform()) { switch (os.platform()) {
case 'darwin': // Mac OS - Enable videotoolbox instead of QSV case 'darwin': // Mac OS - Enable videotoolbox instead of QSV
response.preset += '-hwaccel videotoolbox'; response.preset += '-hwaccel videotoolbox';
@ -705,38 +710,51 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
default: default:
response.preset += '-hwaccel qsv -hwaccel_output_format qsv -init_hw_device qsv:hw_any '; 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 // DECODE FLAGS
// VC1 & VP8 are no longer supported on new HW, add cases here if your HW does support
if (os.platform() !== 'darwin') { if (os.platform() !== 'darwin') {
if (high10 === false) { // Don't enable for High10 switch (file.video_codec_name) {
switch (file.video_codec_name) { case 'mpeg2':
case 'mpeg2': response.preset += '-c:v mpeg2_qsv';
response.preset += '-c:v mpeg2_qsv'; break;
break; case 'h264':
case 'h264': if (high10 !== true) { // Don't enable for High10
response.preset += '-c:v h264_qsv'; response.preset += '-c:v h264_qsv';
break; } else {
case 'vc1': // VC1 no longer supported on latest intel HW response.preset += `-c:v ${file.video_codec_name}`;
// response.preset += '-c:v vc1_qsv'; }
break; break;
case 'mjpeg': case 'mjpeg':
response.preset += '-c:v mjpeg_qsv'; response.preset += '-c:v mjpeg_qsv';
break; break;
case 'vp8': // VP8 no longer supported on latest intel HW case 'hevc':
// response.preset += '-c:v vp8_qsv'; response.preset += '-c:v hevc_qsv';
break; break;
case 'hevc': case 'vp9': // Should be supported by 8th Gen +
response.preset += '-c:v hevc_qsv'; response.preset += '-c:v vp9_qsv';
break; break;
case 'vp9': // Should be supported by 8th Gen + case 'av1': // Should be supported by 11th gen +
response.preset += '-c:v vp9_qsv'; response.preset += '-c:v av1_qsv';
break; break;
case 'av1': // Should be supported by 11th gen + default:
response.preset += '-c:v av1_qsv'; // Use incoming format for software decode
break; response.preset += `-c:v ${file.video_codec_name}`;
default:
}
} }
} }
@ -760,8 +778,10 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
response.preset += 'hevc_qsv'; // Default to QSV response.preset += 'hevc_qsv'; // Default to QSV
} }
// Check if -vf cmd has already been used on user input // Only add on for HW decoded formats
if (high10 !== true) { // 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) { if (inputs.extra_qsv_options.search('-vf scale_qsv') >= 0) {
switch (file.video_codec_name) { switch (file.video_codec_name) {
case 'mpeg2': case 'mpeg2':

@ -149,12 +149,13 @@ const tests = [
output: { output: {
linux: { linux: {
processFile: true, processFile: true,
preset: '-fflags +genpts <io> -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<io> -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, handBrakeMode: false,
FFmpegMode: true, FFmpegMode: true,
reQueueAfter: true, reQueueAfter: true,
infoLog: '☑ It looks like the current video bitrate is 6454kbps. \n' 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' + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n'
+ 'Container for output selected as mkv. \n' + 'Container for output selected as mkv. \n'
+ 'Encode variable bitrate settings: \n' + 'Encode variable bitrate settings: \n'
@ -166,12 +167,13 @@ const tests = [
}, },
win32: { win32: {
processFile: true, processFile: true,
preset: '-fflags +genpts <io> -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<io> -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, handBrakeMode: false,
FFmpegMode: true, FFmpegMode: true,
reQueueAfter: true, reQueueAfter: true,
infoLog: '☑ It looks like the current video bitrate is 6454kbps. \n' 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' + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n'
+ 'Container for output selected as mkv. \n' + 'Container for output selected as mkv. \n'
+ 'Encode variable bitrate settings: \n' + 'Encode variable bitrate settings: \n'
@ -183,7 +185,7 @@ const tests = [
}, },
darwin: { darwin: {
processFile: true, processFile: true,
preset: '-fflags +genpts <io> -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<io> -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, handBrakeMode: false,
FFmpegMode: true, FFmpegMode: true,
reQueueAfter: 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<io> -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<io> -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<io> -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); void run(tests);

Loading…
Cancel
Save