pict-converter.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/sh
  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 convertVideo {
  6. echo 'Video conversion'
  7. pf=$1
  8. vf=$2
  9. ffmpeg -y \
  10. -framerate $pf \
  11. -pattern_type glob -i 'public_html/pictures/*.jpg' \
  12. -r $vf -pix_fmt yuv420p -c:v libx264 \
  13. videos/timelaps-raw.mp4
  14. ffmpeg -y -i public_html/videos/timelaps-raw.mp4 -vf "scale=1920:-1, crop=in_w:1080" videos/timelaps-1080p.mp4
  15. ffmpeg -y -i videos/timelaps-raw.mp4 -vf "scale=1280:-1, crop=in_w:720" videos/timelaps-720p.mp4
  16. ffmpeg -y -i videos/timelaps-raw.mp4 -vf "scale=720:-1, crop=in_w:480" videos/timelaps-480p.mp4
  17. ffmpeg -y -i videos/timelaps-raw.mp4 -vf "scale=640:-1, crop=in_w:340" videos/timelaps-360p.mp4
  18. ffmpeg -y -i videos/timelaps-raw.mp4 -vf "scale=360:-1, crop=in_w:240" videos/timelaps-240p.mp4
  19. }
  20. function exportData {
  21. echo "metadata export"
  22. pf=$1
  23. vf=$2
  24. f=0
  25. echo -e "{" > metadata/frames.json
  26. echo -e '\t"frames":[' >> metadata/frames.json
  27. for pict in pictures/*.jpg; do
  28. # TIME
  29. # time="${pict/pictures\/hehe-/}"
  30. # time="${time/.jpg/}"
  31. time=`exiftool 2>/dev/null -S --DateTimeOriginal -p '$DateTimeOriginal' -d %Y/%m/%d-%T "$pict"`
  32. # GPS
  33. gps=`exiftool 2>/dev/null -n -p '$GPSLatitude,$GPSLongitude' $pict`
  34. # FRAME
  35. frame=$(((60/$vf)*$f))
  36. echo -e "\t\t{\"pict\":\"$pict\", \"time\":\"$time\", \"gps\":\"$gps\", \"frame\":\"$frame\"}," >> metadata/frames.json
  37. f=$(($f+1))
  38. done
  39. echo -e "\t]" >> metadata/frames.json
  40. echo -e "}" >> metadata/frames.json
  41. }
  42. function convert {
  43. now=$(date +"%Y-%m-%d--%T")
  44. echo "Timelaps conversion | $now"
  45. pictframerate=12
  46. videoframerate=24
  47. echo "pictframerate:$pictframerate, videoframerate=$videoframerate"
  48. convertVideo $pictframerate $videoframerate
  49. exportData $pictframerate $videoframerate
  50. }
  51. day=$(date +"%Y-%m-%d")
  52. logfile="logs/convert-$day.log"
  53. touch $logfile
  54. convert | tee -a $logfile