Compile and install Gstreamer 1.22.9 for C3V codec in C3V Ubuntu environment

Introductory

Currently, the C3V Ubuntu rootfs has included the GStreamer 1.22.9 prebuild by default. It carries the commonly used elements and hardware media codec functions. Users can use gst-inspect-1.0 to check the installed elements directly. If you don’t want to use it, you can disable the install in the file <C3V_PRJ>/linux/rootfs/initramfs/build_disk.sh before running make config.

To use hardware media codecs, please run the command chmod +777 /dev/video6* to change the video codec permissions, otherwise, the GStreamer will not find the v4l2 codec element.

In addition to some common plugins, the system also comes with RTSP and its test program, which allows users to test the H264 and JPEG hardware encoding capabilities with the following two commands:

//test V4L2 h264 encoder test-lanuch --gst-debug-level=1 "videotestsrc ! video/x-raw,width=1280,height=720 ! v4l2h264enc ! h264parse ! rtph264pay pt=96 name=pay0" //test V4L2 jpeg encode test-lanuch --gst-debug-level=1 "videotestsrc ! video/x-raw,width=1280,height=720 ! v4l2jpegenc ! jpegparse ! rtpjpegpay pt=26 name=pay0"

If successful, the screen can be viewed with the RTSP tool with the address rtsp://x.x.x.x:8554/test. The x.x.x.x is the IP address of your C3V board.

The test-lanuch is an RTSP test program provided by the GStreamer plugin gst-rtsp-server, its source code is in the examples directory.

The prebuilt GStreamer is in the path <C3V_PRJ>/linux/rootfs/initramfs/ubuntu/prebuilt-app-xxx. If your C3V system doesn’t have it or you feel that the provided GStreamer does not meet your needs, you can recompile one of the plugins or the entire GStreamer as below.


Compile and install Gstreamer to the target version 1.22.9 with C3V Codec supported:

1 . Install the building package

sudo apt update sudo apt install -y build-essential meson ninja-build python3-pip bison libglib2.0-dev flex git sudo apt install -y libx264-dev libgl-dev libjpeg-dev sudo apt install --reinstall libx11-dev libx11-xcb-dev libxext-dev libxrender-dev libxv-dev libxrandr-dev libxi-dev pip3 install --upgrade meson sudo pip3 install --upgrade meson

2 . Build GStreamer and install it:

Gst source and check out to be version 1.22.9

mkdir code cd ~/code git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git cd gstreamer git checkout -b 1.22.9 1.22.9

3 . Apply code patch for supporting C3V codec

Patch files are below. Please download and copy files to the root ~/code folder in C3V rootfs.

Extract patch files: patch files will be extracted in ~/code/gstreamer1

The patch package in this document may not be up to date, if you are using the latest code of C3V, you can get the newest patch in the subdirectories of <C3V_PRJ>/linux/rootfs/initramfs/buildroot/package/gstreamer1 directly.

Apply patch

4. Configure, build and install in prefix path “/home/sunplus/code/install-gstreamer"

Configure:

image-20240827-115611.png

Build:

Install: gstreamer install path is/home/sunplus/code/install-gstreamer

5 . Setting up a development environment while keeping the distribution package

You can use the gst-env tool to set the development environment for GStreamer.

image-20240828-015850.png

Check if V4L2 codec elements are created successfully: v4l2h264dec, v4l2h264enc, v4l2jpegdec, v4l2jpegenc

6 . Running cmd example:

H.264 Encode

Fake live stream:

H.264 Decode

JPEG Encode

JPEG Decode

JPEG to MP4

Show USB camera(/dev/video0) image with GUI interface

 

7. Reference

Build gstreamer from source using Meson