View Single Post
turtle
Lord of the Rant.
Formerly turtle2472
 
Join Date: Mar 2005
Location: Upstate South Carolina
 
2020-09-25, 19:59

Code:
#!/bin/bash # # Copy daily images into folder for previous day, then compile into time lapse. # log=/var/services/homes/turtle/dailySnapshotCron.log yesterday=`date --date="yesterday" "+%Y%m%d"` path=/var/services/homes/turtle/flexImages/ # Start Logging event echo `date +%Y%m%d_%H%M%S` Begun daily actions >> $log # Make dir for yesterday and copy images to it mkdir $path$yesterday find $path -daystart -mtime 1 -size +20k -exec cp -t $path$yesterday {} + # Change to yesterday and nicely run time lapse compilation using ffmpeg cd $path$yesterday nice ffmpeg -hide_banner -loglevel warning -r 24 -pattern_type glob -i '*.jpg' -vcodec libx264 -pix_fmt yuv420p '/volume1/video/tmp/'$yesterday'_timelapse.mp4' >> $log # Remove "yesterday" dir rm -rf $path$yesterday # Closing log echo `date +%Y%m%d_%H%M%S` Completed daily actions >> $log # Unset variables unset log; unset yesterday; unset path
That is the code that will run daily via cron and produce the time lapse videos. Each video is about 30M as I mentioned before. This will take a long time, if I forget to purge, to fill the NAS. I'm copying the images to the folder so I still have one folder housing all the snapshots in a general sense. This will be helpful when I do the weekly time lapse video.

To breakdown the script for those who don't follow:
  • Set variables
    I went with variables like this to allow for flexibility for others using this script. Basically, use it and update your paths as needed.
  • Basic log for the start
    I wanted to log the start and end of the run so I had an idea of how long. It isn't needed, but it takes about 8 minutes on my NAS to run and it is fairly underpowered.
  • Make a directory to send the day's snapshots too
    This is a fun part. It makes the directory where you are going to send the day's snapshots too and then copies those snapshots over. I had to add a filter to the find command because the bad snapshot grabs resulted in 0b files and that stopped ffmpeg in its tracks. Putting the filter keeps it with assumably valid image files. Adjust that size as needed if you are pulling smaller files.
  • Change to that dir and compile the snapshots using nice
    ffmpeg doesn't like pulling globs from a path so you change to that dir. I run it with "nice" because it is a very underpowered NAS and it keeps everything else running mildly well while the process is running. nice can be adjusted as needed, defaults work fine for this.
  • Clean up
    I'm removing the "yesterday" directory because I don't want it hanging around. Since I'm using copy early on, I still have the originals in the source dir.
  • Close log entry
    Again, not required, but helps me know how long it too to run.
  • unset variables
    Old habit though not technically needed, I unset my variables even though they don't live beyond the script.

I still have the barking about deprecated pixel format... but I don't really care so I'm not in a rush to change it. Apparently it has something to do with the "-pix_fmt yuv4420p" portion.

The resulting log looks like this:
Code:
20200925_201851 Begun daily actions 20200925_202634 Completed daily actions
The video is named: 20200924_timelapse.mp4

Louis L'Amour, “To make democracy work, we must be a nation of participants, not simply observers. One who does not vote has no right to complain.”
Visit our archived Minecraft world! | Maybe someday I'll proof read, until then deal with it.
  quote