Ffmpeg captures the current frame and overwrites the output image file

I am trying to extract an image file from the RTSP stream URL every second (it can also run every 1 min) and overwrite this image file.

my code below works, but it is output to several jpg image 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 possibly bash scripts on Linux to overwrite the same image file while continuously extracting the image at a NOT high frequency, say 1 min or 10 seconds?

+5
source share
3 answers

The following command line should work for you.

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

To clarify a bit of 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 the output option -f image2, formats the output format in image2 format, as part of the multiplexing step.

  • Please note that in the ffmpeg file, if the output file name indicates the image format, the image2 multiplex will be used by default, so the command can be shortened to:

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

an image2 format animator expects a file name template, such as img%01d.jpg , to create a series of numbered files. If the update parameter is set to 1, the file name will be interpreted as just the file name, not the template, thereby overwriting the same file.

Using -r , set the frame rate, the video option works, but it generated a lot of me that listened to me.

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

So my version of the work team

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

For some reason, I do not yet know that the minimum frame rate that I can reach from my channel is 1/20 or 0.05.

There is also a thumbnail of a video filter that selects an image from a series of frames, but it is more intensively processed, so I would not recommend it.

Most of this and more I found on FFMpeg Online Documentation

Avconv

For those of you using avconv, this is very similar. They are, after all, the forks of what used to be a shared library. The documentation for AVconv image2 is here .

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

As Xianlin noted, there may be a couple of other interesting options:

-an : disables sound recording.

-r <fps>: sets the frame rate

leading to an alternative version:

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

Hope this helps to understand a possible further setup;)

+3
source

Take a snapshot from the RTSP video stream every 10 seconds.

 #!/bin/bash #fetch-snapshots.sh url='rtsp://IP_ADDRESS/live.sdp' avconv -i $url -r 0.1 -vsync 1 -qscale 1 -f image2 images%09d.jpg 

-r frame rate setting up to 0.1 frames per second (this equals 1 frame every 10 seconds). Thanks westonruter, see https://gist.github.com/westonruter/4508842

Also, watch FFMPEG: extracting 20 images from variable-length video

0
source

Source: https://habr.com/ru/post/1200573/


All Articles