Quick Setup and Verification of Camera Streaming Environment on Embedded Linux

How can we quickly set up a camera streaming environment in an embedded Linux environment? This can be achieved using the combination of ffmpeg and mediamtx. For more information about the mediamtx tool, you can visit its official website at https://mediamtx.org/ and its open-source repository at https://github.com/bluenviron/mediamtx:

A ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS / MPEG-TS / RTP media server and media proxy that allows reading, publishing, proxying, recording, and playback of video and audio streams.

Currently, the mediamtx tool supports audio and video stream pushing and playback operations for protocols such as SRT, WebRTC, RTSP, RTMP, LL-HLS, MPEG-TS, and RTP. The corresponding versions of the mediamtx binary executable files for different platforms are available at https://github.com/bluenviron/mediamtx/releases, which saves us the trouble of compiling the source code.

Below is the verification process of how to use it in the RK3562 Buildroot Linux environment:

1. Simple Verification

Use the system image generated by compiling with the default configuration and flash it onto the board. Then execute the following operations on the board:

Transfer the downloaded mediamtx tool to the development board, and then execute the following command:

./mediamtx &ffmpeg -f v4l2 -input_format mjpeg -video_size 640x480 -i /dev/video36 -c:v libx264 -level 30 -f rtsp rtsp://0.0.0.0:8554/stream

From these two commands, we can see that mediamtx acts as the streaming server, while ffmpeg pushes the encoded stream to it, which then distributes it to the relevant clients. The above command indicates that the video source is from the /dev/video36 camera, which uses the v4l2 driver interface, with an input format of mjpeg, a resolution of 640×480, and encoded in x264 format, pushed to the local port 8554 (which is the streaming port connected to the mediamtx service) using the RTSP protocol.

After executing the above two commands on the board, you can then use a computer on the same local area network to open the link rtsp://192.168.200.200:8554/stream (where 192.168.200.200 is the IP address of the board, please modify according to actual conditions) with VLC player for real-time playback, displaying the image captured by the camera.

2. RK Hardware Encoding and Decoding Verification

From the above streaming command, we can see that the encoding is in the libx264 library video format (H264). To use RK’s hardware encoding to accelerate video encoding, the following steps can be taken:

1) Buildroot configuration for RKMPP hardware encoding and decoding ffmpeg

In Buildroot, to compile ffmpeg with RKMPP support, ensure the following configurations are enabled:

BR2_PACKAGE_X264=yBR2_PACKAGE_X265=yBR2_PACKAGE_FFMPEG=yBR2_PACKAGE_FFMPEG_GPL=yBR2_PACKAGE_FFMPEG_EXTRACONF="--enable-rkmpp --enable-version3 --enable-libdrm --enable-libx264 --enable-gpl"

2) Third-party ffmpeg with RKMPP support

Download the corresponding source code from https://github.com/nyanmisaka/ffmpeg-rockchip, and then compile it with the appropriate platform’s cross-compilation toolchain to create a runnable ffmpeg on the development board. The relevant commands are as follows:

git clone https://github.com/nyanmisaka/ffmpeg-rockchipcd ffmpeg-rockchipexport PATH=/home/guochongxin/bigger_disk/RK3562-SDK/buildroot/output/rockchip_rk3562/host/bin:$PATHln -s /home/guochongxin/bigger_disk/RK3562-SDK/buildroot/output/rockchip_rk3562/host/bin/pkg-config /home/guochongxin/bigger_disk/RK3562-SDK/buildroot/output/rockchip_rk3562/host/bin/aarch64-linux-pkg-config./configure --prefix=./ffmpeg_install --enable-cross-compile --arch=arm64 --target-os=linux --cross-prefix=aarch64-linux- --sysroot=/home/guochongxin/bigger_disk/RK3562-SDK/buildroot/output/rockchip_rk3562/host/aarch64-buildroot-linux-gnu/sysroot/ --enable-rkmpp --enable-version3 --enable-libdrm --enable-libx264 --enable-gplmakemake install

The above commands should be adjusted according to the actual configuration of the cross-compilation toolchain path (PATH environment variable) and sysroot path. Finally, copy all files generated in the ffmpeg_install directory under the current directory to the root filesystem of the board, or copy them to the corresponding directory of the SDK source code and repackage and flash them onto the board.

3) Verification

After processing the above two configuration methods (the second method will support more RKMPP encoding and decoding formats), we can use the following command on the board to push:

./mediamtx &ffmpeg -f v4l2 -input_format mjpeg -video_size 640x480 -i /dev/video36 -c:v h264_rkmpp -level 30 -f rtsp rtsp://0.0.0.0:8554/stream

As can be seen, the corresponding encoding format has changed from libx264 to h264_rkmpp. After running the above command on the board, similarly, a computer on the same local area network can open rtsp://192.168.200.200:8554/stream (where 192.168.200.200 is the IP address of the board, please modify according to actual conditions) for real-time playback, displaying the image captured by the camera.

Leave a Comment