experiment procedure
Install ffmpeg
sudo apt update
sudo apt install ffmpeg
Insert the USB camera, the corresponding device is /dev/video0, you need to update the kernel configuration and the USB mode of the device tree to host, refer to
ffmpeg parameter description
-f output format, use v4l2
-s resolution, too large will occupy too much CPU, it is recommended to keep it small
-r frame rate, needs to correspond to the camera support range
-vcodec encoding method
-i Path to the data input stream
-b:v video bitrate, default 1000k
-an no audio
-pix_fmt pixel format, needs to correspond to the camera support range, such as yuv420p, yuvj422p, mjpeg
-b:a audio bitrate
-vcodec libx264, convert to H264 encoding, you can check ffmpeg's codec support
-preset processing mode, ultrafast, superfast, veryfast, faster, fast, medium
Use the following command to record, the video file name is v1.mp4
ffmpeg -f v4l2 -s 432x240 -r 30 -vcodec mjpeg -i /dev/video0 -pix_fmt yuv420p -b:v 2000k -vcodec libx264 -preset veryfast -an v1.mp4
You need to use sudo privileges. The recording process is as shown above. When it ends, you can press the q key or Ctrl-C
The file name is v1.mp4
Open it and take a look
Video Explanation