# Fetch image from webcam

**URL:** <https://discourse.julialang.org/t/fetch-image-from-webcam/8463>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 18, 2018, 8:06pm UTC](https://discourse.julialang.org/t/fetch-image-from-webcam/8463 "2018-01-18T20:06:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [January 18, 2018, 8:06pm UTC](https://discourse.julialang.org/t/fetch-image-from-webcam/8463/1 "2018-01-18T20:06:12Z")

</div>

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`:

```julia
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:

```bash
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?

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [January 19, 2018, 1:31pm UTC](https://discourse.julialang.org/t/fetch-image-from-webcam/8463/2 "2018-01-19T13:31:28Z")

</div>

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:  
[https://github.com/perrutquist/FFmpegPipe.jl](https://github.com/perrutquist/FFmpegPipe.jl)

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [January 19, 2018, 1:57pm UTC](https://discourse.julialang.org/t/fetch-image-from-webcam/8463/3 "2018-01-19T13:57:29Z")

</div>

Even better than I hoped for. Thanks!!!
