Security camera timelapse
Timelapse can be a great way to express yourself. But it is also a good way to compress time. To show the whole day in just a few seconds. Since there is a construction site next to my office, I wanted to record the works and show them as a simple timelapse.
I don’t want to use expensive equipment. I bought a simple security camera, placed it outside, and started recording. As for the recording software, I simply used FFmpeg. The tricky thing was to find the address of the RTSP stream. The camera IP I found on the router DHCP clients list, and the RTSP address I found using Google (RTSP + my camera type).
Once I gathered the required information, I prepared a simple Linux script:
timenow = 'date +%Y%m%d-%H%M%S' ffmpeg -y -i rtsp://user_name:[email protected]:554//h264Preview_01_main -vframes 1 img-${timenow}.jpg
Let’s take a look at the elements of the script:
- In the first line, I gather the current date and time – it is used as the part of the file name
- In the second line the whole magic happens – I call FFmpeg asking to record one frame from the RTSP stream
- Please note that there is a username, password, and camera address in the RTSP link – you have to configure this as per your camera
- “-vframes 1” is the request to save one frame only
- the file name contains “img” and the date-time part
The script is executed as the cron job – every minute. You can adjust this to save every few minutes if you don’t want to store too many files.
Once I had a good amount of frames captured, I was able to glue them together and create the actual timelapse. This was also done with FFmpeg:
ffmpeg -r 24 -pattern_type glob -i '*.jpg' -s hd1080 -vcodec libx264 timelapse.mp4
This command asks FFmpeg to create a movie, 24 frames per second, using all JPG files found and save it as a timelapse.mp4
With these two easy steps, I gathered the whole day and created this simple timelapse you can see below. As per today, I have over two weeks of photos and I’m going to glue them together to create a larger piece. Easy and fun 🙂
Very nice, you helped a lot!
Thanks 🙂