Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 12 Next »

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

7z x gstreamer-1.22.9-patch.7z

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

cp ~/code/gstreamer1/gst1-plugins-bad/0001-webrtcdsp-Update-code-for-webrtc-audio-processing-1.patch ~/code/gstreamer/subprojects/gst-plugins-bad/
cp ~/code/gstreamer1/gst1-plugins-bad/0002-h264-parser-pts-add.patch ~/code/gstreamer/subprojects/gst-plugins-bad/
cd ~/code/gstreamer/subprojects/gst-plugins-bad
patch -p1 < 0001-webrtcdsp-Update-code-for-webrtc-audio-processing-1.patch
patch -p1 < 0002-h264-parser-pts-add.patch

cp ~/code/gstreamer1/gst1-plugins-good/0001-v4l2-codec-support.patch ~/code/gstreamer/subprojects/gst-plugins-good/
cp ~/code/gstreamer1/gst1-plugins-good/0002-support-jpeg-dec-4k.patch ~/code/gstreamer/subprojects/gst-plugins-good/
cp ~/code/gstreamer1/gst1-plugins-good/0003-fixed-get-v4l2-codec-failed.patch ~/code/gstreamer/subprojects/gst-plugins-good/
cp ~/code/gstreamer1/gst1-plugins-good/0004-add-options-for-IBBP-decoder.patch ~/code/gstreamer/subprojects/gst-plugins-good/
cp ~/code/gstreamer1/gst1-plugins-good/0005-fixed-rtsp-failed-with-v4l2codec.patch ~/code/gstreamer/subprojects/gst-plugins-good/
cp ~/code/gstreamer1/gst1-plugins-good/0006-add-dma-copy-options-to-hw-video-encode.patch ~/code/gstreamer/subprojects/gst-plugins-good/
cd ~/code/gstreamer/subprojects/gst-plugins-good
patch -p1 < 0001-v4l2-codec-support.patch
patch -p1 < 0002-support-jpeg-dec-4k.patch
patch -p1 < 0003-fixed-get-v4l2-codec-failed.patch
patch -p1 < 0004-add-options-for-IBBP-decoder.patch
patch -p1 < 0005-fixed-rtsp-failed-with-v4l2codec.patch
patch -p1 < 0006-add-dma-copy-options-to-hw-video-encode.patch

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

Configure:

cd ~/code/gstreamer
meson setup build --prefix=/home/sunplus/code/install-gstreamer -Dgpl=enabled
image-20240827-115611.png

Build:

ninja -C build

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

ninja -C build install

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.

cd ~/code/gstreamer
python3 gst-env.py
image-20240828-015850.png

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

gst-inspect-1.0 | grep v4l2
image-20240828-020211.png

6 . Running cmd example:

H.264 Encode

Fake live stream:

gst-launch-1.0 -v videotestsrc horizontal-speed=15 num_buffers=100  ! "video/x-raw,width=1920,height=1080,format=NV12,framerate=30/1" ! timeoverlay ! v4l2h264enc ! "video/x-h264,level=(string)4" ! filesink location=gstv4l2h264enc.h264

H.264 Decode

gst-launch-1.0 -v filesrc location=gstv4l2h264enc.h264 ! h264parse ! v4l2h264dec ! filesink location=gstv4l2h264dec.yuv

JPEG Encode

gst-launch-1.0 -v videotestsrc num_buffers=100 horizontal-speed=15 ! "video/x-raw,width=1920,height=1080,format=NV12" ! v4l2jpegenc ! filesink location=1080p.jpg

JPEG Decode

gst-launch-1.0 -v filesrc location=1080p.jpg ! jpegparse ! v4l2jpegdec ! "video/x-raw,colorimetry=bt601" ! filesink location=og_1080p.yuv

JPEG to MP4

gst-launch-1.0 -v filesrc location=1080p.jpg ! jpegdec ! videoconvert ! v4l2h264enc ! h264parse ! mp4mux ! filesink location=1080p.mp4

gst-launch-1.0 -v filesrc location=1080p.jpg ! jpegparse ! v4l2jpegdec ! videoconvert ! x264enc ! h264parse ! mp4mux ! filesink location=1080p.mp4

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

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,format=YUY2,framerate=30/1 ! videoconvert ! ximagesink
or
gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,format=YUY2,framerate=30/1 ! videoconvert ! glimagesink

7. Reference

Build gstreamer from source using Meson

  • No labels