1

I'm using ffmpeg on my Raspberry Pi (running on Raspbian) to record a 5 seconds long video at 12 fps from my webcam. It's not the Raspberry Pi dedicated webcam, just a regular USB one. This is the command I use:

sudo ffmpeg -f video4linux2 -s 640x480 -r 12 -vframes 60 -i /dev/video0 /mnt/ramdisk/output.mp4

The outcome is fine, but the time it takes is unacceptable. For this tiny 5 seconds long 640x480 clip, it takes about 2 minutes to complete converting and everything. I understand that the Pi is not exactly a beast of a computer, but I think it really could do better. As you can see, I use a ram disk to eleminate the bottleneck of the SD card I/O, but even so, it's very slow.

Do you have any ideas on how to make this faster?

I know about streamer, it does a great job and it's very fast (the file is almost immediately available after the recording was finished), but unfortunately I could only get it to output avi format, which is not what I need. I need the recording to be either mp4 or mov format. I know that streamer can theoretically output mov, but I couldn't get it to do so.

So basically I need a solution that's able to record footage from /dev/video0 and output it in mp4 or mov format relatively fast.

4

Well, I found a pretty decent solution. I basically use both together. I think the reason why ffmpeg was so slow, is that it already starts encoding before the recording even finishes. So let's say, a couple of frames were captured from the webcam so far, and ffmpeg already starts encoding those. On a regular computer, this would mean that it finishes more quickly, because it does things simultaneously. On the Pi however, this is reason why it's so slow. The Pi does not have enough horsepower to record and encode at the same time, so things will get very slow. Maybe it runs out of ram, and has to use some swap space (which is terribly slow due to the SD card I/O). This also results in some dropped frames and stutter in the final outcome.

So the solution is to first record an avi file, which doesn't really require much encoding, it's very light on the CPU, therefore, it's done very quickly. Then after it's done, use ffmpeg to convert the file into mp4. This works very well! Here are the exact commands I use:

sudo streamer -q -c /dev/video0 -s 640x480 -f jpeg -t 60 -r 12 -j 75 -w 0 -o /mnt/ramdisk/tmp.avi

sudo ffmpeg -i /mnt/ramdisk/tmp.avi -preset ultrafast -crf 27 /mnt/ramdisk/output.mp4

I added some more options to ffmpeg to further speed up the process. The speed is quite acceptable now, and the outcome is smooth as well.

  • which settings / size did you use for /mnt/ramdisk ? – con Feb 12 '17 at 16:58
  • I can't remember, and sadly I don't have the source anymore either, since this is a really old project – adam10603 Feb 12 '17 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.