/
Compile and install FFmpeg 4.4.4 for C3V codec in the C3V Ubuntu environment

Compile and install FFmpeg 4.4.4 for C3V codec in the C3V Ubuntu environment

Introductory

Currently, the C3V Ubuntu rootfs have included the FFmpeg 4.4.4 prebuilt for version 20.04/22.04 and FFmpeg 6.1.1 for version 24.04 by default. It carries the commonly used elements and hardware media codec functions. If you don’t want to use it, disable the install in the file <C3V_PRJ>/linux/rootfs/initramfs/build_disk.sh before running make config.

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


Compile and install FFmpeg to the target version 4.4.4 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 libmp3lame-dev libx264-dev libopus-dev libvpx-dev libssl-dev libfdk-aac-dev libv4l-dev sudo apt install -y nasm libsdl2-dev libxcb-xfixes0-dev libxcb-shm0-dev libsctp-dev libfdk-aac-dev liblz-dev liblzma-dev sudo pip3 install --upgrade meson

2 . Build and install Openh264 :

Openh264 is a free software library for real-time encoding and decoding of video streams in the H.264/MPEG-4 AVC format. You can do this step if you want to use it with the FFmpeg.

Get source code:

mkdir code cd code git clone https://github.com/cisco/openh264.git

Compile and install:

cd openh264 meson build --prefix=/usr sudo ninja -C build/ install

3 . Build FFmpeg and install it:

Gst source and extract it.

4 . Apply code patch for supporting C3V codec

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

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

The patches 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 directory <C3V_PRJ>/linux/rootfs/initramfs/buildroot/package/ffmpeg directly.

Apply patch

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

6 . Set environment variable to run FFmpeg

Because the FFmpeg install path is/home/sunplus/code/install-ffmpeg, it needs to set LD_LIBRARY_PATH and PATH to execute FFmpeg.

7 . Running cmd example:

Encode the video frame of the webcam to be an H264 video file.

I use the Logitech c270 USB webcam. When plugged in the C3V USB port, you will see the video device in /dev.

In my case, the c270 USB webcam device is video0.

image-20240826-105829.png

You can check the video format support list with “v4l-ctl” app. It can be installed by below command.

Check command is below:

image-20240826-110449.png

I use YUYV422 640x480 30fps video format to be the encoded video source. The action command is below:

If you want to play the encode file “output.h264”, you can use the mplayer. It can be installed by the below command.

Then output.h264 can be played by

You can also record video and separate the record file by time with fixed video length. The action command is below:

The command argument -spspps_to_idr 1 will automatically add SPS and PPS to the second and subsequent recorded video files to prevent playback issues.

Decode H.264 to YUV

JPEG Encode

JPEG Decode

7 . Other Version

The steps for installing FFmpeg 6.1.1 are the same as for FFmpeg 4.4.4, here is the patch for FFmpeg 6.1.1.

If you are using Ubuntu version 24.04, it is recommended to use FFmpeg 6.1.1, otherwise when installing some packages such as OpenCV via apt install, it will download FFmpe 6.1.1 packages to replace the lower version already installed.