pict-converter.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # Bachir Soussi Chiadmi 06/2016
  3. # https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
  4. # needs ffmep and exiftool
  5. function convert {
  6. now=$(date +"%Y-%m-%d--%T")
  7. echo "Timelaps conversion | $now"
  8. mkdir ~/hehe-rover/www/tmp_videos
  9. mkdir ~/hehe-rover/www/tmp_metadata
  10. mkdir ~/hehe-rover/www/tmp_pictures
  11. rm -f tmp_pictures/*
  12. x=1
  13. for i in public_html/pictures/*.jpg; do
  14. counter=$(printf %03d $x)
  15. ln "$i" tmp_pictures/img"$counter".jpg
  16. x=$(($x+1))
  17. done
  18. pf=12
  19. vf=24
  20. echo "pictframerate:$pf, videoframerate=$vf"
  21. echo 'Video conversion'
  22. echo "creating raw timelaps"
  23. ffmpeg -y \
  24. -framerate $pf \
  25. -i tmp_pictures/img%03d.jpg \
  26. -r $vf -pix_fmt yuv420p -vcodec libx264 \
  27. tmp_videos/timelaps-raw.mp4
  28. echo "optimizing responsive videos"
  29. ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=1920:-1, crop=in_w:1080" tmp_videos/timelaps-1080p.mp4
  30. ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=1280:-1, crop=in_w:720" tmp_videos/timelaps-720p.mp4
  31. ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=720:-1, crop=in_w:480" tmp_videos/timelaps-480p.mp4
  32. ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=640:-1, crop=in_w:340" tmp_videos/timelaps-360p.mp4
  33. ffmpeg -y -i tmp_videos/timelaps-raw.mp4 -vf "scale=360:-1, crop=in_w:240" tmp_videos/timelaps-240p.mp4
  34. echo "updating production videos"
  35. rsync -r tmp_videos/ public_html/videos/
  36. echo "metadata export"
  37. f=0
  38. echo -e '{' > tmp_metadata/frames.json
  39. echo -e '\t"frames":[' >> tmp_metadata/frames.json
  40. for pict in public_html/pictures/*.jpg; do
  41. # SRC
  42. src="${pict/public_html\/pictures\//}"
  43. # TIME
  44. # time="${pict/pictures\/hehe-/}"
  45. # time="${time/.jpg/}"
  46. time=`exiftool 2>/dev/null -S --DateTimeOriginal -p '$DateTimeOriginal' -d %Y/%m/%d-%T "$pict"`
  47. # GPS
  48. gps=`exiftool 2>/dev/null -n -p '$GPSLatitude,$GPSLongitude' $pict`
  49. # FRAME
  50. frame=$(((60/$vf)*$f))
  51. echo -e "\t\t{\"src\":\"$src\", \"time\":\"$time\", \"gps\":\"$gps\", \"frame\":\"$frame\"}," >> tmp_metadata/frames.json
  52. f=$(($f+1))
  53. done
  54. echo -e "\t]" >> tmp_metadata/frames.json
  55. echo -e "}" >> tmp_metadata/frames.json
  56. rsync -r tmp_metadata/ public_html/metadata/
  57. }
  58. day=$(date +"%Y-%m-%d")
  59. logfile="logs/convert-$day.log"
  60. touch $logfile
  61. convert | tee -a $logfile