Update plugin - Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC - OS support, custom ffmpeg cmd input + clean-up (#306)

* Create Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js

* Update Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js

* Update Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js

* Update Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js

Corrected some tooltips. Plugin should now have all the descriptions correct & should round bitrates down to avoid decimals on the ffmpeg cmd.

* Initial sweep through noted issues

Initial sweep through all issues. Spelling should be corrected.
Unneeded returns & parenthesis removed.
Force conform added for mp4>mkv etc.
Encoder pre-set speed changed to slow default.
10 bit option now correctly allows encode to 10bit with separate check if file is already 10bit.
Comments & layout improved

* Another round of fixes

Spelling cleaned up again
10bit encode logic corrected again
Vars cleaned up
Comments formatted a bit better

* Fix checkPlugins error

* Fixed input types

Input types should be fixed
Merged change to replace "function details"
Minor correction to a comment in the wrong place

* Very minor update to strings

Just adding some full stops to ends of lines

* Create Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js

* Update Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js

* Update Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js

* Update Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js

Corrected some tooltips. Plugin should now have all the descriptions correct & should round bitrates down to avoid decimals on the ffmpeg cmd.

* Initial sweep through noted issues

Initial sweep through all issues. Spelling should be corrected.
Unneeded returns & parenthesis removed.
Force conform added for mp4>mkv etc.
Encoder pre-set speed changed to slow default.
10 bit option now correctly allows encode to 10bit with separate check if file is already 10bit.
Comments & layout improved

* Another round of fixes

Spelling cleaned up again
10bit encode logic corrected again
Vars cleaned up
Comments formatted a bit better

* Fix checkPlugins error

* Lint

* Changed strings to numbers for bitrate settings

Also added "k" to some strings for the info logs so they are more consistent

* Fix for possible issue where target bitrate ends up higher than current bitrate

Been reported that a file ended up coming out larger and in fact the target bitrate somehow ended up being double the current bitrate instead of half.
Never seen this myself but I've changed two things.
Adjusted the targetBitrate calculation to ensure halving it happens last. Then added in a protection incase the target bitrate ends up equal or higher than the current bitrate.

* Fix for If checks after changing strings to numbers

Due to changing the strings to numbers some IF checks needed updating to check if things were "0" now instead of just blank.

* Tidy up of tooltips to add more info

Tidied up tooltips for hevc options to make them clearer and formatted better
Also removed some lines which were unneeded

* Reverting change from string to number

Changed the inputs back to strings. As numbers we can't default them to a blank value which is better for users
Also moved HDR check to top of video check to ensure it's caught before we start trying to remux anything.

* Changed inputs back to numbers

Text entries now changed back to numbers. Tooltip explains that 0 means disabled and a valid number is needed to use them.

* Very minor fix

Left space at end of "extraArguments" to ensure it doesn't disrupt the rest of the ffmpeg cmd line

* Lint error

* Updated to account for OS types

Updated to account for OS types & clean up of decode & encode steps. Another clean-up of tooltips as well

* Another cleanup

Cleanup tooltips & comments

* Another change to tooltips

* Another cleanup

Also corrected messy info for the OS options

* Another cleanup of Tooltips

Try and make them much clearer...

* Remove bad comment

* Revert "Merge branch 'master' of https://github.com/Boosh1/Tdarr_Plugins"

This reverts commit 116fdc5df958cde059289d0caa8466e187f3f616, reversing
changes made to bf4f1bfeb5e896279aca85a467e1fea7e0026309.

* Revert "Revert "Merge branch 'master' of https://github.com/Boosh1/Tdarr_Plugins""

This reverts commit 5de425147a640f1328f6192e0155fdfe5da59143.

Co-authored-by: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com>
make-only-subtitle-default
Boosh1 4 years ago committed by GitHub
parent 584e4cb557
commit 2179a1f634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,11 @@
// All credit for original plugin logic goes to Migz.
// This Plugin is essentially just his NVENC/CPU plugin modified to work with QSV & with extra hevc logic.
// Extra logic is mainly to control encoder quality/speed & to allow HEVC files to be reprocessed to reduce file size
// NOTE - This does not use VAAPI, it is QSV only. So newer intel igpus only. 8th+ gen should work.
// NOTE - This does not use VAAPI, it is QSV only. So newer intel iGPUs only. 8th+ gen should work.
// Additionally this was designed and tested on UNRAID via docker though there is logic to support use on
// Windows, Linux & Mac
// White paper from intel regarding QSV performance on linux using FFMPEG here:
// eslint-disable-next-line max-len
// https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/cloud-computing-quicksync-video-ffmpeg-white-paper.pdf
@ -12,12 +16,14 @@ const details = () => ({
Name: 'Boosh-Transcode using QSV GPU & FFMPEG',
Type: 'Video',
Operation: 'Transcode',
Description: `This is a QSV specific plugin, VAAPI is NOT used. So an INTEL QSV enabled CPU is required.
8th+ gen CPUs should work. Files not in H265/HEVC will be transcoded into H265/HEVC using Quick Sync Video (QSV)
via Intel GPU with ffmpeg. Settings are dependant on file bitrate working by the logic that H265 can support
Description: `This is a QSV specific plugin. 8th+ gen INTEL QSV enabled CPUs are required. VAAPI is NOT used.
Files not in H265/HEVC will be transcoded into H265/HEVC using Quick Sync Video (QSV)
via Intel GPU using FFmpeg. Settings are dependant on file bitrate working by the logic that H265 can support
the same amount of data at half the bitrate of H264. This plugin will skip files already in HEVC, AV1 & VP9
unless "reconvert_hevc" is marked as true. If it is then these will be reconverted again into HEVC if they
exceed the bitrate specified in "hevc_max_bitrate". Reminder! An INTEL QSV enabled CPU is required.`,
exceed the bitrate specified in "hevc_max_bitrate". Reminder! An INTEL QSV enabled CPU is required.
NOTE - Created for use with UNRAID Docker and while it should support Windows/Mac etc, it may require
a custom version of FFmpeg to work properly.`,
Version: '1.0',
Tags: 'pre-processing,ffmpeg,video only,qsv,h265,hevc,configurable',
Inputs: [
@ -32,9 +38,13 @@ const details = () => ({
'mp4',
],
},
tooltip: `Specifies the output container of the file.
tooltip: `\\n
==DESCRIPTION==
\\n Specifies the output container of the file.
\\n Ensure that all stream types you may have are supported by your chosen container.
\\n MKV is recommended.
\\n
==INFO==
\\n Only MP4 & MKV are supported and MKV is recommended.
\\nExample:\\n
mkv
\\nExample:\\n
@ -51,17 +61,22 @@ const details = () => ({
'true',
],
},
tooltip: `Make the file conform to output containers requirements.
Use if you need to ensure the encode works from mp4>mkv or mkv>mp4.
This will drop data of certain type so ensure you are happy with that,
or use another plugin to convert these data types first.
\\n Drop hdmv_pgs_subtitle/eia_608/subrip/timed_id3 for MP4.
\\n Drop data streams/mov_text/eia_608/timed_id3 for MKV.
\\n Default is false.
\\nExample:\\n
true
\\nExample:\\n
false`,
tooltip: `\\n
==DESCRIPTION==
\\n Make the file conform to output containers requirements.
Use if you need to ensure the encode works from mp4>mkv or mkv>mp4. \\n
==WARNING== \\n
This will remove data of certain types so ensure you are happy with that,
or use another plugin to convert these data types first!
\\n
==INFO==
\\n Drop hdmv_pgs_subtitle/eia_608/subrip/timed_id3 for MP4.
\\n Drop data streams/mov_text/eia_608/timed_id3 for MKV.
\\n Default is false.
\\nExample:\\n
true
\\nExample:\\n
false`,
},
{
name: 'encoder_speedpreset',
@ -79,17 +94,50 @@ const details = () => ({
'veryslow',
],
},
tooltip: `Specify the encoder speed/preset to use.
Slower options mean slower encode but better quality and faster have quicker encodes but worse quality.
For more information see intel white paper on ffmpeg results using qsv: \\n`
// eslint-disable-next-line max-len
+ `https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/cloud-computing-quicksync-video-ffmpeg-white-paper.pdf
tooltip: `\\n
==DESCRIPTION==
\\n Specify the encoder speed/preset to use.
Slower options mean a slower encode but better quality and faster options mean faster encodes but
worse quality.
\\n For more information see intel white paper on FFmpeg results using QSV: \\n`
// eslint-disable-next-line max-len
+ `https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/cloud-computing-quicksync-video-ffmpeg-white-paper.pdf
\\n
==INFO==
\\n Default is "slow".
\\nExample:\\n
medium
\\nExample:\\n
slower`,
},
{
name: 'extra_qsv_options',
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
},
tooltip: `\\n
==DESCRIPTION==
\\n Here you can add extra options to the FFmpeg QSV ENCODE cmd.
This does not override the FFmpeg cmd, it just allows additions to it.
\\n
There are extra QSV options that can be
forced on/off as desired. See here for some possible cmds -
https://ffmpeg.org/ffmpeg-codecs.html#toc-HEVC-Options-1
\\n
==WARNING== \\n
Just because a cmd is mentioned doesn't mean your installed version of FFmpeg supports it...
Be certain to verify the cmds work before adding to your workflow. \\n
Check Tdarr Help Tab. Enter FFmpeg cmd - "-h encoder=hevc_qsv". This will give a list of supported commands.
\\n
==INFO==
\\n Default is empty but a suggested value is below. If unsure just leave empty.
\\n Ensure 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.
\\nExample:\\n
-extbrc 1 -rdo 1 -mbbrc 1 -b_strategy 1 -adaptive_i 1 -adaptive_b 1`,
},
{
name: 'enable_10bit',
type: 'boolean',
@ -101,11 +149,15 @@ const details = () => ({
'true',
],
},
tooltip: `Specify if we want to enable 10bit encoding.
If this is enabled files will be processed and converted into 10bit
tooltip: `\\n
==DESCRIPTION==
\\n Specify if we want to enable 10bit encoding.
\\n If this is enabled files will be processed and converted into 10bit
HEVC using main10 profile and with p010le pixel format. \n
If you just want to retain 10 bit already in files then this can be left as false, as
10bit to 10bit in ffmpeg should be automatic.
If you just want to retain files that are already 10 bit then this can be left as false, as
10bit to 10bit in FFmpeg should be automatic.
\\n
==INFO==
\\n Default is "false".
\\nExample:\\n
true
@ -119,9 +171,13 @@ const details = () => ({
inputUI: {
type: 'text',
},
tooltip: `Specify bitrate cutoff, files with a total bitrate lower then this will not be processed.
tooltip: `\\n
==DESCRIPTION==
\\n Specify bitrate cutoff, files with a total bitrate lower then this will not be processed. \n
Since getting the bitrate of the video from files is unreliable, bitrate here refers to the total
bitrate of the file and not just the video steam.
\\n
==INFO==
\\n Rate is in kbps.
\\n Defaults to 0 which means this is disabled.
\\n Enter a valid number to enable.
@ -137,10 +193,14 @@ const details = () => ({
inputUI: {
type: 'text',
},
tooltip: `Specify a maximum average video bitrate. When encoding we take the current total bitrate and halve it
tooltip: `\\n
==DESCRIPTION==
\\n Specify a maximum average video bitrate. When encoding we take the current total bitrate and halve it
to get an average target. This option sets a upper limit to that average
(i.e if you have a video bitrate of 10000, half is 5000, if your maximum desired average bitrate is 4000
then we use that as the target instead of 5000).
\\n
==INFO==
\\n Bitrate here is referring to video bitrate as we want to set the video bitrate on encode.
\\n Rate is in kbps.
\\n Defaults to 0 which means this is disabled.
@ -157,11 +217,15 @@ const details = () => ({
inputUI: {
type: 'text',
},
tooltip: `Specify a minimum average video bitrate. When encoding we take the current total bitrate and halve
it to get an average target. This option sets a lower limit to that average (i.e if you have a video bitrate
of 3000, half is 1500, if your minimum desired average bitrate is 2000 then we use that as the target instead
of 1500).
\\nBitrate here is referring to video bitrate as we want to set the video bitrate on encode.
tooltip: `\\n
==DESCRIPTION==
\\n Specify a minimum average video bitrate. When encoding we take the current total bitrate and halve
it to get an average target. This option sets a lower limit to that average (i.e if you have a video bitrate
of 3000, half is 1500, if your minimum desired average bitrate is 2000 then we use that as the target instead
of 1500).
\\n
==INFO==
\\n Bitrate here is referring to video bitrate as we want to set the video bitrate on encode.
\\n Rate is in kbps.
\\n Defaults to 0 which means this is disabled.
\\n Enter a valid number to enable.
@ -181,9 +245,12 @@ const details = () => ({
'true',
],
},
tooltip: `Specify if we want to reprocess HEVC, VP9 or AV1 files
(i.e reduce bitrate of files already in those codecs). Since this uses the same logic as normal, halving the
current bitrate, this is NOT recommended unless you know what you are doing, so leave false if unsure.
tooltip: `\\n
==DESCRIPTION==
\\n Specify if we want to reprocess HEVC, VP9 or AV1 files
(i.e reduce bitrate of files already in those codecs).
\\n Since this uses the same logic as normal, halving the current bitrate, this is NOT recommended
unless you know what you are doing, so leave false if unsure.
NEEDS to be used in conjunction with "bitrate_cutoff" or "hevc_max_bitrate" otherwise is ignored.
This is useful in certain situations, perhaps you have a file which is HEVC but has an extremely high
bitrate and you'd like to reduce it.
@ -192,7 +259,9 @@ const details = () => ({
"hevc_max_bitrate" & "max_average_bitrate" to prevent the plugin looping. Also it is highly suggested
that you have your "hevc_max_bitrate" higher than "max_average_bitrate".
\\n Again if you are unsure, please leave this as false!
\\n\\n WARNING!! IF YOU HAVE VP9 OR AV1 FILES YOU WANT TO KEEP IN THOSE FORMATS THEN DO NOT USE THIS OPTION.
\\n
==WARNING== \\n
IF YOU HAVE VP9 OR AV1 FILES YOU WANT TO KEEP IN THOSE FORMATS THEN DO NOT USE THIS OPTION.
\\n
\\nExample:\\n
true
@ -206,7 +275,9 @@ const details = () => ({
inputUI: {
type: 'text',
},
tooltip: `Has no effect unless "reconvert_hevc" is set to true. This allows you to specify a maximum
tooltip: `\\n
==DESCRIPTION==
\\n Has no effect unless "reconvert_hevc" is set to true. This allows you to specify a maximum
allowed average bitrate for HEVC or similar files. Much like the "bitrate_cutoff" option, but
specifically for HEVC files. It should be set HIGHER then your standard cutoff for safety.
\\n Also, it's highly suggested you use the min & max average bitrate options in combination with this. You
@ -216,6 +287,8 @@ const details = () => ({
this is why it is NOT recommended!
\\n As with the cutoff, getting the bitrate of the video from files is unreliable, so bitrate
here refers to the total bitrate of the file and not just the video steam.
\\n
==INFO==
\\n Rate is in kbps.
\\n Defaults to 0 which means this is disabled.
\\n Enter a valid number to enable, otherwise we use "bitrate_cutoff" and multiply x2 for a safe limit.
@ -229,7 +302,7 @@ const details = () => ({
// eslint-disable-next-line no-unused-vars
const plugin = (file, librarySettings, inputs, otherArguments) => {
const lib = require('../methods/lib')();
const lib = require('../methods/lib')(); const os = require('os');
// eslint-disable-next-line no-unused-vars,no-param-reassign
inputs = lib.loadDefaultValues(inputs, details);
const response = {
@ -413,7 +486,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
}
// Check for HDR in files. If so exit plugin. We assume HDR files have bt2020 color spaces. HDR can be complicated
// and some aspects are still unsupported in ffmpeg I believe. Likely we don't want to re-encode anything HDR.
// and some aspects are still unsupported in FFmpeg I believe. Likely we don't want to re-encode anything HDR.
if (file.ffProbeData.streams[i].color_space === 'bt2020nc'
&& file.ffProbeData.streams[i].color_transfer === 'smpte2084'
&& file.ffProbeData.streams[i].color_primaries === 'bt2020') {
@ -502,57 +575,80 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
+ `-maxrate ${maximumBitrate}k -bufsize ${currentBitrate}k`;
// Print to infoLog information around file & bitrate settings.
response.infoLog += `\nContainer for output selected as ${inputs.container}. \n`;
response.infoLog += `The current file bitrate = ${currentBitrate}k \n`;
response.infoLog += 'Bitrate settings: \n';
response.infoLog += 'Encode variable bitrate settings: \n';
response.infoLog += `Target = ${targetBitrate}k \n`;
response.infoLog += `Minimum = ${minimumBitrate}k \n`;
response.infoLog += `Maximum = ${maximumBitrate}k \n`;
// Codec will be checked so it can be transcoded correctly
// (QSV doesn't support HW decode of all older codecs, h263 & mpeg1 are SW based currently)
// If source file is 10 bit then don't hardware decode at all as this can cause issues.
// Instead best just to cpu decode to ensure it works.
// START PRESET
// DECODE FLAGS
// -fflags +genpts should regenerate timestamps if they end up missing...
response.preset = '-fflags +genpts ';
// Attempt to enable HW Decoding...
// If source file is 10 bit then bail as this can cause issues. Think it's the -c:v option that can break during 10bit
if (main10 === false) {
// Currently supported HW decode types
switch (file.video_codec_name) {
case 'h263':
response.preset = '-hwaccel qsv -c:v h263';
case 'mpeg2':
response.preset += '-hwaccel qsv -c:v mpeg2_qsv';
break;
case 'h264':
response.preset = '-hwaccel qsv -c:v h264_qsv';
break;
case 'mjpeg':
response.preset = '-hwaccel qsv -c:v mjpeg_qsv';
break;
case 'hevc':
response.preset = '-hwaccel qsv -c:v hevc_qsv';
break;
case 'mpeg1':
response.preset = '-hwaccel qsv -c:v mpeg1';
break;
case 'mpeg2':
response.preset = '-hwaccel qsv -c:v mpeg2_qsv';
response.preset += '-hwaccel qsv -c:v h264_qsv';
break;
case 'vc1':
response.preset = '-hwaccel qsv -c:v vc1_qsv';
response.preset += '-hwaccel qsv -c:v vc1_qsv';
break;
case 'mjpeg':
response.preset += '-hwaccel qsv -c:v mjpeg_qsv';
break;
case 'vp8':
response.preset = '-hwaccel qsv -c:v vp8_qsv';
response.preset += '-hwaccel qsv -c:v vp8_qsv';
break;
case 'av1':
response.preset = '-hwaccel qsv -c:v av1';
case 'hevc':
response.preset += '-hwaccel qsv -c:v hevc_qsv';
break;
case 'vp9': // Should be supported by 8th Gen +
response.preset += '-hwaccel qsv -c:v vp9_qsv';
break;
default:
response.preset = '';
response.preset += '-hwaccel qsv';
}
} else {
response.preset += '-hwaccel qsv';
// Enable basic hwaccel regardless. Seems to work...
}
response.preset += `<io> -map 0 -c:v hevc_qsv ${bitrateSettings} `
+ `-preset ${inputs.encoder_speedpreset} -look_ahead 1
// ADD ENCODE FLAGS TO PRESET
response.preset += '<io> -map 0 -c:v ';
// Account for different OS setup for QSV.
// FYI Darwin is Mac OS
switch (os.platform()) {
case 'darwin':
response.preset += 'hevc_videotoolbox';
// hevc_videotoolbox is for Mac but that doesn't seem to be included in Tdarr current Jellyfin FFmpeg
// Likely needs custom FFmpeg installed
break;
case 'linux':
response.preset += 'hevc_qsv';
break;
case 'win32':
response.preset += 'hevc_qsv -load_plugin hevc_hw';
// Windows needs the additional -load_plugin plugin. Tested working on a Win 10 - i5-10505
break;
default:
response.preset += 'hevc_qsv';
}
// Add the rest of the FFmpeg command
response.preset += ` ${bitrateSettings} `
+ `-preset ${inputs.encoder_speedpreset} ${inputs.extra_qsv_options}
-c:a copy -c:s copy -max_muxing_queue_size 9999 ${extraArguments}`;
// Other settings to consider.
// -b_strategy 1 -adaptive_b 1 -adaptive_i 1 -async_depth 1 -look_ahead 1 -look_ahead_depth 100
response.processFile = true;
response.infoLog += 'File Transcoding. \n';
response.infoLog += 'File Transcoding... \n';
return response;
};
module.exports.details = details;

Loading…
Cancel
Save