@ -353,10 +353,10 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
for ( let i = 0 ; i < file . ffProbeData . streams . length ; i += 1 ) {
const strstreamType = file . ffProbeData . streams [ i ] . codec _type . toLowerCase ( ) ;
videoIdx = - 1 ;
// Check if stream is a video.
if ( videoIdx === - 1 && strstreamType === 'video' ) {
videoIdx = i ;
if ( strstreamType === 'video' ) {
if ( file . ffProbeData . streams [ i ] . codec _name !== 'mjpeg'
&& file . ffProbeData . streams [ i ] . codec _name !== 'png' ) {
// Try checking file stats using Mediainfo first, then ffprobe.
try {
videoBR = Number ( file . mediaInfo . track [ i + 1 ] . BitRate ) / 1000 ;
@ -380,9 +380,15 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
duration = file . meta . Duration ;
duration = ( new Date ( ` 1970-01-01T ${ duration } Z ` ) . getTime ( ) / 1000 ) / 60 ;
} else { // If not filled then get duration of video stream and do the same.
duration = file . ffProbeData . streams [ v ideoIdx ] . tags . DURATION ;
duration = file . ffProbeData . streams [ i] . tags . DURATION ;
duration = ( new Date ( ` 1970-01-01T ${ duration } Z ` ) . getTime ( ) / 1000 ) / 60 ;
}
if ( videoBR <= 0 || Number . isNaN ( videoBR ) ) {
// videoBR not yet valid so Loop
} else {
break ; // Exit loop if videoBR is valid
}
}
}
}
@ -532,10 +538,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
// Check if codec of stream is mjpeg/png, if so then remove this "video" stream.
// mjpeg/png are usually embedded pictures that can cause havoc with plugins.
if ( file . ffProbeData . streams [ i ] . codec _name === 'mjpeg' || file . ffProbeData . streams [ i ] . codec _name === 'png' ) {
extraArguments += ` -map -v: ${ videoIdx } ` ;
}
// Check for HDR in files. If so exit plugin. We assume HDR files have bt2020 color spaces. HDR can be complicated
extraArguments += ` -map -0:v: ${ videoIdx } ` ;
} else { // Ensure to only do further checks if video stream is valid for use
// Check for HDR in files. If so exit plugin. HDR can be complicated
// 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'
@ -618,6 +623,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
|| file . ffProbeData . streams [ i ] . bits _per _raw _sample === '10' || inputs . enable _10bit === true ) {
main10 = true ;
}
}
// Increment video index. Needed to keep track of video id in case there is more than one video track.
// (i.e png or mjpeg which we would remove at the start of the loop)
@ -661,6 +667,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
}
// Are we encoding to 10 bit? If so enable correct profile & pixel format.
if ( os . platform ( ) !== 'darwin' ) {
if ( swDecode === true && main10 === true ) {
// This is used if we have High10 or Main10 is enabled & odd format files.
// SW decode and use standard -pix_fmt p010le
@ -676,6 +683,11 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
}
response . infoLog += '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n' ;
}
} else {
// Mac - Video toolbox profile & pixel format
extraArguments += '-profile:v 2 -pix_fmt yuv420p10le ' ;
response . infoLog += '10 bit encode enabled. Setting VideoToolBox Profile v2 & 10 bit pixel format \n' ;
}
// Set bitrateSettings variable using bitrate information calculated earlier.
bitrateSettings = ` -b:v ${ targetBitrate } k -minrate ${ minimumBitrate } k `
@ -712,6 +724,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
}
} else {
switch ( os . platform ( ) ) {
case 'darwin' : // Mac OS - Enable videotoolbox instead of QSV
response . preset += '-hwaccel videotoolbox' ;
break ;
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 ` ;
@ -780,7 +795,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
// Only add on for HW decoded formats
// VC1 & VP8 are no longer supported on new HW, add cases here if your HW does support
if ( swDecode !== true ) {
if ( swDecode !== true && os . platform ( ) !== 'darwin' ) {
// Check if -vf cmd has already been used on user input
if ( inputs . extra _qsv _options . search ( '-vf scale_qsv' ) >= 0 ) {
switch ( file . video _codec _name ) {