pict-converter.sh 1.9 KB

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