pict-converter.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 tmp_videos
  9. mkdir tmp_metadata
  10. mkdir tmp_pictures
  11. rm -f tmp_pictures/*
  12. x=1
  13. for i in public_html/pictures/*.jpg; do
  14. counter=$(printf %06d $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%06d.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. l=0
  38. for pict in public_html/pictures/*.jpg; do
  39. l=$((l+1))
  40. done
  41. f=0
  42. echo -e '{' > tmp_metadata/frames.json
  43. echo -e '\t"frames":[' >> tmp_metadata/frames.json
  44. for pict in public_html/pictures/*.jpg; do
  45. # SRC
  46. src="${pict/public_html\/pictures\//}"
  47. # TIME
  48. # time="${pict/public_html\/pictures\/hehe-/}"
  49. # time="${time/.jpg/}"
  50. datetime=`exiftool 2>/dev/null -S --DateTimeOriginal -p '$DateTimeOriginal' -d %Y-%m-%dT%T "$pict"`
  51. # GPS
  52. gps=`exiftool 2>/dev/null -n -p '$GPSLatitude,$GPSLongitude' $pict`
  53. # FRAME
  54. currenttime=$(((1/$pf)*$f))
  55. if [[ $f == $(($l-1)) ]]; then
  56. echo -e "\t\t{\"src\":\"$src\", \"datetime\":\"$datetime\", \"gps\":\"$gps\", \"currenttime\":\"$currenttime\"}" >> tmp_metadata/frames.json
  57. else
  58. echo -e "\t\t{\"src\":\"$src\", \"datetime\":\"$datetime\", \"gps\":\"$gps\", \"currenttime\":\"$currenttime\"}," >> tmp_metadata/frames.json
  59. fi
  60. f=$(($f+1))
  61. done
  62. echo -e '\t]' >> tmp_metadata/frames.json
  63. echo -e '}' >> tmp_metadata/frames.json
  64. rsync -r tmp_metadata/ public_html/metadata/
  65. }
  66. day=$(date +"%Y-%m-%d")
  67. logfile="logs/convert-$day.log"
  68. touch $logfile
  69. convert | tee -a $logfile