ffmpeg capture current frame and overwrite the image output file

后端 未结 4 1542
野趣味
野趣味 2021-02-07 16:13

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 t

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-07 16:45

    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:// -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:// -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:// -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:// -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.

    • Found in Audio Options Section

    -r < fps > : sets frame rate

    • Found in the Video Options Section
    • used as an output option is actually a a substitute for the fps filter

    leading to an alternate version :

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

    Hope it helps understand for possible further tweaking ;)

提交回复
热议问题