pict-converter.sh 2.3 KB

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