ffmpeg - Continuously stream webcam to single .jpg file (overwrite)

17,045

Solution 1

It is possible to achieve what I wanted by using:

./mjpg_streamer -i "input_uvc.so -r 1280×1024 -d /dev/video0 -y" -o "output_http.so -p 8080 -w ./www"

...from within the mjpg_streamer's directory. It will do all the nasty work for you by displaying the stream in the browser when using the address: http://{IP-OF-THE-SERVER}:8080/ It's also light-weight enough to run on a Raspberry Pi.

Here is a good tutorial for setting it up.

Thanks for the help!

Solution 2

You can use the -update option:

ffmpeg -y -f v4l2 -i /dev/video0 -update 1 -r 1 output.jpg

From the image2 file muxer documentation:

-update number

If number is nonzero, the filename will always be interpreted as just a
filename, not a pattern, and this file will be continuously overwritten
with new images.
Share:
17,045
Germanunkol
Author by

Germanunkol

Updated on June 19, 2022

Comments

  • Germanunkol
    Germanunkol almost 2 years

    I have installed ffmpeg and mjpeg-streamer. The latter reads a .jpg file from /tmp/stream and outputs it via http onto a website, so I can stream whatever is in that folder through a web browser.

    I wrote a bash script that continuously captures a frame from the webcam and puts it in /tmp/stream:

    while true
    do
        ffmpeg -f video4linux2 -i /dev/v4l/by-id/usb-Microsoft_Microsoft_LifeCam_VX-5000-video-index0 -vframes 1 /tmp/stream/pic.jpg
    done
    

    This works great, but is very slow (~1 fps). In the hopes of speeding it up, I want to use a single ffmpeg command which continuously updates the .jpg at, let's say 10 fps. What I tried was the following:

    ffmpeg -f video4linux2 -r 10 -i /dev/v4l/by-id/usb-Microsoft_Microsoft_LifeCam_VX-5000-video-index0 /tmp/stream/pic.jpg
    

    However this - understandably - results in the error message:

    [image2 @ 0x1f6c0c0] Could not get frame filename number 2 from pattern '/tmp/stream/pic.jpg'
    av_interleaved_write_frame(): Input/output error
    

    ...because the output pattern is bad for a continuous stream of images.

    Is it possible to stream to just one jpg with ffmpeg?

    Thanks...