Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active August 2, 2023 12:39
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/4508842 to your computer and use it in GitHub Desktop.
Save westonruter/4508842 to your computer and use it in GitHub Desktop.
Grab a snapshot from an RTSP video stream every 1 second.
#!/bin/bash
url='rtsp://10.0.1.10:554/video-stream'
avconv -i $url -r 1 -vsync 1 -qscale 1 -f image2 images%09d.jpg
@westonruter
Copy link
Author

@westonruter
Copy link
Author

The first few frames mostly come through properly, but then the images start to just have the two part of the image filled with the expected data and then about a quarter of the way down the data just repeats resulting in streaks/smudges all the way to the bottom. It's like the processor isn't able to keep up with the frames coming in on on the stream, and so it has to drop them and the result is corrupted images.

@westonruter
Copy link
Author

The stream is 720p (960x720) H.264 video.

@crdx
Copy link

crdx commented Oct 24, 2015

@westonruter I encounter this as well. Did you find a fix?

@bhasselbeck
Copy link

Same issue here. I'm using a Raspberry Pi, and I got debugging output saying that there were missing packets during the network transfer. I assume it's simply edging the processing strength of my Pi.

@mutrised
Copy link

Having the same issue, I found some more pieces of information.
The data loss might be due to UDP use, you could try to for use of TCP instead with the flag: -rtsp_transport tcp which should be put in first position into the command

@AnSieger
Copy link

AnSieger commented May 14, 2021

You can use ffmpeg instad of avconv. Works also.
If you want just one frame use -frames:v 1
Then you can create a cronjob an execute each X minutes/days ...
url='rtsp://192.168.1.51:554/12' ffmpeg -i $url -r 1 -vsync 1 -qscale 1 -frames:v 1 -f image2 images_$(date +%F_%H-%M-%S).jpg

@alfonsrv
Copy link

alfonsrv commented Mar 2, 2022

@AnSieger ffmpeg is way too slow for this kind of job. Takes around 6 seconds for each grab from what I have experienced.

@allComputableThings
Copy link

ffmpeg is way too slow for this kind of job. Takes around 6 seconds

Is that an ffmpeg issue or an RTSP issue?

@alfonsrv
Copy link

alfonsrv commented Mar 7, 2022

Is that an ffmpeg issue or an RTSP issue?

Most is probably protocol overhead and initial negotiation. I ended up using OpenCV for the task + additional motion detection.

Just dumped a Gist for reference here: https://gist.github.com/alfonsrv/a788f8781fb1616e81a6b9cebf1ea2fa

@ronaldDMAS
Copy link

Just dumped a Gist for reference here:

Do you have a command line example of use? I get name 'STREAM_URL' is not defined
Ronald

PS. I find that ffmpeg causes Fedora 33 to crash after a day (running it permanently) and Raspbian ffmpeg never gets a result (too old?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment