CESNET / UltraGrid

UltraGrid low-latency audio and video network transmission system
http://www.ultragrid.cz
Other
492 stars 53 forks source link

12G SDI RGB12bit crazy colors #248

Closed alatteri closed 1 year ago

alatteri commented 1 year ago

Hello,

I know there is some overlap with other discussions and issues, but those have several issues being tracked, and I want to have this as a separate issue.

When capturing with hevc_nvenc and 12G RGB 12bit (Full Range) SDI from BMD at UHD resolution, the color is crazy psycho.

RGB12bit (Full Range) 2K SDI is fine though, as is RGB10bit (Limited Range) UHD.

The problem with using RGB10bit is that our local monitoring (direct SDI) requires 12Bit to properly show Full Range.

I find it strange that 12bit 2K SDI (3G) is fine, but 12bit UHD SDI (12G) is not, as I would think the pixel encoding is the same.

See below screencaps.

12G RGB 4:4:4 12bit UHD Screen Shot 2022-09-10 at 4 03 00 PM

12G RGB 4:4:4 12bit 2K

Screen Shot 2022-09-10 at 4 04 16 PM

alatteri commented 1 year ago

also want to add that without specifying lavc-use-codec=yuv444p16le then the color is wrong at all resolutions.

[Decklink capture] Using codec: R10k
[DeckLink capture] Using limited range R10k as specified by BMD, use '--param bmd-r10k-full-range' to override.
Enable video input: 2160p23.98
[lavc] Using codec: H.265, encoder: hevc_nvenc
[lavc] Setting bitrate to 30.0 Mbps.
[lavc] Setting NVENC preset to p7.
[lavc] Selected pixfmt: gbrp16le

IMG_0626

[Decklink capture] Using codec: R12L
Enable video input: 2Kp24 DCI
[lavc] Using codec: H.265, encoder: hevc_nvenc
[lavc] Setting bitrate to 30.0 Mbps.
[lavc] Setting NVENC preset to p7.
[lavc] Selected pixfmt: gbrp16le

IMG_0627

mpiatka commented 1 year ago

Hello,

we are having trouble reproducing this. Could you please provide the following?

  1. Is the issue reproducible with testcard or only with the decklink input?
  2. What are the exact command line arguments on sender?
  3. Does this happen when running the receiver with just -d gl? If not, what are the exact arguments on the receiver?
  4. Are you running from AppImage (latest?), or did you compile ug yourself? If not AppImage, please provide the complete output of ffmpeg -version
  5. What GPU are you using? What OS (including version)? What is the version of the nvidia driver?
alatteri commented 1 year ago

1) Seems to be BMD only, and only UHD 12bit SDI. 2K 12bit SDI is fine. With hevc_nvenc, --param lavc-use-codec=yuv444p16le must be used or color is wrong at all resolutions

2) ./UltraGrid-continuous-x86_64.AppImage -t decklink -c libavcodec:encoder=hevc_nvenc --record cat export.20220916/00* > out.h265 ffmpeg -r 24000/1001 -i out.h265 -codec:v copy output2.mp4

 To eliminate that it is a display issue on the receiver I'm recording the frames and converting to mp4 that I can view in VLC.

3) AppImage - UltraGrid 1.7+ (tags/continuous rev d31d3300 built Aug 31 2022 14:54:17)

ffmpeg version git-2022-07-29-e0691eab Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
configuration: --enable-gpl --enable-nonfree --extra-cflags=-I/var/tmp/ffmpeg/bmd_sdk/Linux/include/ --extra-ldflags=-L/var/tmp/ffmpeg/bmd_sdk/Linux/include/ --enable-decklink --enable-nvenc --enable-cuvid --enable-libfdk-aac
libavutil      57. 30.100 / 57. 30.100
libavcodec     59. 39.100 / 59. 39.100
libavformat    59. 29.100 / 59. 29.100
libavdevice    59.  8.101 / 59.  8.101
libavfilter     8. 46.100 /  8. 46.100
libswscale      6.  8.101 /  6.  8.101
libswresample   4.  8.100 /  4.  8.100
libpostproc    56.  7.100 / 56.  7.100

4). NVIDIA T1000 Driver Version: 515.65.01 Ubuntu 22.04.1 LTS

MartinPulec commented 1 year ago

I am sorry but we were still not able to reproduce the issue capturing DeckLink 8K Pro and compressing with NV 1080 Ti. I think we need to decouple the problem from input signal. To do so, we've generated the signal with testcard + DeckLink output. Another 8K Pro input was used to capture (wired with a short SDI):

U.AppImage -t testcard:fps=23.98:pattern=uv_plane=0.5:size=3840x2160:codec=R12L -d decklink:device=0  # sig. generator
U.AppImage -t decklink:device=1 -c libavcodec:encoder=hevc_nvenc -d gl

The UV plane was displayed correctly, no need to use --param lavc-use-codec=yuv444p16le, although that worked as well. Tried also testcard patterns _uvplane=0.0, _uvplane=1.0, gradient, gradient2 and noise [1]. Would it be possible to check if the above works for you?

([1] noise would most likely not exhibit the problem, obviously)

alatteri commented 1 year ago

Please see the output of the testing using the above steps... Not sure what I should actually look like, but this seems wrong.

machineA-
 * DeckLink 4K Pro (P14421001)
     Firmware is up to date

./UltraGrid-continuous-x86_64.AppImage -t testcard:fps=23.98:pattern=uv_plane=0.5:size=3840x2160:codec=R12L -d decklink
sed: /tmp/.mount_UltraGbOHoFC/usr/lib/libselinux.so.1: no version information available (required by sed)
sed: /tmp/.mount_UltraGbOHoFC/usr/lib/libselinux.so.1: no version information available (required by sed)
stat: /tmp/.mount_UltraGbOHoFC/usr/lib/libselinux.so.1: no version information available (required by stat)
UltraGrid 1.7+ (tags/continuous rev 9bde4a99 built Sep 22 2022 14:56:10)

[Decklink display] Card number unset, using first found (see -d decklink:help)!
[Decklink display] Using low-latency mode. In case of problems, you can try '-d decklink:no-low-latency'.
[Decklink display] Using device DeckLink 4K Pro
[Decklink display] Setting output signal as progressive, see option "Use1080PsF" to use PsF or keep default.
[Decklink display] bmdDeckLinkConfigVideoOutputIdleOperation set to: 1818322529
Display initialized-decklink
[testcard] capture set to 3840x2160 @23.98p, codec R12L, bpp 4.5, pattern: uv_plane=0.5, audio off
Video capture initialized-testcard
Created new RTP session with SSRC 0x2d61e1b1.
[video dec.] New incoming video format detected: 3840x2160 @23.98p, codec R12L
[Decklink display] Selected mode: 2160p23.98
[Decklink display] Setting single link by default.
[video dec.] Successfully reconfigured display to 3840x2160 @23.98p, codec R12L
[decklink] 115 frames in 5.01433 seconds = 22.9343 FPS
SSRC 0x2d61e1b1: 445249/500992 packets received (88.8735%), 55743 lost, max loss 64
[testcard] 120 frames in 5.00331 seconds = 23.9841 FPS
[decklink] 120 frames in 5.00433 seconds = 23.9792 FPS
SSRC 0x2d61e1b1: 518226/518400 packets received (99.9664%), 174 lost, max loss 4
[testcard] 120 frames in 5.00417 seconds = 23.98 FPS
[decklink] 120 frames in 5.00475 seconds = 23.9772 FPS
SSRC 0x2d61e1b1: 518289/518400 packets received (99.9786%), 111 lost, max loss 4
[testcard] 120 frames in 5.00417 seconds = 23.98 FPS
Video dec stats (cumulative): 470 total / 470 disp / 0 drop / 153 corr / 0 missing.
Pbuf: total 3863017887/4044531328 packets received (95.51213%).
Exit
machineB-
 * DeckLink 8K Pro (G8709f060)
     Firmware is up to date

./UltraGrid-continuous-x86_64.AppImage -t decklink -c libavcodec:encoder=hevc_nvenc --record
sed: /tmp/.mount_UltraGAKndbP/usr/lib/libselinux.so.1: no version information available (required by sed)
sed: /tmp/.mount_UltraGAKndbP/usr/lib/libselinux.so.1: no version information available (required by sed)
stat: /tmp/.mount_UltraGAKndbP/usr/lib/libselinux.so.1: no version information available (required by stat)
UltraGrid 1.7+ (tags/continuous rev 9bde4a99 built Sep 22 2022 14:56:10)

Using export directory: ./export.20220922
Display initialized-none
[DeckLink] Auto-choosen device 0.
[Decklink capture] Using codec: UYVY
[DeckLink capture] Using device DeckLink 8K Pro (1)
[DeckLink capture] bmdDeckLinkConfigCapturePassThroughMode set to: 1885628787
The desired display mode is supported: 525i59.94 NTSC
[DeckLink capture] Enable video input: 525i59.94 NTSC
[DeckLink] Trying to autodetect format.
Video capture initialized-decklink
Created new RTP session with SSRC 0x7440c26b.
Frame received (#0) - No input signal detected
[Decklink capture] Format change detected (display mode, color space - RGB444, 12bit).
[Decklink capture] Detected 12-bit signal, use ":codec=UYVY" to enforce 8-bit capture (old behavior).
[Decklink capture] Using codec: R12L
[DeckLink capture] Enable video input: 2160p23.98
[lavc] Using codec: H.265, encoder: hevc_nvenc
[lavc] Setting bitrate to 31.8 Mbps.
[lavc] Setting NVENC preset to p7.
[lavc] Slice-based or external multithreading not available, encoding won't be parallel. You may select frame-based paralellism if needed.
[lavc] Selected pixfmt: gbrp16le

[lavc] Selected pixfmt has not 4:2:0 subsampling, which is usually not supported by hw. decoders
[decklink] 94 frames in 5.02904 seconds = 18.6914 FPS
[decklink] 120 frames in 5.00512 seconds = 23.9755 FPS
[decklink] 120 frames in 5.00508 seconds = 23.9757 FPS
Exit

nvenc.mp4.zip

alatteri commented 1 year ago

and here, using libx265, just results in black.

./UltraGrid-continuous-x86_64.AppImage -t decklink -c libavcodec:encoder=libx265 --record
UltraGrid 1.7+ (tags/continuous rev 9bde4a99 built Sep 22 2022 14:56:10)

Using export directory: ./export.20220922
Display initialized-none
[DeckLink] Auto-choosen device 0.
[Decklink capture] Using codec: UYVY
[DeckLink capture] Using device DeckLink 8K Pro (1)
[DeckLink capture] bmdDeckLinkConfigCapturePassThroughMode set to: 1885628787
The desired display mode is supported: 525i59.94 NTSC
[DeckLink capture] Enable video input: 525i59.94 NTSC
[DeckLink] Trying to autodetect format.
Video capture initialized-decklink
Created new RTP session with SSRC 0x55de05d6.
Frame received (#0) - No input signal detected
[Decklink capture] Format change detected (display mode, color space - RGB444, 12bit).
[Decklink capture] Detected 12-bit signal, use ":codec=UYVY" to enforce 8-bit capture (old behavior).
[Decklink capture] Using codec: R12L
[DeckLink capture] Enable video input: 2160p23.98
[lavc] Using codec: H.265, encoder: libx265
[lavc] Setting CRF to 22.00.
[lavc] Setting preset to ultrafast.
x265 [info]: HEVC encoder version 3.5+1-f0c1022b6
x265 [info]: build info [Linux][GCC 7.5.0][64 bit] 12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [warning]: halving the quality when psy-rd is enabled for 444 input. Setting cbQpOffset = 6 and crQpOffset = 6
x265 [warning]: Scenecut is disabled when Intra Refresh is enabled
x265 [warning]: Keyint value is very low.It leads to frequent intra refreshes, can be almost every frame.Prefered use case would be high keyint value or an API call to refresh when necessary
x265 [info]: Main 4:4:4 12 profile, Level-5 (Main tier)
x265 [info]: Thread pool created using 40 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 6 / wpp(68 rows)
x265 [info]: Coding QT: max CU size, min CU size : 32 / 16
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : dia / 57 / 0 / 2
x265 [info]: Cb/Cr QP Offset                     : 6 / 6
x265 [info]: Lookahead / bframes / badapt        : 0 / 0 / 0
x265 [info]: b-pyramid / weightp / weightb       : 0 / 0 / 0
x265 [info]: References / ref-limit  cu / depth  : 1 / off / off
x265 [info]: Rate Control / qCompress            : CRF-22.0 / 0.50
x265 [info]: tools: rd=2 psy-rd=2.00 early-skip rskip mode=1 tmvp cip
x265 [info]: tools: fast-intra strong-intra-smoothing lslices=8 deblock
[lavc] Selected pixfmt: gbrp12le
[lavc] Selected pixfmt has not 4:2:0 subsampling, which is usually not supported by hw. decoders
[decklink] 62 frames in 5.01003 seconds = 12.3752 FPS
[decklink] 95 frames in 5.00694 seconds = 18.9737 FPS
x265 [info]: frame I:      1, Avg QP:19.09  kb/s: 861666.30
x265 [info]: frame P:    170, Avg QP:25.21  kb/s: 31384.15
x265 [info]: consecutive B-frames: 100.0% 

encoded 171 frames in 9.96s (17.17 fps), 36239.61 kb/s, Avg QP:25.18
Exit

libx265.mp4.zip

alatteri commented 1 year ago

Here is libx265 forcing to R10k on input which does have picture:

./UltraGrid-continuous-x86_64.AppImage -t decklink:codec=R10k -c libavcodec:encoder=libx265 --param bmd-r10k-full-range --record
UltraGrid 1.7+ (tags/continuous rev 9bde4a99 built Sep 22 2022 14:56:10)

Display device   : none
Capture device   : decklink
Audio capture    : none
Audio playback   : none
MTU              : 1500 B
Video compression: libavcodec:encoder=libx265
Audio codec      : PCM
Network protocol : UltraGrid RTP
Audio FEC        : none
Video FEC        : none

Using export directory: ./export.20220922
Display initialized-none
[Decklink capture] Using codec: R10k
[DeckLink capture] Using device DeckLink 8K Pro (1)
[DeckLink capture] bmdDeckLinkConfigCapturePassThroughMode set to: 1885628787
The desired display mode is supported: 1080p23.98
[DeckLink capture] Enable video input: 1080p23.98
[DeckLink] Trying to autodetect format.
Video capture initialized-decklink
Created new RTP session with SSRC 0x08daf063.
Frame received (#0) - No input signal detected
[Decklink capture] Format change detected (display mode, color space - RGB444, 12bit).
[Decklink capture] Using codec: R10k
[DeckLink capture] Enable video input: 2160p23.98
[Decklink capture] Format change detected (color space - RGB444, 12bit).
[lavc] Using codec: H.265, encoder: libx265
[lavc] Setting CRF to 22.00.
[lavc] Setting preset to ultrafast.
x265 [info]: HEVC encoder version 3.5+1-f0c1022b6
x265 [info]: build info [Linux][GCC 7.5.0][64 bit] 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [warning]: halving the quality when psy-rd is enabled for 444 input. Setting cbQpOffset = 6 and crQpOffset = 6
x265 [warning]: Scenecut is disabled when Intra Refresh is enabled
x265 [warning]: Keyint value is very low.It leads to frequent intra refreshes, can be almost every frame.Prefered use case would be high keyint value or an API call to refresh when necessary
x265 [info]: Main 4:4:4 10 profile, Level-5 (Main tier)
x265 [info]: Thread pool created using 40 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 6 / wpp(68 rows)
x265 [info]: Coding QT: max CU size, min CU size : 32 / 16
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : dia / 57 / 0 / 2
x265 [info]: Cb/Cr QP Offset                     : 6 / 6
x265 [info]: Lookahead / bframes / badapt        : 0 / 0 / 0
x265 [info]: b-pyramid / weightp / weightb       : 0 / 0 / 0
x265 [info]: References / ref-limit  cu / depth  : 1 / off / off
x265 [info]: Rate Control / qCompress            : CRF-22.0 / 0.50
x265 [info]: tools: rd=2 psy-rd=2.00 early-skip rskip mode=1 tmvp cip
x265 [info]: tools: fast-intra strong-intra-smoothing lslices=8 deblock
[lavc] Selected pixfmt: gbrp10le
[lavc] Selected pixfmt has not 4:2:0 subsampling, which is usually not supported by hw. decoders
[decklink] 69 frames in 5.01847 seconds = 13.7492 FPS
[decklink] 96 frames in 5.00199 seconds = 19.1923 FPS
[decklink] 96 frames in 5.01325 seconds = 19.1492 FPS
x265 [info]: frame I:      1, Avg QP:19.09  kb/s: 861844.41
x265 [info]: frame P:    266, Avg QP:25.30  kb/s: 26664.94
x265 [info]: consecutive B-frames: 100.0% 

encoded 267 frames in 14.74s (18.12 fps), 29792.96 kb/s, Avg QP:25.28
Exit

libx265_r10k.mp4.zip

alatteri commented 1 year ago

OK... and here I'm forcing R10k --param bmd-r10k-full-range on both machines, and the result here looks correct. Unfortunately, this is not a usable configuration in the real world, as BMD SDK doesn't output Full Range in 10bit mode. Only way to get Full Range with the creative apps we use is to output 12bit SDI, which shows corrupt output in UG.

machineA:

./UltraGrid-continuous-x86_64.AppImage -t testcard:fps=23.98:pattern=uv_plane=0.5:size=3840x2160:codec=R10k -d decklink --param bmd-r10k-full-range

UltraGrid 1.7+ (tags/continuous rev 9bde4a99 built Sep 22 2022 14:56:10)

[Decklink display] Card number unset, using first found (see -d decklink:help)!
[Decklink display] Using low-latency mode. In case of problems, you can try '-d decklink:no-low-latency'.
[Decklink display] Using device DeckLink 4K Pro
[Decklink display] Setting output signal as progressive, see option "Use1080PsF" to use PsF or keep default.
[Decklink display] bmdDeckLinkConfigVideoOutputIdleOperation set to: 1818322529
Display initialized-decklink
[testcard] capture set to 3840x2160 @23.98p, codec R10k, bpp 4, pattern: uv_plane=0.5, audio off
Video capture initialized-testcard
Created new RTP session with SSRC 0x64032623.
[video dec.] New incoming video format detected: 3840x2160 @23.98p, codec R10k
[Decklink display] Selected mode: 2160p23.98
[Decklink display] Setting single link by default.
[video dec.] Successfully reconfigured display to 3840x2160 @23.98p, codec R10k
SSRC 0x64032623: 488284/500992 packets received (97.4634%), 12708 lost, max loss 64
[decklink] 116 frames in 5.0386 seconds = 23.0223 FPS
[testcard] 120 frames in 5.00316 seconds = 23.9849 FPS
SSRC 0x64032623: 518400/518400 packets received (100.0000%), 0 lost, max loss 0
[decklink] 120 frames in 5.00387 seconds = 23.9814 FPS
[testcard] 120 frames in 5.00417 seconds = 23.98 FPS
SSRC 0x64032623: 518400/518400 packets received (100.0000%), 0 lost, max loss 0
[decklink] 120 frames in 5.00424 seconds = 23.9797 FPS

machineB:

./UltraGrid-continuous-x86_64.AppImage -t decklink -c libavcodec:encoder=hevc_nvenc --param bmd-r10k-full-range --record 
UltraGrid 1.7+ (tags/continuous rev 9bde4a99 built Sep 22 2022 14:56:10)

Using export directory: ./export.20220922
Display initialized-none
[DeckLink] Auto-choosen device 0.
[Decklink capture] Using codec: UYVY
[DeckLink capture] Using device DeckLink 8K Pro (1)
[DeckLink capture] bmdDeckLinkConfigCapturePassThroughMode set to: 1885628787
The desired display mode is supported: 525i59.94 NTSC
[DeckLink capture] Enable video input: 525i59.94 NTSC
[DeckLink] Trying to autodetect format.
Video capture initialized-decklink
Created new RTP session with SSRC 0x7fba6e2b.
Frame received (#0) - No input signal detected
[Decklink capture] Format change detected (display mode, color space - RGB444, 10bit).
[Decklink capture] Detected 10-bit signal, use ":codec=UYVY" to enforce 8-bit capture (old behavior).
[Decklink capture] Using codec: R10k
[DeckLink capture] Enable video input: 2160p23.98
[lavc] Using codec: H.265, encoder: hevc_nvenc
[lavc] Setting bitrate to 31.8 Mbps.
[lavc] Setting NVENC preset to p7.
[lavc] Slice-based or external multithreading not available, encoding won't be parallel. You may select frame-based paralellism if needed.
[lavc] Selected pixfmt: gbrp16le
[lavc] Selected pixfmt has not 4:2:0 subsampling, which is usually not supported by hw. decoders
[decklink] 95 frames in 5.01526 seconds = 18.9422 FPS
[decklink] 120 frames in 5.00501 seconds = 23.976 FPS
Exit

nvenc_r10k_both.mp4.zip

alatteri commented 1 year ago

OK....so I did more testing and it is now clear that this issue is not related to UG or FFMPEG, but BMD itself. Not sure if this is hardware or their SDK. So here it is.

I installed BMD MediaExpress, which is their our capture/playout software. I output a UHD signal from Resolve and Flame, in both 12bit and 10bit format. 12bit was corrupt, 10bit was fine, and this is with their own app. See screenshots.

IMG_0652 IMG_0653

alatteri commented 1 year ago

I've heard back from BlackMagic tech support, they acknowledge the bug.

alatteri commented 1 year ago

From BMD: "The dev team is aware of the issue and currently working on a fix"

alatteri commented 1 year ago

BMD driver 12.4.1 this is still an issue

alatteri commented 1 year ago

This is still happening. I closed it because it is not really a bug in UG, but a flaw in BMD drivers.