簡體   English   中英

從支持 NV12 和 YUYV 的采集卡采集全范圍/無損 rgb 幀 output

[英]Capture full-range/lossless rgb frame from capture card that supports NV12 and YUYV output

我正在嘗試制作一個捕獲圖像的程序,然后我需要比較捕獲的圖像和我顯示的輸入數據,兩者都應該逐像素匹配

這是我的采集卡的詳細信息

$ v4l2-ctl --list-formats-ext -d /dev/video0

ioctl: VIDIOC_ENUM_FMT
        Type: Video Capture

        [0]: 'NV12' (Y/CbCr 4:2:0)
                Size: Discrete 3840x2160
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 2560x1440
                        Interval: Discrete 0.017s (60.000 fps)
                Size: Discrete 1920x1080
                        Interval: Discrete 0.017s (60.000 fps)
                Size: Discrete 1280x720
                        Interval: Discrete 0.017s (60.000 fps)
                Size: Discrete 640x480
                        Interval: Discrete 0.017s (60.000 fps)
        [1]: 'YUYV' (YUYV 4:2:2)
                Size: Discrete 2560x1440
                        Interval: Discrete 0.020s (50.000 fps)
                Size: Discrete 1920x1080
                        Interval: Discrete 0.017s (60.000 fps)
                Size: Discrete 1280x720
                        Interval: Discrete 0.017s (60.000 fps)
                Size: Discrete 640x480
                        Interval: Discrete 0.017s (60.000 fps)
        [2]: '' (30313050-0000-0010-8000-00aa003)
        [3]: '' (e436eb7e-524f-11ce-9f53-0020af0)

$ v4l2-ctl --all

Driver Info:
        Driver name      : uvcvideo
        Card type        : ITE HDMI 4K+ Bridge: ITE HDMI 4
        Bus info         : usb-0000:00:14.0-6
        Driver version   : 5.18.0
        Capabilities     : 0x84a00001
                Video Capture
                Metadata Capture
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps      : 0x04200001
                Video Capture
                Streaming
                Extended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
        Width/Height      : 1920/1080
        Pixel Format      : 'YUYV' (YUYV 4:2:2)
        Field             : None
        Bytes per Line    : 3840
        Size Image        : 4147200
        Colorspace        : sRGB
        Transfer Function : Rec. 709
        YCbCr/HSV Encoding: Rec. 709
        Quantization      : Default (maps to Limited Range)
        Flags             :
Crop Capability Video Capture:
        Bounds      : Left 0, Top 0, Width 1920, Height 1080
        Default     : Left 0, Top 0, Width 1920, Height 1080
        Pixel Aspect: 1/1
Selection Video Capture: crop_default, Left 0, Top 0, Width 1920, Height 1080, Flags:
Selection Video Capture: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags:
Streaming Parameters Video Capture:
        Capabilities     : timeperframe
        Frames per second: 60.000 (60/1)
        Read buffers     : 0


我嘗試過使用各種方法 opencv 但 ffmpeg 最接近

使用以下命令我可以獲得良好的結果但不是我想要的

ffmpeg -y -f v4l2 -pix_fmt NV12 -video_size 1920x1080 -i /dev/video0 -pix_fmt bgra -frames:v 10 webcam%03d.bmp

參考圖像

參考圖像的 RGB

拍攝圖像的 RGB

注意:- 我可以在 windows 上使用 Aforge 捕獲正常,但不能在 linux 上使用 ffmpeg 捕獲。想知道是否有人已經解決了這個問題。

提前致謝。

我們必須將輸入標記為帶有“TV Range”的BT.709

ffmpeg -y -f v4l2 -pix_fmt nv12 -video_size 1920x1080 -color_primaries bt709 -color_trc bt709 -colorspace bt709 -color_range tv -i /dev/video0 -pix_fmt bgra -frames:v 10 webcam%03d.bmp


將輸入顏色格式標記為 BT.709:

默認情況下,FFmpeg 采用BT.601顏色格式,而輸入視頻采用 BT.709 顏色格式,因此我們必須使用-color_primaries bt709 -color_trc bt709 -colorspace bt709將視頻標記為 BT.709。

當輸入顏色格式為BT.709,FFmpeg按BT.601格式轉換,結果是錯誤的output colors。


將范圍標記為“電視范圍”:
默認情況下 FFmpeg assumes 假設“有限范圍”(電視范圍),但我們可以添加-color_range tv來確定。

筆記:
“TV Range”適用於“Limited range”——Y顏色通道的范圍是[16, 235](U和V范圍是[16, 240])。
(與 YUV 范圍為 [0, 255] 的“完整范圍”或“PC 范圍”相對)。


為了重現問題,我們可能會使用合成視頻(而不是相機)。

創建參考圖像:
ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=1:duration=1 -pix_fmt bgra ref%03d.bmp

在 BT.709,“有限范圍”(電視范圍)中創建 NV12 原始幀:
ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=1:duration=1 -vf scale=out_color_matrix=bt709:out_range=tv -pix_fmt nv12 -f rawvideo in.nv12

在不標記顏色格式和范圍的情況下將原始幀轉換為 BMP(得到錯誤的顏色):
ffmpeg -y -f rawvideo -pix_fmt nv12 -video_size 192x108 -i in.nv12 -pix_fmt bgra -frames:v 1 wrong_colors_out%03d.bmp

通過標記顏色格式和范圍(獲得正確的顏色)將原始幀轉換為 BMP:
ffmpeg -y -f rawvideo -pix_fmt nv12 -video_size 192x108 -color_primaries bt709 -color_trc bt709 -colorspace bt709 -color_range tv -i in.nv12 -pix_fmt bgra -frames:v 1 out%03d.bmp


從左到右排列:
參考圖像,“錯誤的顏色”和“正確的顏色”:
在此處輸入圖像描述 在此處輸入圖像描述 在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM