Timelapse video

Hello, Last month with my colleague Andrey start Meteo station for Dobrich town (I will wrote about this next time) – and after this project, we decide to put cameras for timelapse video. Everything needed for timelapse video which I use is :

  1. Cron which downloads snapshots from the camera every 1 minute and saves it with uniq name (date-hour-minute)
  2. Script which merge every picture snapshots in one timelapse video
  3. Script which makes this video faster so we can get 1 minute video for the laste 24 hours

Here’s how things look like:

Cron:

*/1 * * * * root curl -s "http://111.112.111.33:8889/webcapture.jpg?command=snap&channel=1" > "/var/www/cdn.root.bg/weather-pics/$(date +\%Y\%m\%d\%H\%M\%S).jpg"
30 5 * * * root /root/scripts/timelapse.sh &> /dev/null

it’s important to mention that the script that makes the video is starting every morning at 5:30 to catch the sunrise!

Timelapse script:

#!/bin/bash
rm -f /var/www/cdn.root.bg/timelapse.mp4
rm -f /var/www/cdn.root.bg/weather-pics/out.mp4
cd /var/www/cdn.root.bg/weather-pics/ ; cat *.jpg | ffmpeg -f image2pipe -r 1 -vcodec mjpeg -i - -vcodec libx264 out.mp4 ; ffmpeg -i out.mp4 -vf "setpts=(PTS-STARTPTS)/10" -r 10 ../timelapse.mp4
rm -f /var/www/cdn.root.bg/weather-pics/*.jpg ; rm -f /var/www/cdn.root.bg/weather-pics/*.jpg.webp

To have no cache from the nginx web server, I’ve added a special rule to serve each time to a new one from the cdn timelapse.mp4

location = /timelapse.mp4 {
        # kill cache
        add_header Last-Modified $date_gmt;
        add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
        if_modified_since off;
        expires off;
        etag off;
        add_header "Access-Control-Allow-Origin" "*";
        add_header P3P "Can I help you? Contact me via https://root.bg/contacts/, CP=CAO ADMa DEVa IND PHY ONL UNI COM LOC";
}

PS. The version of ffmpeg I use is: 3.4.6 – I had tried before with a new snap installed but did not work as I wanted.

And the result is :

That’s it!