...
Currently, the C3V Ubuntu rootfs has included the FFmpeg 4.4.4 prebuilt for version 20/22 and FFmpeg 6.1 for version 24 by default. It carries the commonly used elements and hardware media codec functions. 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.
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 that the provided does not meet your needs, you can recompile it as below.
...
Openh264 is a free software library for real-time encoding and decoding of video streams in the H.264/MPEG-4 AVC format. If You can do this step if you want to use it with the FFmpeg, you can do this step.
Get source code:
Code Block |
---|
mkdir code cd code git clone https://github.com/cisco/openh264.git |
...
4 . Apply code patch for supporting C3V codec
Patch The patch files are below. Please download files and copy files it to the root path of the FFmpeg ~/code folder extracted in step 3C3V rootfs.
View file | ||
---|---|---|
|
View file | ||
---|---|---|
|
View file | ||
---|---|---|
|
View file | ||
---|---|---|
|
View file | ||
---|---|---|
|
View file | ||
---|---|---|
|
Extract patch files: patch files will be extracted in ~/code/ffmpeg
Code Block |
---|
7z x ffmpeg-4.4.4-patch.7z |
Info |
---|
The patches in this document may not be up to date, if you are using the latest code of C3V, you can get the latest newest patch in the directory <C3V_PRJ>/linux/rootfs/initramfs/buildroot/package/ffmpeg directly. |
...
Code Block |
---|
cd ~/code/ffmpeg-4.4.4 patch -p1 < ../ffmpeg/0001-swscale-x86-yuv2rgb-Fix-build-without-SSSE3.patch patch -p1 < ../ffmpeg/0002-avcodec-vaapi_h264-skip-decode-if-pic-has-no-slices.patch patch -p1 < ../ffmpeg/0003-libavutil-Fix-mips-build.patch patch -p1 < ../ffmpeg/0004-configure-add-extralibs-to-extralibs_xxx.patch patch -p1 < ../ffmpeg/0005-Fixes-assembling-with-binutils-as-2.41.patch patch -p1 < ../ffmpeg/0006-v4l2-hw-codec-support.patch patch -p1 < 0006../ffmpeg/0007-v4l2-enc-add-spspps-to-each-idr.patch |
...
6 . Set environment variable to run ffmpeg FFmpeg
Because ffmpeg the FFmpeg install path is/home/sunplus/code/install-ffmpeg
, it needs to set LD_LIBRARY_PATH and PATH to execute ffmpegFFmpeg.
Code Block |
---|
export LD_LIBRARY_PATH=/home/sunplus/code/install-ffmpeg/lib:/usr/local/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH export PATH=/home/sunplus/code/install-ffmpeg/bin:$PATH |
7 . Running cmd example:
Encode the video frame of the webcam to be an H264 video file.
I use logitech the Logitech c270 usb USB webcam. When it is plugged in the C3V usb USB port, you will see the video device in /dev.
In my case, the c270 usb USB webcam device is video0.
...
You can check the video format support list with “v4l-ctl” app. It can be installed by below command.
...
Code Block |
---|
v4l2-ctl --list-formats-ext --device /dev/video0 |
...
I choose to use YUYV422 640x480 30fps video format to be the encode encoded video source. Action The action command is below:
Code Block |
---|
ffmpeg -f v4l2 -input_format yuyv422 -framerate 30 -video_size 640x480 -i /dev/video0 -vcodec h264_v4l2m2m -vframes 100 output.h264 |
If you want to play the encode file “output.h264”, you can use the mplayer. It can be installed by the below command.
Code Block |
---|
sudp pat install mplayer |
...
You can also record video and separate the record file by time with fix fixed video length. Action The action command is below:
Code Block |
---|
ffmpeg -f v4l2 -input_format yuyv422 -framerate 30 -video_size 640x480 -i /dev/video0 -vcodec h264_v4l2m2m -spspps_to_idr 1 -f segment -segment_time 60 -map 0 -reset_timestamps 1 -strftime 1 -preset ultrafast -crf 23 output_%Y-%m-%d_%H:%M:%S.h264 |
Command 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.
...
Code Block |
---|
ffmpeg -benchmark -y -vcodec jpeg_v4l2m2m -i ffout_001.jpg -vframes 1 ffout_001.yuv |
7 . Other Version
The steps for installing FFmpeg 6.1 are the same as for FFmpeg 4.4.4, here is the patch for FFmpeg 6.1.
View file | ||
---|---|---|
|
Note |
---|
If you are using Ubuntu version 24, it is recommended to use FFmpeg 6.1, otherwise when installing some packages such as OpenCV via apt, it will download FFmpe 6.1 packages to replace the lower version already installed. |