ffmpeg capture current frame and overwrite the image output file

37,954

Solution 1

Following command line should work for you.

ffmpeg -i rtsp://IP_ADDRESS/live.sdp -f image2 -updatefirst 1 img.jpg

Solution 2

To elaborate a bit on the already accepted answer from pragnesh,

FFmpeg

As stated in the ffmpeg documentation: ffmpeg command line options are specified as

ffmpeg [global_options] {[input_options] -i input_file} ... {[output_options] output_file} ...

So

ffmpeg -i rtsp://<rtsp_source_addr> -f image2 -update 1 img.jpg

Uses output option -f image2 , force output format to image2 format, as part of the muxer stage.

  • Note that in ffmpeg, if the output file name specifies an image format the image2 muxer will be used by default, so the command could be shortened to:

    ffmpeg -i rtsp://<rtsp_source_addr> -update 1 img.jpg

The image2 format muxer expects a filename pattern, such as img%01d.jpg to produce a sequentially numbered series of files. If the update option is set to 1, the filename will be interpreted as just a filename, not a pattern, thereby overwriting the same file.

Using the -r , set frame rate, video option works, but generated me a whole lot of dropping frame messages which was bugging me.

Thanks to another answer on the same topic, I found the fps Video Filter to do a better job.

So my version of the working command is

ffmpeg -i rtsp://<rtsp_source_addr> -vf fps=fps=1/20 -update 1 img.jpg

For some reason still unkown to me the minimum framerate I can achieve from my feed is 1/20 or 0.05.

There also exists the video filter thumbnail, which selects an image from a series of frames but this is more processing intensive and therefore I would not recommend it.

Most of this and more I found on the FFMpeg Online Documentation

AVconv

For those of you who use avconv it is very similar. They are after all forks of what was once a common library. The AVconv image2 documentation is found here.

avconv -i rtsp://<rtsp_source_addr> -vf fps=fps=1/20 -update 1 img.jpg

As Xianlin pointed out there may be a couple other interesting options to use:

-an : Disables audio recording.

-r < fps > : sets frame rate

leading to an alternate version :

avconv -i rtsp://<rtsp_source_addr> -r 1/20 -an -update 1 img.jpg

Hope it helps understand for possible further tweaking ;)

Solution 3

I couldn't get the option -update working to overwrite the .jpg. Doing some experiments resulted in a working solution (at least for me) with the option -y at the end (upper-case is not working). I also needed http:// instead of rstp:// for this camera.

ffmpeg -i http://xx:[email protected]:yyy/snapshot.cgi /tmp/Capture2.jpg -y

Share:
37,954
Xianlin
Author by

Xianlin

Updated on December 30, 2020

Comments

  • Xianlin
    Xianlin over 3 years

    I am trying to extract the image file from a RTSP stream url every second (could be every 1 min also) and overwrite this image file.

    my below code works but it outputs to multiple image jpg files: img1.jpg, img2.jpg, img3.jpg...

    ffmpeg -i rtsp://IP_ADDRESS/live.sdp -f image2 -r 1 img%01d.jpg
    

    How to use ffmpeg or perhaps bash scripts in Linux to overwrite the same image file while continuously extract the image at a NOT high frequecy, say 1 min or 10 sec?

  • Xianlin
    Xianlin almost 10 years
    so I will have 6 images within 60 seconds, how about I only have ONLY one image overwritten 6 times within 60 seconds? That's what I need.
  • Xianlin
    Xianlin almost 10 years
    This works for me and I added "-r 1/5" option to make it capture every 5 seconds.
  • Kokkie
    Kokkie almost 10 years
    Have you tried the option ‘-y (global)’ Overwrite output files without asking.
  • Xianlin
    Xianlin about 9 years
    to use avconv instead of ffmpeg, avconv -i rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k‌​.mov -r 1/20 -an -y -update 1 test.jpg
  • Pau Coma Ramirez
    Pau Coma Ramirez about 9 years
    According to the -r Video Options docs, -r option actually causes the fps filter to be inserted. so -vf fps=fps=1/20 should also do the same. But it is shorter with -r :) Also I don't think you need the -y ( Overwrite output files without asking) option as the -update 1 already knows it should overwrite. -an addition is an interesting one, which may reduce process guessing. Thanks for the comment I'll update the answer with avconv option.
  • Matias
    Matias almost 9 years
    @pragnesh How would yo do to save each screenshot in a different file?
  • chubao
    chubao over 5 years
    it seems updatefirst has been removed in ffmpeg version 4.X?
  • Sean Ferons
    Sean Ferons over 3 years
    As pointed out the -updatefirst option has been removed and no longer works. Use the -y option instead.