How to Achieve Dual Camera Recording with ffmpeg?
Command
1. The video recording was unsuccessful with the command ffmpeg -framerate 25 -f v4l2 -i /dev/video4 recording1.mp4 . According to the official ffmpeg documentation, -r and -framerate have the same function, but the actual test shows that they are different. -framerate is used to limit the input while -r is used to limit the output
2. Video can be recorded with the command ffmpeg -r 25 -f v4l2 -i /dev/video4 recording1.mp4 , but problems such as frame error and frame repetition will occur.
3. Use ffmpeg -f v4l2 -r 25 -thread_queue_size 128 -i /dev/video4 -vcodec libx264 -b:v 800k-preset ultrafast recording1.mp4 to achieve dual camera video recording at the same time.
Parameter Description:
⚫ -f Set the output format, the output format is v412 frame
(The commands found earlier all use the framework avfoundation, a full-featured framework for handling multimedia data on iOS, macOS, watchOS, and tvOS. The v412 framework used in this command is a framework for video device drivers in the Linux kernel, which provides a unified interface to the application layer and supports flexible expansion of various complex hardware).
⚫ -r Set frame rate, set frame rate to 25fbs.
⚫ -thread_queue_size
(The thread _ queue _ size is applied to the first input specified after it. The term "thread_queue_size" can be applied to all inputs and determines at the application level. How many packets from that input can be queued while waiting for ffmpeg to receive and process them on its main thread. A few capture devices, primarily dshow, use "rtbufsize" to store incoming frames while waiting for them to be transferred to the application-level queue for that input. These two options do not adjust the value of the other, so they should be set manually. The default is 8. Common Warnings: Thread message queue blocking; consider raising the thread_queue_size option (current value: 8). To solve this problem, the official explanation: This option sets the maximum number of packets queued when reading from a file or device. (In low-latency/high-rate real-time streams, packets may be dropped if they are not read in a timely manner; increasing this value prevents this.)
⚫ -i Set input stream, set input from video4
⚫ -vcodec Set the video encoder,(-vcodec and-codec:v equal in value)
Encoders are library files that implement a certain encoding format. Encoding and decoding of video/audio in a certain format can only be achieved if an encoder for that format is installed.
Here are some of FFmpeg's built-in video encoders.
- libx264: The most popular open source H.264 encoder
- NVENC: NVIDIA GPU-based H.264 encoder
- libx265: Open source HEVC encoder
- libvpx: Google's VP8 and VP9 encoders
- libaom:AV1 Encoder
⚫ -B:v Video bit rate
⚫ -preset specifies the output video quality, which will affect the file generation speed. The following values are available:
Ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placebo from fast to slow, the ultrafast transcoding rate is the fastest, and the video is often the most blurred.
⚫ recording1.mp4 Name and file type of the output videoYou can use ffmpeg-formats to get all the file types supported by ffmpeg, where the annotation before the file is as follows:
D.=Demuxing supported(Support for video/audio encapsulation)
.E=Muxing supported(Support decapsulation of video/audio)
Method:
Software:
⚫ Ubuntu:
1.Devepoment board networking
2. sudo apt-gat update upgrades apt-gat to the latest version (optional)
3. sudo apt-get install ffmpeg uses apt-gat to obtain ffmpeg
4. Enter relevant commands
Hardware:
Connect the Forlinx self-made analog camera module to support two cameras. Video4-7 are nodes generated by the TVIN, with the upper left corresponding to video7, lower left corresponding to video6, lower right corresponding to video5, and upper right corresponding to video4. Select according to the actual situation.