2

I am writing an app (running on ARM Ubuntu) that needs to be able to do image processing on the video stream from a webcam. The easiest way that I can get the data is through the output stream on a process, so I am planning to host a child process, run a command, and consume the output. My current plan is to use FFMPEG, but I can use any command-line tool that works on ARM. There are really two parts to my question:

  1. What FFMPEG (or other utility, if there is a better one) command do I need to use from the command line to get a stream of pixel data from a webcam?
  2. What format will the output be in (preferably just RGB data, no encodings or headers)? I am going to need to parse it in my app and need to know the encoding format.

Any information would be appreciated!

1

With FFmpeg and video4linux2, you can get almost any webcam input. Make sure to use a recent version of ffmpeg from the download page or by compiling yourself. Your camera frame sizes and framerates can be checked with:

v4l2-ctl --list-formats-ext

For example, if you found out what framerate and picture size your webcam delivers:

ffmpeg -f video4linux2 -r 25 -s 640x480 -i /dev/video0 \
-c:v rawvideo -f rawvideo -pix_fmt yuv420p -

This would capture 25fps video at 640×480 pixels from the camera at /dev/video0 and output raw YUV frames encoded with the YUV 4:2:0 planar pixel format to stdout. The rawvideo encoder and format takes care of that. There will be no headers.

What you can change here:

  • Set a different framerate or -size.

  • Here, the - at the end sends the data to stdout, but you can choose a file as well if you want to.

  • To see what other pixel formats are available, run ffmpeg -pix_fmts. Their byte order is explained on fourcc.org. If you really want RGB data (although I doubt this is the default your camera outputs), you can use -pix_fmt rgb24, for example.

7
  • Thanks! this is exactly what I was looking for. But shouldn't I see something in the terminal when I run it? I haven't tried it in my app yet, but shouldn't I see something? – Wasabi Fan Oct 1 '13 at 4:18
  • Yes, you should see something. If you don't get any output maybe it couldn't find the webcam. Depends on your setup – if you can paste the full uncut console output somewhere we could check. – slhck Oct 2 '13 at 17:41
  • Here's the output... not very exciting: pastebin.com/Z2hWV1uL – Wasabi Fan Oct 2 '13 at 23:07
  • I was able to capture a single image with a different utility, so I know the webcam works as /dev/video0 – Wasabi Fan Oct 2 '13 at 23:09
  • You're using a terribly outdated version of ffmpeg. As I mentioned in my post, please download a recent one. The one you have is actually not even from FFmpeg but a fork that released it under the wrong name. – slhck Oct 3 '13 at 5:55
-1

Definitely check out VLC's command line options. I'm not really familiar with it's output streams but I seem to have read that it could do pretty much what you're trying to do.

VLC homepage

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.