Fetch image from webcam

I want to fetch an image from a connected webcam. I’d rather avoid saving the image to disk. I know I can achieve this with VideoIO:

using Images
import VideoIO
f = VideoIO.opencamera("/dev/video1")
img = read(f)

But since I’m on a Linux machine with ffmpeg, I thought I’d pipe the output from a call to ffmpeg and get the data like that. For instance:

ffmpeg -f video4linux2 -s $res -i /dev/video1 -ss 0:0:2 -frames 1 -f image2 -

But how can I scoop up the output from a pipe call to ffmpeg and get the image data?


What I’ve done in a similar situation is have ffmpeg send a sequence of PNG images to the pipe, and then parse those from Julia. This requires PNG encoding/decoding of every frame, so not CPU efficient, but at least it is lossless. It also works in the other direction, sending frames to ffmpeg for encoding as a movie.

Code can be found here:

1 Like

Even better than I hoped for. Thanks!!!