I am reading an RTSP stream from a surveillance camera and want to use ffmpeg to create a snapshot of the camera as jpeg. Principally it works to create a snapshot.jpg using the -update 1 option, but if it happens (what it does very often) that the client application reads the file while ffmpeg writes to it, the image is displayed only partially.
Hence I want to use ffmpeg to capture more than 1 images in a kind of ring buffer, so I can access the image captured just before the current one and have also the last n images as short history.
Though ffmpeg allows to create a series of jpgs, this seems infinite. Is it possible to tell ffmpeg to create images in a file pattern like this:
pic1.jpg, pic2.jpg, pic3.jpg, pic4.jpg, pic5.jpg and after pic5.jpg to start over again using pic1.jpg etc. This way it could consume a stream continuously without filling up my drive. Unfortunately something like -update 5 seems not to work (ffmpeg simply exits).
Principally I can also let it run infinitely and clean up all files older than n seconds, but that would introduce additional overhead and is IMHO not really clean programming compared to ffmpeg using this kind of ring buffer approach.
Any help would be appreciated.
You have to use the segment muxer.
ffmpeg -i input -f segment -segment_time 0.0001 -segment_format singlejpeg -segment_wrap 5 pic%d.jpg