MPSoC VCU調試方法和調試流程


Author

Hank FU hankf@xilinx.com 2021-09-29

概要介紹

MPSoC VCU在很多產品中得到了應用。在不同產品的調試過程中,有一些共同的辦法。

首先看看Video子系統的簡單框圖,其中包含視頻輸入、編解碼、視頻輸出等模塊。視頻輸入模塊,硬件可能是HDMI-RX和FrmBufWrite; 軟件一般是Linux V4L2。編解碼模塊是VCU,配套的軟件是GStreamer,或者Ctrl-SW。視頻輸出模塊,硬件可能是HDMI-TX和FrmBufRead; 軟件一般是Linux DRM。

Video_Subsystem_Simple_Diagram

調試時,根據上述框圖,逐個檢查其中的模塊的輸入輸出。

視頻輸入模塊

檢查視頻輸入源

調試VCU時,首先檢查視頻輸入模塊的輸出是否正常。如果Linux V4L2管理視頻輸入模塊的硬件,則會創建Linux的media/video設備,可以使用工具media-ctl查看它們的信息。對於HDMI-Rx,可以看到有沒有連接源設備,視頻輸入源的分辨率、格式等。

#media-ctl -p -d /dev/media0 
 
Media controller API version 0.1.0
  
Media device information
------------------------
driver          xilinx-video
model           Xilinx Video Composite Device
serial
bus info
hw revision     0x0
driver version  0.0.0
  
Device topology
- entity 1: vcap_hdmi output 0 (1 pad, 1 link)
            type Node subtype V4L flags 0
            device node name /dev/video0
        pad0: Sink
                <- "a0000000.v_hdmi_rx_ss":0 [ENABLED]
  
- entity 5: a0000000.v_hdmi_rx_ss (1 pad, 1 link)
            type V4L2 subdev subtype Unknown flags 0
            device node name /dev/v4l-subdev0
        pad0: Source
                [fmt:RBG24/1920x1080 field:none]
                [dv.caps:BT.656/1120 min:0x0@25000000 max:4096x2160@297000000 stds:CEA-861,DMT,CVT,GTF caps:progressive,reduced-blanking,custom]
                [dv.detect:BT.656/1120 1920x1080p60 (2200x1125) stds:CEA-861 flags:CE-video]
                -> "vcap_hdmi output 0":0 [ENABLED]

抓取原始圖像

在確保視頻輸入源的工作正常、分辨率和格式正確后,可以再繼續使用yavta來抓取原始圖像,從而檢查圖像內容。

#yavta -n 3 -c10 -f UYVY -f UYVY -s 1920x1080 --skip 7 -F /dev/video0
Device /dev/video0 opened.
Device `vcap_hdmi output 0' on `platform:vcap_hdmi:0' is a video output (without mplanes)[63898.159475] xilinx-frmbuf a0010000.v_frmbuf_wr: Framebuffer not configured for fourcc 0x59565955
 device.
Video format set: UYVY (59565955) 1920x1080 field none[63898.173868] xilinx-frmbuf a0010000.v_frmbuf_wr: Framebuffer not configured for fourcc 0x59565955
, 1 planes:
 * Stride 3840, buffer size 4147200
Video format:[63898.188189] xilinx-frmbuf a0010000.v_frmbuf_wr: Framebuffer not configured for fourcc 0x59565955
 UYVY (59565955) 1920x1080 field none, 1 planes:
 * Stride 3840, buffer size 4147200
3 buffers requested.
length: 1 offset: 3444933696 timestamp type/source: mono/EoF
Buffer 0/0 mapped at address 0x7fa84b0000.
length: 1 offset: 3444933696 timestamp type/source: mono/EoF
Buffer 1/0 mapped at address 0x7fa80bb000.
length: 1 offset: 3444933696 timestamp type/source: mono/EoF
Buffer 2/0 mapped at address 0x7fa7cc6000.
Unable to start streaming: Invalid argument (22).
3 buffers released.

檢查原始圖像

接下來再使用YUV Player 或者 YUV Player github 分支 檢查原始圖像是否正確。需要根據圖像源,正確設置分辨率和YUV格式。如果圖像輪廓就時錯誤的,這表明Y數據就是錯誤的,或者分辨率的行寬是錯誤的,如果輪廓正確、顏色錯誤,這表明Y數據是對的,分辨率的高不對,或色彩格式不對。大塊的連續色彩錯誤,有可能是把Y數據,當成了UV數據。

Encoder

得到了正確的YUV數據后,繼續使用Encoder編碼。如果有問題,保存Encoder輸出的碼流,傳送到PC機上,使用FFMpeg檢查。首先可以使用ffplay播放,用肉眼觀察圖像。

Microsoft Windows [Version 10.0.18363.1801]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\prj>ffplay vcu_example.h265
ffplay version N-89369-g5a93a85fd0 Copyright (c) 2003-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      56.  4.100 / 56.  4.100
  libavcodec     58.  6.102 / 58.  6.102
  libavformat    58.  2.103 / 58.  2.103
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  6.100 /  7.  6.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
[hevc @ 000001b016710180] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, hevc, from 'vcu_example.h265':=    0KB sq=    0B f=0/0
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: hevc (Main), yuv420p(tv, unknown/bt709/unknown), 3840x2160, 45 fps, 45 tbr, 1200k tbn, 45 tbc
    nan M-V:    nan fd=   2 aq=    0KB vq=  844KB sq=    0B f=0/0

其次可以使用ffprobe導出碼流信息,查看各幀的類型和大小。

C:\prj>ffprobe vcu_example.h265 > vcu_example.h265.txt
ffprobe version N-89369-g5a93a85fd0 Copyright (c) 2007-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      56.  4.100 / 56.  4.100
  libavcodec     58.  6.102 / 58.  6.102
  libavformat    58.  2.103 / 58.  2.103
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  6.100 /  7.  6.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
[hevc @ 0000019dfe94cd80] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, hevc, from 'vcu_example.h265':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: hevc (Main), yuv420p(tv, unknown/bt709/unknown), 3840x2160, 45 fps, 45 tbr, 1200k tbn, 45 tbc

還可以使用ffmpeg把每一幀轉換成bmp圖片,仔細查看。

C:\prj>ffmpeg  -i vcu_example.h265  -frames 10 vcu_example.%04d.bmp
ffmpeg version N-89369-g5a93a85fd0 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      56.  4.100 / 56.  4.100
  libavcodec     58.  6.102 / 58.  6.102
  libavformat    58.  2.103 / 58.  2.103
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  6.100 /  7.  6.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
[hevc @ 000002bda8bd9880] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, hevc, from 'vcu_example.h265':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: hevc (Main), yuv420p(tv, unknown/bt709/unknown), 3840x2160, 45 fps, 45 tbr, 1200k tbn, 45 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> bmp (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'vcu_example.%04d.bmp':
  Metadata:
    encoder         : Lavf58.2.103
    Stream #0:0: Video: bmp, bgr24, 3840x2160, q=2-31, 200 kb/s, 45 fps, 45 tbn, 45 tbc
    Metadata:
      encoder         : Lavc58.6.102 bmp
frame=   10 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.22 bitrate=N/A speed=0.568x
video:243001kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

有問題時,再使用保存的YUV文件,使用xilinx發布的ctrlsw_encoder在ZCU106單板上編碼,對比效果。也可以試試Xilinx提供的配置文件。如果有區別,再對比實際代碼和xilinx發布的ctrlsw_encoder、配置文件的區別。

Decoder

檢查完encoder的輸出,再檢查decoder的輸出。ctrlsw_decoder默認輸出I420(YUV420)/I422(YUV422)格式的YUV輸出。如果需要,可以參考VCU Ctrl-SW 2020.2輸出 NV12 的 YUV 文件,使ctrlsw_decoder輸出NV12/NV16的文件。輸出后,也可以使用YUV Player 或者 YUV Player github 分支 檢查解碼后的YUV圖像是否正確。

圖像質量

如果圖像質量有問題,建議使用大的顯示器或電視機查看。顯示器或電視機要真實支持檢查的分辨率,在顯示中不能有縮放,避免縮放引起新的問題。也可以使用ffmpeg的下面命令,將碼流轉換為bmp圖片,一幀一幀查看。

C:\prj>ffmpeg  -i vcu_example.h265  -frames 10 vcu_example.%04d.bmp
ffmpeg version N-89369-g5a93a85fd0 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      56.  4.100 / 56.  4.100
  libavcodec     58.  6.102 / 58.  6.102
  libavformat    58.  2.103 / 58.  2.103
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  6.100 /  7.  6.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
[hevc @ 000001bb953e9880] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, hevc, from 'vcu_example.h265':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: hevc (Main), yuv420p(tv, unknown/bt709/unknown), 3840x2160, 45 fps, 45 tbr, 1200k tbn, 45 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> bmp (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'vcu_example.%04d.bmp':
  Metadata:
    encoder         : Lavf58.2.103
    Stream #0:0: Video: bmp, bgr24, 3840x2160, q=2-31, 200 kb/s, 45 fps, 45 tbn, 45 tbc
    Metadata:yo
      encoder         : Lavc58.6.102 bmp
frame=   10 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.22 bitrate=N/A speed=0.553x
video:243001kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

通常,增大碼率、減小QP值、使用VBR、使用跳幀等,可以優化圖像質量。

VCU性能

如果檢查VCU性能,建議使用實際視頻輸入輸出,因為文件操作有耗時內存拷貝。如果用文件,也一定要把文件放在Linux的ramdisk上,不能使用sd等存放。

測試性能時,千萬記住,不能使用軟件復制Video數據,包括Gstreamer的tee插件。

案例

使用VBR優化圖像質量

有項目反應圖像質量與參考的視頻有差距。拿到VCU編碼的視頻碼流和參考視頻碼流后,使用ffprobe分析,得到每一幀的大小。發現VCU的視頻碼流的I幀小於150KByte,而參考視頻碼流的視頻碼流的I幀有400KByte。建議使用VBR。應用VBR后,圖像質量明顯改善。

解決I幀小導致的圖像質量問題

有項目反應圖像質量與參考的視頻有差距。拿到VCU編碼的視頻碼流和參考視頻碼流后,使用ffprobe分析,得到每一幀的大小。發現VCU的視頻碼流的I幀大約時是180KByte,而參考視頻碼流的視頻碼流的I幀有1000KByte。該項目使用VBR后,I幀圖像也沒有增大。檢查VCU的配置,發現配置文件了有“MaxPictureSize = 1500”,相當於180KByte。建議客戶設置“MaxPictureSize = 20000”,或者移除這一條后,圖像質量明顯改善。MaxPictureSize用於限制幀編碼后的最大大小,目的是減少碼率波動,會限制I幀的質量。

建議

分析VCU的問題時,請提供VCU的視頻碼流、參考視頻碼流、原始碼流、配置文件。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM