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

Quicksync issues on Alder Lake 12th generation CPU. #378

Open
TheSashmo opened this issue Apr 1, 2024 · 11 comments
Open

Quicksync issues on Alder Lake 12th generation CPU. #378

TheSashmo opened this issue Apr 1, 2024 · 11 comments
Assignees

Comments

@TheSashmo
Copy link

So I have been playing around with ultra grid for a while, and I have never been able to get quicksync working correctly.

I decided to splurge and get a CPU that is newer, so now I have 12th Gen Intel(R) Core(TM) i7-1255U.

I've been testing on the latest release, and can confirm that I can get quicksync running correctly in interlaced only. I am able to get interlaced video working correctly and get proper encode and decode 150 Frames of video every 5 seconds in h.264

But when I try to use HEVC in interlaced mode, the encoding seems to work fine, but the decode is throwing tons of errors:

[lavc hevc @ 0x7fddf400fa00] CABAC_MAX_BIN : 7
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta 1094995529 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta 50 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta -31 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta -40 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta 39 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta -31 is outside the valid range [-26, 25].

Second issue is that I can not get h.264 or HEVC to encode at 300 frames every 5 seconds which would be the amount of frames needed for 59.94 progressive video encoding.

Screenshot 2024-04-01 at 3 09 37 PM

It seems like there is enough power to handle it, but it just cant get there.

My goal is to be able to encode and decode up to 1080p H264 and/or HEVC.

Here is the command for h.264:
./UltraGrid-1.9.1-x86_64.AppImage -t decklink:0 -s embedded -c libavcodec:encoder=h264_vaapi:bitrate=15000k --audio-codec=opus:sample_rate=48000:bitrate=256k --audio-capture-format channels=16 -m 1316 -P 10000 127.0.0.1 --control-port 1234

Here is the command for HEVC:
./UltraGrid-1.9.1-x86_64.AppImage -t decklink:0 -s embedded -c libavcodec:encoder=hevc_vaapi:bitrate=15000k --audio-codec=opus:sample_rate=48000:bitrate=256k --audio-capture-format channels=16 -m 1316 -P 10000 127.0.0.1 --control-port 1234

And in addtion to above, my hevc decode in either interlaced or progressive gives me this same output on the decode session:

[lavc hevc @ 0x7fddf400fa00] CABAC_MAX_BIN : 7
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta 1094995529 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta 50 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta -31 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta -40 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta 39 is outside the valid range [-26, 25].
[lavc hevc @ 0x7fddf400fa00] The cu_qp_delta -31 is outside the valid range [-26, 25].

@alatteri
Copy link

alatteri commented Apr 1, 2024

Hi @TheSashmo . I believe that vaapi and QSV are different.

Here are our parameters for HEVC_QSV using a NUC12+. You might need to install libvpl stuff, depending on what OS you are running. Ubuntu plays the best.

COMPRESSIONCODEC="hevc_qsv"
COMPRESSIONFRAMEDELAY="0"
HEVCQSVRC=":rc=qvbr"                    ##Rate Control Method [qvbr,vbr,cbr,cqp]
HEVCQSCQP=":cqp=20"                    ##Constant Quality Factor.  Best used in conjunction with rc=qvbr 

@TheSashmo
Copy link
Author

TheSashmo commented Apr 1, 2024

Thanks for such quick response @alatteri. See I tried that, but qsv would always throw errors. What method are you using to install drivers? Could it be because I am trying to run this as headless and server mode instead of desktop ubuntu?

Update. I made some progress, and it seems that I have to follow these instructions to make some progress:
https://dgpu-docs.intel.com/installation-guides/ubuntu/ubuntu-jammy-dc.html

But even when I try:
./UltraGrid-1.9.1-x86_64.AppImage -t decklink:0 -s embedded -c libavcodec:encoder=h264_qsv:bitrate=15000k --audio-codec=opus:sample_rate=48000:bitrate=256k --audio-capture-format channels=16 -m 1316 -P 10000 127.0.0.1 --control-port 1234

or

./UltraGrid-1.9.1-x86_64.AppImage -t decklink:0 -s embedded -c libavcodec:encoder=hevc_qsv:bitrate=15000k --audio-codec=opus:sample_rate=48000:bitrate=256k --audio-capture-format channels=16 -m 1316 -P 10000 127.0.0.1 --control-port 1234

I get similar errors for hevc and h264 respectively:
[lavc hevc_qsv @ 0x7f3da0113bc0] Error during set display handle
: device failed (-17)
[lavc] Could not open codec for pixel format yuyv422
[lavc] Setting bitrate to 15.0 Mbps.
[lavc] Setting codec parameter preset to medium
[lavc] Setting codec parameter scenario to livestreaming
[lavc] Setting codec parameter async_depth to 1
[lavc] Auto-enabling intra-refresh which may not be supported by HW decoders.
[lavc] Use ':disable_intra_refresh' or ':safe' to disable.
[lavc] Setting codec parameter int_ref_type to vertical
[lavc] Setting codec parameter int_ref_cycle_size to 20
[lavc] Auto-enabling interlaced DCT which may not be supported by HW decoders.
[lavc] Use ':disable_interlaced_dct' or ':safe' to disable.
[lavc] Setting thread count to 1, type: (other)

[lavc h264_qsv @ 0x7f71a80f0500] Error during set display handle
: device failed (-17)
[lavc] Could not open codec for pixel format nv12
[lavc] No direct decoder format for: v210. Trying to convert with swscale instead.
[lavc] Unable to find suitable pixel format for: v210.
[lavc] Using codec: H.264, encoder: h264_qsv
[lavc] Setting bitrate to 15.0 Mbps.
[lavc] Setting codec parameter preset to medium
[lavc] Setting codec parameter scenario to livestreaming
[lavc] Setting codec parameter async_depth to 1
[lavc] Auto-enabling intra-refresh which may not be supported by HW decoders.
[lavc] Use ':disable_intra_refresh' or ':safe' to disable.
[lavc] Setting codec parameter int_ref_type to vertical
[lavc] Setting codec parameter int_ref_cycle_size to 20
[lavc] Auto-enabling interlaced DCT which may not be supported by HW decoders.
[lavc] Use ':disable_interlaced_dct' or ':safe' to disable.
[lavc] Setting thread count to 1, type: (other)

@alatteri
Copy link

alatteri commented Apr 1, 2024

sudo apt-get install -y libvpl2 libmfx-gen1.2 intel-media-va-driver-non-free
sudo update-initramfs -u

Make sure to use ubuntu 22.04 LTS with the latest HWE kernel.

@alatteri
Copy link

alatteri commented Apr 1, 2024

also make sure the user running UG is added to the video, audio and render groups.

@TheSashmo
Copy link
Author

TheSashmo commented Apr 1, 2024

So looks like it needed the libmfx-gen1.2 and now it seems to work. At lease the qsv does now. The issue is almost the same. I tested both hevc and h264 in qsv. The h264 can't get up to 150 frames of interlaced in 5 seconds. Normally its about 147-148. Note that this is encoding and decoding on the same box at the same time.
Screenshot 2024-04-01 at 4 01 19 PM
Gpu usage looks fine.

When I try hevc, I get tons of errors on the decode:
[lavc hevc @ 0x7ff97413c580] Could not find ref with POC 8
[lavc hevc @ 0x7ff97413c580] Could not find ref with POC 7
[lavc hevc @ 0x7ff97413c580] Could not find ref with POC 8
[lavc hevc @ 0x7ff97413c580] Could not find ref with POC 14
[lavc hevc @ 0x7ff97413c580] Could not find ref with POC 13
[lavc hevc @ 0x7ff97413c580] Could not find ref with POC 14
[lavc hevc @ 0x7ff97413c580] Could not find ref with POC 4

I even tried to drop to 8 bit 420 and still can't get there.....

./UltraGrid-1.9.1-x86_64.AppImage -t decklink:0 -s embedded -c libavcodec:encoder=h264_qsv:bitrate=15000k:depth=8:subsampling=420 --audio-codec=opus:sample_rate=48000:bitrate=256k --audio-capture-format channels=16 -m 1316 -P 10000 127.0.0.1 --control-port 1234

@TheSashmo
Copy link
Author

Let me add some more confusion to the mix..... I used to use this command -t decklink:0::UYVY and -c libavcodec:encoder=libx264:bitrate=15000k:subsampling=420 to set 8 bit 420.

Now using the new error messages that I see in the console output I did this:

-c libavcodec:encoder=libx264:bitrate=15000k:depth=8:subsampling=420

And I can get 1080p and 1080i at 60 without an issue, where as with the inital example I could not get progressive at 60 to be consistent.

Have I been completely bleeping wrong this whole time?? Ideally I want to do 10bit 422 at P and I, but could live with 8 bit 420 as a back up solution not having to chase hardware encoding and decoding.

@alatteri
Copy link

alatteri commented Apr 1, 2024

HD 4:2:2 should be easily achievable with x264/x265 in software (CPU). There are less restrictions and it is better quality than hardware based encoders.

@TheSashmo
Copy link
Author

1080p 10 bit 4:2:2 just can't encode and decode on the same machine at the same time. If I switch to 8 bit I can do 1080p 4:2:2

@alatteri
Copy link

alatteri commented Apr 2, 2024

We tweak the OS (Ubuntu 22) to increase performance.

sysctl

# Increase the read-buffer space allocatable
net.ipv4.tcp_mem = 1000000 2000000 83886080
net.ipv4.tcp_rmem = 8192 4194394 83886080
net.ipv4.udp_mem = 8388608 12582912 83886080
net.core.rmem_default = 83886080
net.core.rmem_max = 83886080
net.core.netdev_max_backlog = 2000

# Increase the write-buffer-space allocatable
net.ipv4.tcp_wmem = 8192 4194394 83886080
net.ipv4.udp_wmem = 8388608 12582912 83886080
net.core.wmem_default = 83886080
net.core.wmem_max = 83886080

# intel gpu
dev.i915.perf_stream_paranoid=0

grub
mitigations=off cpufreq.default_governor=performance

MartinPulec added a commit that referenced this issue May 21, 2024
@MartinPulec
Copy link
Collaborator

MartinPulec commented May 21, 2024

But when I try to use HEVC in interlaced mode,

I'd strongly recommend deinterlacing the interlaced content before the HEVC compression (-F deinterlace). The point is, that HEVC doesn't have support interlacing so anytime there is a rapid movement, the compression complexity is high. Just for the reference, QuickSync also has a deinterlace filtrer, but it is not yet supported by UG.

Ideally I want to do 10bit 422 at P and I, but could live with 8 bit 420 as a back up solution not having to chase hardware encoding and decoding.

I've just tried uv -t testcard:c=v210:fps=60:patt=noise -c lavc:enc=hevc_qsv -d dummy and it worked, but it was just about the edge case, increasing the FPS causes the decoder drops (it certainly depends on the CPU performance, I've tried with i7-5960X)

ADDENDUM (2024-05-22): I can confirm that QSV-encoded HEVC doesn't use WPP threads, so that it is not decoded in parallel by the default FFmpeg HEVC decoder.

@MartinPulec MartinPulec self-assigned this May 23, 2024
@MartinPulec
Copy link
Collaborator

I've updated SW requirements for QSV.

From the development point of view, I believe that there is nothing that can be done further for this issue if I am not mistaken. The decoding is unfortunately single-threaded, maybe just the content complexity can be reduced by the deinterlacing[1]. Let me know, if you think that something can be improved.

[1] the deinterlacing can be also accelerated by QSV if needed (eg. here), but since it is the libavfilter, it is possible that the amount of development will be higher, so we won't perhaps do it for now.

MartinPulec added a commit that referenced this issue May 23, 2024
Print warning if decompress takes more than 66% of time per frame on
average - as the decompress is now written (synchronously), the whole
frame time is not available and the drops start earlier.

refer to GH-378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants