ahmed mosad
Posts: 17
Joined: Sun Jun 03, 2018 10:41 pm

ffmpeg to record 30 FPS video from 2M camera

Sat Jul 13, 2019 1:35 pm

hello
i am facing problem with my raspberry pi , i am trying to record FULL HD 30FPS video from USB 2M camera by using ffmpeg , when i set FPS to 30 it ignore that and just keep record video with about 21FPS , i spent good time on that but i can not figure out where the problem , any body can help me please ?

bellow that command i use :
ffmpeg -f v4l2 r- 30 -c h264 -s 1920x1080 -itsoffset 0.5 -i /dev/video2 -t 30 -copyinkf -bufsize 3M -b:v 10M -c copy -g 10 xx.mp4

User avatar
HermannSW
Posts: 1383
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: ffmpeg to record 30 FPS video from 2M camera

Sat Jul 13, 2019 2:06 pm

Try "/dev/shm/xx.mp4" instead of "xx.mp4", if that is faster then SD card write is the bottleneck.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
jbeale
Posts: 3474
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: ffmpeg to record 30 FPS video from 2M camera

Sat Jul 13, 2019 2:35 pm

You don't mention which version of the Pi you have (Original Pi, Pi2, Pi3, Pi4)? Any of them are capable of handling the raw data rate of a compressed 1080p mp4 video just as a file transfer, but I believe that actually encoding such a video in real time at 30 fps requires the GPU hardware. At least, that is what happens with the official RPi camera that attaches with the flex cable and uses 'raspivid' to record. I don't know what image or video format your USB webcam delivers. It is possible that ffmpeg is trying to first decode whatever format the webcam provides, and then re-encode that to H.264 format, which is a lot of computation to try in realtime, especially if it is trying to do this all in software (ARM CPU, not GPU). If the USB camera is streaming a set of still images (eg JPEG or MJPEG or raw/uncompressed) there might even be a Pi USB bandwidth problem at 1080p/30 in addition to the compute limit.

I don't fully understand this thread https://www.raspberrypi.org/forums/view ... 8&t=199775 but it appears to make the claim that you need to take specific steps to make ffmpeg take advantage of the GPU (hardware acceleration) for video on the Pi hardware, instead of trying to make do with the CPU. Also, depending on source resolution and quality settings, even the GPU may not be enough to reach 30 fps:
FFMPEG: BENCHMARK RESULTS FOR MY SOURCE-BUILT VERSION ON THE RASPBERRY PI 3B+:

ENCODING HIGH-COMPLEXITY 30 FPS VIDEO FROM A 1920 X 1080 JPEG IMAGE SEQUENCE – SIGNIFICANT MOTION AND INTRAFRAME DETAIL – HIGH QUALITY SETTINGS:

Software-Based H.264 Encoding (CPU): 2.6 FPS (11.5 times slower than real time)
Hardware-Based H.264 Encoding (GPU): 6.3 FPS (4.8 times slower than real time)

from: https://www.raspberrypi.org/forums/view ... 8&t=199775

Return to “General discussion”