ROCK 3A Camera streaming with RTSP

With the Zero 3E/W just around the corner, it’s a good idea to warm up on camera stuff before it launches.

Here are some basic instructions to stream video on Rock 3A, which i think will also work on Zero 3.
For the instructions, we are streaming video from the imx219 sensor without the tuning file.
The print screens are converted to jpeg to fit the size to upload the image.

  • Make sure the camera is detected

      rock@rock3a:~$ ls /dev/video*
      /dev/video0  /dev/video2  /dev/video4  /dev/video6  /dev/video8
      /dev/video1  /dev/video3  /dev/video5  /dev/video7
    
  • Check our Rock 3A IP which will be our server.

      rock@rock3a:~/rockchip/gstreamer$ ifconfig
      eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
              inet 192.168.254.187  netmask 255.255.0.0  broadcast 192.168.255.255
              inet6 fe80::8a6b:bf67:85ab:9985  prefixlen 64  scopeid 0x20<link>
              inet6 2804:7f4:322a:3049:261f:9a4d:3ddc:73bf  prefixlen 64  scopeid 0x0<global>
              inet6 2804:7f4:322a:3049:9d91:626d:6064:be1a  prefixlen 64  scopeid 0x0<global>
              inet6 2804:7f4:322a:3049:29d6:d7f5:acf2:27c8  prefixlen 64  scopeid 0x0<global>
              inet6 2804:7f4:322a:3049:f8f4:5c30:a607:a544  prefixlen 64  scopeid 0x0<global>
              ether 2e:76:74:ce:a4:6e  txqueuelen 1000  (Ethernet)
              RX packets 15737  bytes 1450280 (1.4 MB)
              RX errors 0  dropped 0  overruns 0  frame 0
              TX packets 3513  bytes 72985157 (72.9 MB)
              TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
              device interrupt 38  
    
      lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
              inet 127.0.0.1  netmask 255.0.0.0
              inet6 ::1  prefixlen 128  scopeid 0x10<host>
              loop  txqueuelen 1000  (Local Loopback)
              RX packets 338  bytes 22652 (22.6 KB)
              RX errors 0  dropped 0  overruns 0  frame 0
              TX packets 338  bytes 22652 (22.6 KB)
              TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
      wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
              ether 18:93:7f:b3:d9:e2  txqueuelen 1000  (Ethernet)
              RX packets 0  bytes 0 (0.0 B)
              RX errors 0  dropped 0  overruns 0  frame 0
              TX packets 2  bytes 240 (240.0 B)
              TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

Pre-requisites:

  • rockchip mpp and rga
  • gstreamer with rockchip rkmpp
  • imx219

Building gstreamer rtsp server

    rock@rock3a:~/rockchip/gstreamer$ mkdir rtsp-server
    rock@rock3a:~/rockchip/gstreamer$ cd rtsp-server/
    rock@rock3a:~/rockchip/gstreamer/rtsp-server$ wget https://gstreamer.freedesktop.org/src/gst-rtsp-server/gst-rtsp-server-1.20.3.tar.xz
    rock@rock3a:~/rockchip/gstreamer/rtsp-server$ tar -xf gst-rtsp-server-1.20.3.tar.xz
    rock@rock3a:~/rockchip/gstreamer/rtsp-server$ cd gst-rtsp-server-1.20.3/
    rock@rock3a:~/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3$ mkdir build && cd build
    rock@rock3a:~/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/build$ meson --prefix=/usr --wrap-mode=nofallback -D buildtype=release -D package-origin=https://gstreamer.freedesktop.org/src/gstreamer/ -D package-name="GStreamer 1.20.3" ..
    The Meson build system
    Version: 0.61.2
    Source dir: /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3
    Build dir: /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/build
    Build type: native build
    Project name: gst-rtsp-server
    Project version: 1.20.3
    C compiler for the host machine: cc (gcc 11.4.0 "cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0")
    C linker for the host machine: cc ld.bfd 2.38
    Host machine cpu family: aarch64
    Host machine cpu: aarch64
    Compiler for C supports link arguments -Wl,-Bsymbolic-functions: YES 
    Compiler for C supports arguments -fvisibility=hidden: YES 
    Compiler for C supports arguments -fno-strict-aliasing: YES 
    Message: Disabling GLib cast checks
    Compiler for C supports arguments -Wmissing-declarations: YES 
    Compiler for C supports arguments -Wmissing-prototypes: YES 
    Compiler for C supports arguments -Wredundant-decls: YES 
    Compiler for C supports arguments -Wundef: YES 
    Compiler for C supports arguments -Wwrite-strings: YES 
    Compiler for C supports arguments -Wformat: YES 
    Compiler for C supports arguments -Wformat-nonliteral: YES 
    Compiler for C supports arguments -Wformat-security: YES 
    Compiler for C supports arguments -Wold-style-definition: YES 
    Compiler for C supports arguments -Waggregate-return: YES 
    Compiler for C supports arguments -Winit-self: YES 
    Compiler for C supports arguments -Wmissing-include-dirs: YES 
    Compiler for C supports arguments -Waddress: YES 
    Compiler for C supports arguments -Wno-multichar: YES 
    Compiler for C supports arguments -Wdeclaration-after-statement: YES 
    Compiler for C supports arguments -Wvla: YES 
    Compiler for C supports arguments -Wpointer-arith: YES 
    Found pkg-config: /usr/bin/pkg-config (0.29.2)
    Run-time dependency glib-2.0 found: YES 2.72.4
    Run-time dependency gstreamer-1.0 found: YES 1.20.3
    Run-time dependency gstreamer-rtsp-1.0 found: YES 1.20.1
    Run-time dependency gstreamer-rtp-1.0 found: YES 1.20.1
    Run-time dependency gstreamer-sdp-1.0 found: YES 1.20.1
    Run-time dependency gstreamer-app-1.0 found: YES 1.20.1
    Run-time dependency gstreamer-net-1.0 found: YES 1.20.3
    Run-time dependency gstreamer-check-1.0 found: YES 1.20.3
    Header <gst/gstconfig.h> has symbol "GST_DISABLE_GST_DEBUG" with dependency gstreamer-1.0: NO 
    Message: GStreamer debug system is enabled
    Program g-ir-scanner found: YES (/usr/bin/g-ir-scanner)
    Run-time dependency gobject-introspection-1.0 found: YES 1.72.0
    Dependency gobject-introspection-1.0 found: YES 1.72.0 (cached)
    Program g-ir-scanner found: YES (/usr/bin/g-ir-scanner)
    Dependency gobject-introspection-1.0 found: YES 1.72.0 (cached)
    Program g-ir-compiler found: YES (/usr/bin/g-ir-compiler)
    Run-time dependency gstreamer-plugins-base-1.0 found: YES 1.20.1
    Run-time dependency gstreamer-plugins-bad-1.0 found: YES 1.20.3
    Found CMake: /usr/bin/cmake (3.22.1)
    Run-time dependency libcgroup found: NO (tried pkgconfig and cmake)
    Program /usr/libexec/gstreamer-1.0/gst-plugins-doc-cache-generator found: NO
    ../docs/meson.build:50: WARNING: GStreamer plugin inspector for documentation not found, can't update the cache
    Program hotdoc found: NO
    Message: Hotdoc not found, not building the documentation
    Program scripts/extract-release-date-from-doap-file.py found: YES (/home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/scripts/extract-release-date-from-doap-file.py)
    Message: Package release date: 2022-06-15
    Configuring config.h using configuration
    Build targets in project: 41

    gst-rtsp-server 1.20.3

      User defined options
        buildtype     : release
        prefix        : /usr
        wrap_mode     : nofallback
        package-name  : GStreamer 1.20.3
        package-origin: https://gstreamer.freedesktop.org/src/gstreamer/

    Found ninja-1.10.1 at /usr/bin/ninja
    rock@rock3a:~/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/build$ ninja -j4
    [105/105] Linking target examples/test-video-rtx

Installing gstreamer rtsp-server:

rock@rock3a:~/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/build$ sudo ninja install
sudo ldconfig
[sudo] password for rock: 
[0/1] Installing files.
Installing gst/rtsp-server/libgstrtspserver-1.0.so.0.2003.0 to /usr/lib/aarch64-linux-gnu
Installing symlink pointing to libgstrtspserver-1.0.so.0.2003.0 to /usr/lib/aarch64-linux-gnu/libgstrtspserver-1.0.so.0
Installing symlink pointing to libgstrtspserver-1.0.so.0 to /usr/lib/aarch64-linux-gnu/libgstrtspserver-1.0.so
Installing gst/rtsp-server/GstRtspServer-1.0.gir to /usr/share/gir-1.0
Installing gst/rtsp-server/GstRtspServer-1.0.typelib to /usr/lib/aarch64-linux-gnu/girepository-1.0
Installing gst/rtsp-sink/libgstrtspclientsink.so to /usr/lib/aarch64-linux-gnu/gstreamer-1.0
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-auth.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-address-pool.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-context.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-params.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-sdp.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-thread-pool.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-media.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-media-factory.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-media-factory-uri.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-mount-points.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-permissions.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-stream.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-stream-transport.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-session.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-session-media.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-session-pool.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-token.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-client.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-server.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-server-object.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-server-prelude.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-onvif-server.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-onvif-client.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-onvif-media-factory.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/gst/rtsp-server/rtsp-onvif-media.h to /usr/include/gstreamer-1.0/gst/rtsp-server
Installing /home/rock/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/build/meson-private/gstreamer-rtsp-server-1.0.pc to /usr/lib/aarch64-linux-gnu/pkgconfig

Testing the rtsp-server:

rock@rock3a:~/rockchip/gstreamer/rtsp-server$ cd examples/
rock@rock3a:~/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/build/examples
rock@rock3a:~/rockchip/gstreamer/rtsp-server/gst-rtsp-server-1.20.3/build/examples$ sudo ./test-launch "( videotestsrc ! video/x-raw,format=NV12,width=1920,height=1080 ! mpph264enc ! rtph264pay name=pay0 pt=96 )"

From our PC box, we can check the result using ffplay, like so:

ffplay -rtsp_transport tcp rtsp://192.168.254.187:8554/test
ffplay version 3.4.11-0ubuntu0.1 Copyright (c) 2003-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, rtsp, from 'rtsp://192.168.254.187:8554/test': 0B f=0/0   
  Metadata:
    title           : Session streamed with GStreamer
    comment         : rtsp-server
  Duration: N/A, start: 0.199989, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 30 fps, 30 tbr, 90k tbn, 60 tbc
  73.39 M-V: -0.001 fd=  10 aq=    0KB vq=  309KB sq=    0B f=1/1   

If everything is all right we can see the stream:

Now we can stream the contents of the imx219 camera (1920x1080 h264):

sudo ./test-launch "( v4l2src device=/dev/video0 io-mode=dmabuf ! video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1 ! mpph264enc ! rtph264pay name=pay0 pt=96 )"

Here is the result:

As you can see, not perfect, there are some issues that can be resolved with the tunning file, like whitening and noise reduction but it is not as bad as the compressed image shown here (jpeg) and updated kernel.

1 Like