Hey all, I’m trying to capture raw Bayer-pattern frames from multiple cameras on an embedded Linux board. I’ve got 6 cameras connected — they show up under /dev/video0 through /dev/video5. I need to grab a single raw frame from each one. My cameras are 1920x1080 sensors. What’s the best way to approach this? I’m a bit new to V4L2 on the command line.
Welcome! The first thing you’ll want is the v4l-utils package — it gives you v4l2-ctl which is the go-to tool for this kind of thing. Start there:
sudo apt install v4l-utils
Once that’s in place, we can walk through the capture command. Are all six cameras identical sensors?
Thanks for the quick reply. Yes, all six are the same sensor model. I ran the install — v4l-utils is now on the system. What’s the v4l2-ctl command I should use? I poked around the man page but there are a ton of options and I don’t want to mess up the pixel format.
Totally understandable, the man page is dense. Since you’re after raw Bayer data, you’ll want to use the RG10 pixel format (10-bit Bayer RGGB, which is common for these types of sensors). For a single camera, the command would be:
v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat='RG10' --stream-mmap --stream-count=1 --stream-to=image.raw
Breaking that down:
--set-fmt-videosets resolution and the raw Bayer format--stream-mmapuses memory-mapped streaming (generally more reliable)--stream-count=1grabs exactly one frame--stream-to=image.rawdumps the raw frame to a file
Give that a shot on /dev/video0 first and let me know what you get.
That worked perfectly on /dev/video0! I got a raw file — opened it up in a hex editor and I can see the Bayer pattern data. So now I need to do this for all 6 cameras. Should I just run the same command and swap out the device path each time? I assume I should use different output filenames so they don’t overwrite each other.
Exactly right. Just repeat the same v4l2-ctl invocation for each device node from /dev/video0 through /dev/video5, with a unique output filename per camera. In practice you can script it quickly:
for i in 0 1 2 3 4 5; do
v4l2-ctl -d /dev/video$i --set-fmt-video=width=1920,height=1080,pixelformat='RG10' --stream-mmap --stream-count=1 --stream-to=camera_${i}.raw
done
That’ll give you camera_0.raw through camera_5.raw, each containing a single 1920x1080 RG10 Bayer frame from the corresponding sensor. One thing to keep in mind — if any of the cameras are already in use by another process (like a preview daemon), v4l2-ctl will fail with a “device busy” error on that node. So you may want to make sure nothing else has them open before running the loop.
Just ran the loop — all six cameras captured without any errors. Output files are all the same size too (which makes sense since they’re identical sensors). Thanks for walking me through this step by step, really appreciate it. The RG10 format was the part I was most unsure about, so that clarification saved me a lot of trial and error.
Glad it all worked smoothly! And yeah, the pixel format is usually where people get stuck — V4L2 supports a huge number of formats and the fourcc codes aren’t always intuitive. For reference, if you ever need to verify what formats a particular camera actually supports, you can run:
v4l2-ctl -d /dev/video0 --list-formats-ext
That’ll dump all the resolutions and frame rates the sensor advertises. Handy when you’re working with an unfamiliar module. Good luck with the rest of your project!