#!/bin/bash # Bachir Soussi Chiadmi 06/2016 # https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images # needs ffmep and exiftool function convert { now=$(date +"%Y-%m-%d--%T") echo "Timelaps conversion | $now" mkdir ~/hehe-rover/www/tmp_videos mkdir ~/hehe-rover/www/tmp_metadata mkdir ~/hehe-rover/www/tmp_pictures rm -f tmp_pictures/* x=1 for i in public_html/pictures/*.jpg; do counter=$(printf %03d $x) ln "$i" tmp_pictures/img"$counter".jpg x=$(($x+1)) done pf=12 vf=24 echo "pictframerate:$pf, videoframerate=$vf" echo 'Video conversion' echo "creating raw timelaps" ffmpeg -y \ -framerate $pf \ -i tmp_pictures/img%03d.jpg \ -r $vf -pix_fmt yuv420p -vcodec libx264 \ tmp_videos/timelaps-raw.mp4 echo "optimizing responsive videos" ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=1920:-1, crop=in_w:1080" tmp_videos/timelaps-1080p.mp4 ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=1280:-1, crop=in_w:720" tmp_videos/timelaps-720p.mp4 ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=720:-1, crop=in_w:480" tmp_videos/timelaps-480p.mp4 ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=640:-1, crop=in_w:340" tmp_videos/timelaps-360p.mp4 ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=360:-1, crop=in_w:240" tmp_videos/timelaps-240p.mp4 echo "updating production videos" rsync -r tmp_videos/ public_html/videos/ echo "metadata export" f=0 echo -e '{' > tmp_metadata/frames.json echo -e '\t"frames":[' >> tmp_metadata/frames.json for pict in public_html/pictures/*.jpg; do # SRC src="${pict/public_html\/pictures\//}" # TIME # time="${pict/pictures\/hehe-/}" # time="${time/.jpg/}" time=`exiftool 2>/dev/null -S --DateTimeOriginal -p '$DateTimeOriginal' -d %Y/%m/%d-%T "$pict"` # GPS gps=`exiftool 2>/dev/null -n -p '$GPSLatitude,$GPSLongitude' $pict` # FRAME frame=$(((60/$vf)*$f)) echo -e "\t\t{\"src\":\"$src\", \"time\":\"$time\", \"gps\":\"$gps\", \"frame\":\"$frame\"}," >> tmp_metadata/frames.json f=$(($f+1)) done echo -e "\t]" >> tmp_metadata/frames.json echo -e "}" >> tmp_metadata/frames.json rsync -r tmp_metadata/ public_html/metadata/ } day=$(date +"%Y-%m-%d") logfile="logs/convert-$day.log" touch $logfile convert | tee -a $logfile