CM5 Lite + CM5 IO BOARD - 4k Camera crashes

Hi guys.

I’m running the CLI Image (bookworm) on the CM5 Lite. One encoder core running, one defective (to be expected). Kernel version 6.1.43-15-rk2312, ISP version v02.04.00.

Hooked up the imx415 to my board, enabled the overlay, ran GStreamer with the following command (also tried io-mode=mmap):

gst-launch-1.0 -e \
  v4l2src device=/dev/video11 io-mode=dmabuf \
  ! 'video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1' \
  ! mpph265enc \
  ! h265parse config-interval=1 \
  ! queue \
  ! tcpserversink host=0.0.0.0 port=5000

The video is choppy as hell (~ 15 - 20 fps max, drops to 5 fps sometimes), and crashes after 30 seconds or so. This is not a bandwidth issue, local recording (mkv, mp4 etc) yields the exact same results. It’s also not a hardware issue - there are no mipi CRC errors reported, which would happen with a defective FFC cable/ connector.

GStreamer reports:

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
rga_api version 1.10.0_[9]
Redistribute latency...
Redistribute latency...
662:dst has not fd and address for render
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
../libs/gst/base/gstbasesrc.c(3132): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4)
Execution ended after 0:00:32.385796429
Setting pipeline to NULL ...
Freeing pipeline ...

And from dmesg:

radxa@radxa-cm5-io:~$ [ 1670.778345] rockchip-mipi-csi2 mipi0-csi2: stream on, src_sd: 000000005f399405, sd_name:rockchip-csi2-dphy0
[ 1670.778360] rockchip-mipi-csi2 mipi0-csi2: stream ON
[ 1674.979155] rockchip-mipi-csi2 mipi0-csi2: stream off, src_sd: 000000005f399405, sd_name:rockchip-csi2-dphy0
[ 1674.979246] rockchip-mipi-csi2 mipi0-csi2: stream OFF
[ 1677.763089] rockchip-mipi-csi2 mipi0-csi2: stream on, src_sd: 000000005f399405, sd_name:rockchip-csi2-dphy0
[ 1677.763173] rockchip-mipi-csi2 mipi0-csi2: stream ON
[ 1710.025028] rk_vcodec: mpp_translate_reg_address:1816: reg[ 12]: 0xffffffff fd -1 failed
[ 1710.025069] rk_vcodec: mpp_task_dump_mem_region:2003: --- dump task 0 mem region ---
[ 1710.025086] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  0]: 0x0000000010c00000, size 2fd000
[ 1710.025103] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  1]: 0x0000000010c00000, size 2fd000
[ 1710.025120] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  2]: 0x0000000010c00000, size 2fd000
[ 1710.025136] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  3]: 0x00000000fec00000, size 334000
[ 1710.025152] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  4]: 0x00000000fec00000, size 334000
[ 1710.025168] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  5]: 0x00000000ff800000, size 334000
[ 1710.025185] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  6]: 0x00000000ff800000, size 334000
[ 1710.025201] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  7]: 0x00000000ff7e0000, size d000
[ 1710.025217] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  8]: 0x00000000febe0000, size d000
[ 1710.025233] rk_vcodec: mpp_task_dump_mem_region:2008: reg[  9]: 0x00000000feb80000, size 22000
[ 1710.025249] rk_vcodec: mpp_task_dump_mem_region:2008: reg[ 10]: 0x00000000ff780000, size 22000
[ 1710.025272] rk_vcodec: mpp_process_task_default:614: alloc_task failed.
[ 1710.025291] rkvenc2_wait_result:2051: session 00000000a243c5d4 pending list is empty!
[ 1710.025308] rk_vcodec: mpp_msgs_wait:1612: session 15 wait result ret -5
[ 1710.048280] rockchip-mipi-csi2 mipi0-csi2: stream off, src_sd: 000000005f399405, sd_name:rockchip-csi2-dphy0
[ 1710.048293] rockchip-mipi-csi2 mipi0-csi2: stream OFF

I cannot for the life of me get this to stream for more than 60 seconds (usually around 30). The video quality is horrendous - the ISP does kick in, but to say there’s ghosting is like saying “water is somewhat wet”. And the noise is atrocious.

Not only does GStreamer crash, but more often than not, it crashes the whole system, with the only option being a power cycle.

While using GStreamer is definitely a plus, I do have some experience with rockchip’s sdk, so I’m not afraid of putting in some work. I wrote something that streamed mpegts over udp using libav and rkipc, in c, on a RV1103/1106.
But I do need to ask - is this SBC actually capable of doing 4k H265? Or is it something along the lines of “well, according to the datasheet… yeah, maybe, sometime in the future - but not supported right now.”?

EDIT: in the meantime, I’ve found several posts saying 4k camera + encoding used to work on 5.10 kernel. However, can’t find any image anywhere for my module.

@radxa I’d greatly appreciate any pointers or clarification you guys could give me.
Thank you kindly for your time!

I’ve tested 4K h264 and 4K h265 on my rk3582 with all cores enabled, but with the wifi driver compiled natively on kernel 6.1, which is somewhat broken (i mean my port). With my compiled driver, the board freezes after a few minutes of data streaming. Which does not seem to be your case.
With ethernet it works as it should.

I did the following experiment:
1 - Using Wifi and also ethernet
2 - Encoded 3840x2160 h265 30fps and pushed it to the internet in real-time
3 - Somewhere on the internet, using an Intel® Core™2 Duo CPU E8600 i rendered it on screen using gstreamer with software decoding h265. Not possible to use hw decoding on E8600 anyway.

The results i found:
a) Yes, with 2 cores it can encode 4k h265 30fps (most likely 25 fps i guess)
b) Latency started at 0.5 secs and increased with time
c) After a few minutes (2~3 min), a few artifacts appeared and increased with time.

With 1920x1080, zero latency, no issues at all.
Rockchip has pushed some fixes to h265 that i don’t have now.
IMHO, you need to play with the parameters like gop,rc,bps, and it looks like in my case is a software issue.

@ChenJaly @ken any idea? Maybe the SDK revision is too low?

I tried updating via rsetup - the camera no longer works reliably.

With the update applied, i get a flood of MIPI CRC errors (most of the time), one uncorrupted frame / 10 seconds. And the 3A service, although running, no longer works - dark image with only bright spots visible (such as lightbulbs, monitors etc.).

I’m going ro repeat myself, I dont expect you guys to debug GStreamer for me - i can use whatever works, including a c api. But, right now, the only documentation is “plug camera in, use gstreamer” and i have no clue whatsoever about what to do next.

I just updated with the latest mpp, 2 Mbps, and rendered the stream with hw decoding (radxa board), no latency, no artifacts.
My board has 4GB. Maybe you have 8GB, which could be a problem. 2 cores for encoding,
I get 27~33 fps, but if i write the raw h265 stream to a file, it gives me 25 fps., no matter what fps i try.

~/rockchip/ffmpeg/ffmpeg-rockchip/ffprobe -i video.h265 
mpp[39185]: mpp_platform: client 12 driver is not ready!
ffprobe version 8164ff7 Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 12 (Ubuntu 12.3.0-1ubuntu1~22.04)
  configuration: --prefix=/usr --disable-libopenh264 --disable-vaapi --disable-vdpau --disable-decoder=h264_v4l2m2m --disable-decoder=vp8_v4l2m2m --disable-decoder=mpeg2_v4l2m2m --disable-decoder=mpeg4_v4l2m2m --disable-libxvid --disable-libx264 --disable-libx265 --enable-rkmpp --enable-nonfree --enable-gpl --enable-version3 --enable-libmp3lame --enable-libpulse --enable-libv4l2 --enable-libdrm --enable-libxml2 --enable-librtmp --enable-libfreetype --enable-openssl --enable-opengl --enable-libopus --enable-libvorbis --disable-shared --enable-decoder='aac,ac3,flac' --disable-cuvid --enable-rkrga
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
Input #0, hevc, from 'video.h265':
  Duration: N/A, bitrate: N/A
  Stream #0:0: Video: hevc (Main), yuvj420p(pc), 3840x2160, 25 fps, 30 tbr, 1200k tbn

You can try @nyanmisaka tips for ffmpeg.

1 Like

What kernel version do you use?

I already built/ ran this:

GitHub - nyanmisaka/ffmpeg-rockchip: FFmpeg with async and zero-copy Rockchip MPP & RGA support

Had loads of issues. The 3A service no longer worked (dark image). Also got two ioctl errors (upon launching the process), so I had to set the video device to NV12 manually (ffmpeg left it at yuv).

By “board” do you mean the CM5 lite module or a 5a/b/c?
I think there’s some subtle issues with the Radxa CM5 image.

Thank you so much for trying to help!

Rock 5C-lite, which i suppose uses the same rk3582 as your CM5-lite, kernel 6.1.43.
If you would like me to build your code and test it here, feel free.

   total        used        free      shared  buff/cache   available
Mem:         3812928      214196     3421440       18472      177292     3536888
Swap:              0           0           0

2 cores, no errors.

root@rock5c-lite:/home/rock# find /sys/devices/platform/ -name f*.rkvenc-core
    /sys/devices/platform/fdbef000.iommu/iommu/fdbef000.iommu/devices/fdbe0000.rkvenc-core
    /sys/devices/platform/fdbe0000.rkvenc-core
    /sys/devices/platform/fdbd0000.rkvenc-core
    /sys/devices/platform/fdbdf000.iommu/iommu/fdbdf000.iommu/devices/fdbd0000.rkvenc-core
1 Like

Them there’s definitely something fishy going on, because what I’ve done was:

  1. Download the CLI image.
  2. Take a picture with the camera, just to confirm it’s actually working.
  3. Launch gstreamer via afore mentioned command
  4. watch as it crashes and burns after 30 seconds.

I’ve also tried going the ffmpeg route - built it, ran it, did test the encoders (as per the project’s wiki), verified the VPU kicks ass - it does.

But the video is garbage, because there’s no auto exposure. Without which, as you can imagine, the video is dark and … unusable.

I’m sure your setup works, and yes, the chips match - which leads me to believe there’s some difference/ missing patch in the CM5 CLI image.

Do you have the CLI image or the KDE one? Just checked, just to be sure. The KDE image behaves the same.

EDIT: I forgot to mention an important detail - gstreamer eats up > 3GB RAM. Which is a lot, considering it’s hardware encoding. I was monitoring the resources it eats up in a separate terminal, and at the 30 second mark, before crashing, my SoC was down to ~ 4 free GB. Before running gstreamer, I had way more than 7 GB available.

I’ll to update just MPP and maybe rebuild gstreamer.

I updated MPP. As soon as i updated it, gstreamer started lagging. bad. it was jumping from 00:00:00.1 to 00:00:23.1 … unsable. After, updated rga. After, updated the whole system. The camera basically stopped working at all. All I get (mostly) - crc errors. Needless to say, i didn’t even touch the camera.

[   41.000403] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.001047] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.001343] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.001817] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.001835] mipi0-csi2-hw ERR2:0x100 (ecc,vc: 0) 
[   41.002158] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.002617] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.003077] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.003529] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.003973] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.004423] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.004966] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.005395] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.005832] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.005989] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.006277] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.006788] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.007218] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.007662] mipi0-csi2-hw ERR1:0x10000000 (ecc2) 
[   41.008055] mipi0-csi2-hw ERR1:0x1000000 (crc,vc: 0) 

I am officially out of ideas.

Now i got what you meant by “4GB”.

Yes, my module has 8GB. Which Im beginning to suspect is the culprit.

I tried a video test source instead of the camera last night and lo and behold, clean output (including 4k), 25fps. So the encoder does work and GStreamer as well. At 1080p, it ate around 100MB.

I tried to disable RGA (via the environment variable), but no matter what I tried, gst always crashes after 32 seconds. I strongly suspect some 32 bit plugin/ library.

Now I’m torn. Im really reluctant, I already spent 200 bucks on something that does not work. Should I throw another 100 bucks at the problem and get the 4GB CM5 module? @radxa

Looks like an FPC issue, have a look here: 4K camera not working on ROCK5C

I don’t think so, the camera works without any single CRC error unless i update MPP or the whole system (via rsetup).

  1. The CRC errors only occur after a system update.
  2. Updating MPP results in a laggy gstreamer behavior, but 0 crc errors.

I always check dmesg and those ought to be reported there.

I’ve worked with MIPI for a long time and this is the absolute first time I’ve encountered this thing.

If you think the issue is related to max memory (I vaguely recall some RGA issues related to this), you can limit the max memory in kernel command line.

Edit /etc/kernel/cmdline and add mem=4G to it. Then run sudo u-boot-update and reboot. You should see your system booted with 4G memory now.

Already tried that yesterday.
Makes no difference.