Taking still images from stream

For questions and discussion that is NOT (I repeat NOT) specific to a certain Operating System.
wvmarle
New Cone
New Cone
Posts: 3
Joined: 19 Feb 2016 14:51

Taking still images from stream

Postby wvmarle » 19 Feb 2016 15:47

Hi,

I'm looking for a way to take still images from a video stream on the command line, not capture the actual stream but just occasional frames.

Specifically: I have a web cam, which I want to use to create a time lapse video of plants growing, and in order to do this I want to take a photo every 5-10 minutes or so during daylight hours (that would be a cron job). Exact timing is not important. I'm not interested in the actual stream (way too much data; I'll have to record for 1-2 months), just a frame on a regular basis, saved to a specific directory, so later I can stitch them together to create a video.

This WiFi connected web cam streams at rtsp://user:password@IP-address:10554/tcp/av0_0 This stream I can see on the screen just fine using the VLC client. Of course I can then also take screen shots of the video manually. I assume capturing of the stream on the command line is easy, seen many references to that, but that's way too much data for me to handle.

Ideally: a single command that fires up VLC, connects to the web cam, takes a screen shot, and saves it.
Alternative: fire up VLC, capture and save a second or two of video before it quits again, take a single frame of that recorded video (the first would do), save the frame and delete the video.

Suggestions?

Ludrax
Big Cone-huna
Big Cone-huna
Posts: 568
Joined: 07 Jul 2010 14:28

Re: Taking still images from stream

Postby Ludrax » 19 Feb 2016 17:15

Specifically: I have a web cam, which I want to use to create a time lapse video of plants growing, and in order to do this I want to take a photo every 5-10 minutes or so during daylight hours (that would be a cron job).
that seems already requested :-|

viewtopic.php?f=13&t=125101
viewtopic.php?f=14&t=120783
viewtopic.php?f=2&t=127415
An' if ain't broke, then don't try to fix it...

wvmarle
New Cone
New Cone
Posts: 3
Joined: 19 Feb 2016 14:51

Re: Taking still images from stream

Postby wvmarle » 21 Feb 2016 06:16

Thanks!

Not surprised, really. I did try to search, but couldn't come up with working search terms to find those threads... But lack of response seems to show it can't be done...

wvmarle
New Cone
New Cone
Posts: 3
Joined: 19 Feb 2016 14:51

Re: Taking still images from stream

Postby wvmarle » 21 Feb 2016 14:55

After some serious searching I managed to find a solution with vlc, and after that an even better solution using ffmpeg. Hereby posting for others to use.

This method to take a single snapshot with vlc, and then exit:

Code: Select all

prefix=`date +"img-%Y-%m-%d_%H-%M-%S-"` cvlc rtsp://un:pw@ip:10554/tcp/av0_0 --video-filter=scene --scene-prefix=$prefix --scene-format=jpg --scene-path=./ --scene-ratio 240 --sout-x264-lookahead=10 --sout-x264-tune=stillimage --vout=dummy --run-time 15 vlc://quit
What it does:
- create a prefix with timestamp
- open cvlc (the command line version of vlc)
- connect to the rtsp stream (give complete URL for your camera - use the "open network stream" in VLC first to make sure you have a working stream, then copy/paste the URL)
- take snapshot of every 240 frames (10 seconds for my 24fps stream)
- run for 15 seconds, then quit
The 15 seconds as it takes about 11-12 seconds for VLC to connect to the camera and get the stream, so this script takes one snapshot for me.

Code: Select all

outfile=`date +"img-%Y-%m-%d_%H-%M-%S.jpg"` ffmpeg -loglevel fatal -rtsp_transport tcp -i "rtsp://un:pw@ip:10554/tcp/av0_0" -r 1 -vframes 1 $outfile
This is for me a much faster solution than using vlc, it takes a snapshot within a few seconds.
I found I had to add the "-rtsp_transport tcp" option, without it this doesn't work for me. Other examples on the net don't have this included, so you may need to tweak this for your camera.
Do provide a different file name for every snapshot, it does not automatically overwrite or add any kind of extension to it.

You can do the same with ffmpeg's successor, avconv. This also returns very fast for me.

Code: Select all

outfile=`date +"img-%Y-%m-%d_%H-%M-%S.jpg"` avconv -loglevel fatal -rtsp_transport tcp -i "rtsp://un:pw@ip:10554/tcp/av0_0" -r 1 -vframes 1 $outfile

Ludrax
Big Cone-huna
Big Cone-huna
Posts: 568
Joined: 07 Jul 2010 14:28

State of Confusion: Taking still images from stream

Postby Ludrax » 21 Feb 2016 21:00

You can do the same with ffmpeg's successor, avconv. This also returns very fast for me.
maybe counterpart is better suited :-|
An' if ain't broke, then don't try to fix it...

oystro
New Cone
New Cone
Posts: 1
Joined: 01 Dec 2017 22:29

Re: Taking still images from stream

Postby oystro » 01 Dec 2017 22:33

Hi.
How do you run this script?
I would like a task scheduled in Windows planed tasks on one of our server to take a snapshot every hour.
Can someone guide me through that. We have an Vivotek camera that support rtsp streaming.

Thank you in advance?


Return to “General VLC media player Troubleshooting”

Who is online

Users browsing this forum: No registered users and 148 guests