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

Fix for HW decode & High10 - Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js #502

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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`;
Expand All @@ -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';
Expand All @@ -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';
Expand Down
8 changes: 5 additions & 3 deletions tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ const tests = [
output: {
linux: {
processFile: true,
preset: '-fflags +genpts <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 -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<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 -profile:v main10 -vf scale_qsv=format=p010le ',
handBrakeMode: false,
FFmpegMode: true,
reQueueAfter: true,
Expand All @@ -96,7 +97,8 @@ const tests = [
},
win32: {
processFile: true,
preset: '-fflags +genpts <io> -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<io> -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,
Expand All @@ -113,7 +115,7 @@ const tests = [
},
darwin: {
processFile: true,
preset: '-fflags +genpts <io> -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<io> -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,
Expand Down
Loading