Open uchagani opened 1 year ago
Looks like adding it to postopts works postopts = -vf,scale_qsv=w=1920:h=1080:format=nv12
however I had to remove the values from pix-fmt
so it looks like pix-fmt =
. Does this mean that all files will be converted to nv12?
Is there a way for me to only convert only if the source pix_fmt is not nv12, yuv420p
? And if a conversion is necessary, use the -vf
parameter to specify the format instead of the -pix_fmt
since it seems that's what ffmpeg needs in this situation to work correctly.
@mdhiggins I wonder if these issues are because of ffmpeg 5+? I just tried vaapi instead of qsv and i got the same error trying to convert 10bit hevc to h264: Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scale_0'
@mdhiggins it seems that for quicksync the pix_fmt
option is not supported and it needs to be part of the video format:
Also when transcoding 10bit to 8bit, the pix_fmt option needs to be nv12 with qsv. other options won't work.
So it looks like this issue is multifactorial
First problem is that the QSV protcol in SMA doesn't have a specific override like VAAPI or NVENC to handle the resizing scalar options and insert the proper filters, I just added a variant of this based on the way NVEnvc is implemented so see if that helps
bc362d41e4ecc855cebf204c6155270bb440ea7d
The other issue is your approach to inserting this information. With this update and with the behavior of the other codecs you don't need to force the filter using post opts as it will get injected when appropriate
Your pix_fmt shouldn't be nv12 since this is more of a transitional format to move between the hardware encoder/decoder and not a valid final output format, and the above update should inject nv12 as the format transiently
See if that works, if not I have another approach more similar to the way the VAAPI codec injects the filters that I can try. I unfortunately do not have a QSV device available for testing
thanks i'll try this out today. I'm aiming to convert all files to 8bit h264. if that's the case, what pix_fmt should i use in order to use qsv?
@mdhiggins still getting some errors and i'm happy to test out as much as you would like. I tried the following ways:
Here are the different errors and the generated ffmpeg commands:
pix_fmt blank:
[h264_qsv @ 0x55cf63a71580] Current pixel format is unsupported
[h264_qsv @ 0x55cf63a71580] some encoding parameters are not supported by the QSV runtime. Please double check the input parameters.
[vost#0:0/h264_qsv @ 0x55cf63a6bdc0] Error initializing output stream: Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[aac @ 0x55cf63a76a80] Qavg: 55872.289
[aac @ 0x55cf63a76a80] 2 frames left in the queue on closing
Conversion failed!
ffmpeg command:
/usr/lib/jellyfin-ffmpeg/ffmpeg -hwaccel qsv -hwaccel_output_format qsv -vcodec hevc_qsv -i "/downloads/Family Guy (1999) - S20E10 - Christmas Crime [WEBRip-1080p].mkv" -vcodec h264_qsv -map 0:0 -metadata:s:v title=FHD -metadata:s:v handler_name=FHD -global_quality 18 -profile:v high -tag:v avc1 -look_ahead 0 -c:a:0 ac3 -map 0:1 -ac:a:0 6 -b:a:0 768k -metadata:s:a:0 BPS=768000 -metadata:s:a:0 BPS-eng=768000 -metadata:s:a:0 "title=5.1 Channel" -metadata:s:a:0 "handler_name=5.1 Channel" -metadata:s:a:0 language=eng -disposition:a:0 -default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions -c:a:1 copy -map 0:1 -metadata:s:a:1 "title=5.1 Channel" -metadata:s:a:1 "handler_name=5.1 Channel" -metadata:s:a:1 language=eng -disposition:a:1 -default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions -c:a:2 aac -map 0:1 -ac:a:2 2 -b:a:2 256k -metadata:s:a:2 BPS=256000 -metadata:s:a:2 BPS-eng=256000 -filter:a:2 "pan=stereo|FL=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR=0.5*FC+0.707*FR+0.707*BR+0.5*LFE" -metadata:s:a:2 title=Stereo -metadata:s:a:2 handler_name=Stereo -metadata:s:a:2 language=eng -disposition:a:2 +default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions -strict experimental -f mp4 -threads 0 -metadata:g encoding_tool=SMA -y "/downloads/Family Guy (1999) - S20E10 - Christmas Crime [WEBRip-1080p].mp4"
pix_fmt=yuv420p
Incompatible pixel format 'yuv420p' for codec 'h264_qsv', auto-selecting format 'nv12'
Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scale_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
[aac @ 0x5640a2edfdc0] Qavg: 55872.289
[aac @ 0x5640a2edfdc0] 2 frames left in the queue on closing
Conversion failed!
ffmpeg command:
/usr/lib/jellyfin-ffmpeg/ffmpeg -hwaccel qsv -hwaccel_output_format qsv -vcodec hevc_qsv -i "/downloads/Family Guy (1999) - S20E10 - Christmas Crime [WEBRip-1080p].mkv" -vcodec h264_qsv -map 0:0 -pix_fmt yuv420p -metadata:s:v title=FHD -metadata:s:v handler_name=FHD -global_quality 18 -profile:v high -tag:v avc1 -look_ahead 0 -c:a:0 ac3 -map 0:1 -ac:a:0 6 -b:a:0 768k -metadata:s:a:0 BPS=768000 -metadata:s:a:0 BPS-eng=768000 -metadata:s:a:0 "title=5.1 Channel" -metadata:s:a:0 "handler_name=5.1 Channel" -metadata:s:a:0 language=eng -disposition:a:0 -default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions -c:a:1 copy -map 0:1 -metadata:s:a:1 "title=5.1 Channel" -metadata:s:a:1 "handler_name=5.1 Channel" -metadata:s:a:1 language=eng -disposition:a:1 -default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions -c:a:2 aac -map 0:1 -ac:a:2 2 -b:a:2 256k -metadata:s:a:2 BPS=256000 -metadata:s:a:2 BPS-eng=256000 -filter:a:2 "pan=stereo|FL=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR=0.5*FC+0.707*FR+0.707*BR+0.5*LFE" -metadata:s:a:2 title=Stereo -metadata:s:a:2 handler_name=Stereo -metadata:s:a:2 language=eng -disposition:a:2 +default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions -strict experimental -f mp4 -threads 0 -metadata:g encoding_tool=SMA -y "/downloads/Family Guy (1999) - S20E10 - Christmas Crime [WEBRip-1080p].mp4"
pix_fmt=nv12:
Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scale_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
[aac @ 0x55a70524edc0] Qavg: 55872.289
[aac @ 0x55a70524edc0] 2 frames left in the queue on closing
Conversion failed!
ffmpeg command:
/usr/lib/jellyfin-ffmpeg/ffmpeg -hwaccel qsv -hwaccel_output_format qsv -vcodec hevc_qsv -i "/downloads/Family Guy (1999) - S20E10 - Christmas Crime [WEBRip-1080p].mkv" -vcodec h264_qsv -map 0:0 -pix_fmt nv12 -metadata:s:v title=FHD -metadata:s:v handler_name=FHD -global_quality 18 -profile:v high -tag:v avc1 -look_ahead 0 -c:a:0 ac3 -map 0:1 -ac:a:0 6 -b:a:0 768k -metadata:s:a:0 BPS=768000 -metadata:s:a:0 BPS-eng=768000 -metadata:s:a:0 "title=5.1 Channel" -metadata:s:a:0 "handler_name=5.1 Channel" -metadata:s:a:0 language=eng -disposition:a:0 -default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions -c:a:1 copy -map 0:1 -metadata:s:a:1 "title=5.1 Channel" -metadata:s:a:1 "handler_name=5.1 Channel" -metadata:s:a:1 language=eng -disposition:a:1 -default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions -c:a:2 aac -map 0:1 -ac:a:2 2 -b:a:2 256k -metadata:s:a:2 BPS=256000 -metadata:s:a:2 BPS-eng=256000 -filter:a:2 "pan=stereo|FL=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR=0.5*FC+0.707*FR+0.707*BR+0.5*LFE" -metadata:s:a:2 title=Stereo -metadata:s:a:2 handler_name=Stereo -metadata:s:a:2 language=eng -disposition:a:2 +default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions -strict experimental -f mp4 -threads 0 -metadata:g encoding_tool=SMA -y "/downloads/Family Guy (1999) - S20E10 - Christmas Crime [WEBRip-1080p].mp4"
@mdhiggins any ideas what i could be doing wrong here?
Haven't had free time to work on this.
Could you post a sample of a working version of the command you're looking for and I'll try to tweak things to target that
this seems to work to convert 10bit HEVC to 8bit h264:
/usr/lib/jellyfin-ffmpeg/ffmpeg -loglevel 40 -hwaccel qsv -hwaccel_output_format qsv -c:v hevc_qsv -i input.mkv -vf 'scale_qsv=w=1920:h=1080:format=nv12' -c:v h264_qsv output.mp4
Hm so this command is not ideal because you're not specifying any sort of output format, you're just letting it pick defaults. What pix_fmt does this ultimately output? nv12 is just a transitional format so the final pix_fmt here would be out of user control. We would need to come up with a command that allows that to be specified otherwise we are forcing everyone to drop hdr
@mdhiggins I'm not really sure tbh, the command above is the only thing i could get to get quicksync working (as verified by intel_gpu_top). Are there any other pix_fmt i should try? I have an Intel® Celeron® G4900 Processor
(8th gen) that supports hevc decoding and encoding according to: https://www.intel.com/content/www/us/en/docs/onevpl/developer-reference-media-intel-hardware/1-0/overview.html#SUMMARY
What was the pix fmt that was created using your sample command? Should be able to pull this from ffprobe
@mdhiggins Here is the output for ffprobe. it looks like it is yuv420p
. According to https://github.com/jellyfin/jellyfin/issues/2046#issuecomment-558312305 it seems the pix_fmt option is not supported by h264_qsv
which is what we're seeing here where it's not taking yuv420p
when i set it as a pix_fmt option. This Jellyfin PR seemed to fix a lot of the 10bit hevc to 8bit h264 transcode issues. Maybe it might help solve the mystery around this: https://github.com/jellyfin/jellyfin/pull/2099
ffprobe version 6.0-Jellyfin Copyright (c) 2007-2023 the FFmpeg developers
built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04.1)
configuration: --prefix=/usr/lib/jellyfin-ffmpeg --target-os=linux --extra-version=Jellyfin --disable-doc --disable-ffplay --disable-ptx-compression --disable-static --disable-libxcb --disable-sdl2 --disable-xlib --enable-lto --enable-gpl --enable-version3 --enable-shared --enable-gmp --enable-gnutls --enable-chromaprint --enable-libdrm --enable-libass --enable-libfreetype --enable-libfribidi --enable-libfontconfig --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libopenmpt --enable-libdav1d --enable-libwebp --enable-libvpx --enable-libx264 --enable-libx265 --enable-libzvbi --enable-libzimg --enable-libfdk-aac --arch=amd64 --enable-libsvtav1 --enable-libshaderc --enable-libplacebo --enable-vulkan --enable-opencl --enable-vaapi --enable-amf --enable-libvpl --enable-ffnvcodec --enable-cuda --enable-cuda-llvm --enable-cuvid --enable-nvdec --enable-nvenc
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.3.100
Duration: 00:21:38.11, start: 0.000000, bitrate: 1053 kb/s
Chapters:
Chapter #0:0: start 0.000000, end 957.015000
Metadata:
title : Chapter 1
Chapter #0:1: start 957.015000, end 1209.022000
Metadata:
title : Chapter 2
Chapter #0:2: start 1209.022000, end 1298.112000
Metadata:
title : Chapter 3
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 660 kb/s, 23.98 fps, 23.98 tbr, 24k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc60.3.100 h264_qsv
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 6 channels, fltp, 387 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:2[0x3](eng): Data: bin_data (text / 0x74786574)
Metadata:
handler_name : SubtitleHandler
Unsupported codec with id 98314 for input stream 2
Pix_fmt should be supported and is included in the QSV documentation
https://trac.ffmpeg.org/wiki/Hardware/QuickSync
I'll see if I can find a solution
I'm seeing similar issues with NVENC :( I'm doing a similar thing - converting 10bit HDR HEVC => 8bit h264 - just using NVENC vs QSV.
I did a bunch of digging and experimentation... Trying different combinations of scaling filters, format filters, etc. The lowest-touch change I was able to come up with was:
scale_npp
to scale_cuda
(it appears scale_npp
doesn't have the ability to deal with p10le
)-vf scale_cuda=w=1920:h=1038:format=yuv420p,hwdownload
Like I said, I tried TONS of combinations such as hwdownloading, converting to nv12 or yuv420p, re-hwuploading, etc etc. But the above is the only thing that worked for my file.
a38aabb7f337b8f493c530b0aa59d2c867a0c829
Alright, so trying to find a way to implement this dynamically, that's my first attempt
I added a subclass of the nvenc for h265 that will override the default scaler to scale_cuda instead of scale_npp; so now if you configure your codecs to be either h265_nvenc_cuda or hevc_nvenc_cuda it will use that scaler
Now similar to how vaapi is handled I'm also reading and pulling the pix_fmt data from the settings and if that's specified it's including that in the filter using the sample filter string you provided.
I don't have any nvidia hardware readily available to test this on so let me know if it works. If it get close but you have to tweak the final ffmpeg command generated to get it to behave let me know and I can try and adjust
Open to suggestions too if you think there's a better way to implement this stuff; the hardware acceleration implementations have made this project quite the headache its hard to have a general solution that works for everyone
Edit: if we get this working I'll update the nvenc h264 classes as well
This is analgous (albeit re: conversions TO 265...) to a previous issue with pix-fmt...
I have used
pix-fmt =
and
filter = scale_qsv=format=p010
...leaving the pix-fmt emtpy
Sorry for jumping in here, but it looks like the error I'm getting with SMA and using cuda, cuvid is similar. This error only appears in SMA when I scale down to 720p "No such filter: 'scale_npp'"
Relevant sections of .ini file
[Converter] ffmpeg = /usr/bin/ffmpeg ffprobe = /usr/bin/ffprobe threads = 0 hwaccels = cuda, cuvid hwaccel-decoders = h264_cuvid hwdevices = hwaccel-output-format = cuda:cuda output-directory = /media/data1/work output-directory-space-ratio = 0.0 output-format = mp4 output-extension = mp4
[Video] codec = h264_nvenc, h264, x264 max-bitrate = 2800 bitrate-ratio = crf = -1 crf-profiles = preset = codec-parameters = dynamic-parameters = False max-width = 1280 profile = main max-level = 4.1 pix-fmt = yuv420p prioritize-source-pix-fmt = True filter = force-filter = False
[HDR] codec = pix-fmt = space = bt2020nc transfer = smpte2084 primaries = bt2020 preset = codec-parameters = filter = force-filter = False profile =
I can use the following direct ffmpeg command to scale to 720p using cuda without any errors. /usr/local/bin/ffmpeg -benchmark -hwaccel cuda -hwaccel_output_format cuda -i "input.1080p.WEB.h264.mkv" -vf scale_cuda=-2:720 -c:v h264_nvenc "output.720p.WEB.h264.mp4"
Describe the bug I'm trying to convert all videos to h264. but when converting hevc files i'm getting errors. I have hardware decoding and encoding working by using the following ffmpeg command:
Command or context you are trying to run
./automator/manual.py -a -nd -i input.mkv
autoProcess.ini settings
Log files
FFMpeg headers
System Information
Expected behavior
hevc_qsv
is used for decoding andh264_qsv
is used for encodingAdditional context I have it working with the following ffmpeg command: