Advertisement
metalx1000

video to animated gif

Sep 27th, 2018
2,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.62 KB | None | 0 0
  1. #!/bin/bash
  2. #Created by Kris Occhipinti
  3. #Copyright September 2018
  4. #http://filmsbykris.com
  5. #License - GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
  6.  
  7. dir="$HOME/storage/dcim/Camera/"
  8. output="$(date +%s)"
  9. open="termux-open"
  10.  
  11. #image scale size
  12. scale=320
  13.  
  14. #frame rate
  15. rate=10
  16.  
  17. #move to photo dir
  18. cd "$dir"
  19.  
  20. #if r argument, then create reverse loop
  21. if [ "$1" = "r" ]
  22. then
  23.   reverse=true
  24. fi
  25.  
  26. #shopt -nullglob
  27. files=( *.mp4 )
  28.  
  29. let x=0;
  30. for i in "${files[@]}"
  31. do
  32.   echo "$x)$i"
  33.   let x++
  34. done
  35.  
  36. echo -n "Select a number: "
  37. read vid
  38.  
  39. v="${files[vid]}"
  40.  
  41. function progress(){
  42.   while [ $convert ]
  43.   do
  44.     sleep 1
  45.     clear
  46.     echo "Creating Loop..."
  47.     ls -la ${output}_loop.gif|awk '{print $5}'
  48.   done
  49. }
  50.  
  51. #does file exist?
  52. if [ -f "$v" ]
  53. then
  54.   pal="$HOME/pal.png"
  55.   rm $pal
  56.   ffmpeg -i $v -vf \ fps=15,scale=320:-1:flags=lanczos,palettegen $pal
  57.   #if reverse if true, make reverse loop
  58.   if [ $reverse ]
  59.   then
  60.     ffmpeg -i "$v" -filter_complex \
  61.       "[0:v]reverse,fifo[r];[0:v][0:a][r] [0:a]concat=n=2:v=1:a=1 [v] [a]"\
  62.       -map "[v]" -map "[a]" -r $rate $output.mp4
  63.  
  64.     ffmpeg -i "$output.mp4" -i $pal -filter_complex "fps=$rate,scale=$scale:-1:flags=lanczos[x];[x][1:v]paletteuse" $output.gif
  65.     #ffmpeg -i "$output.mp4" -vf scale=$scale:-1  -r $rate $output.gif
  66.     rm "$output.mp4"
  67.   else
  68.     ffmpeg -i "$v" -i $pal -filter_complex "fps=$rate,scale=$scale:-1:flags=lanczos[x];[x][1:v]paletteuse" $output.gif
  69.     #ffmpeg -i "$v" -vf scale=$scale:-1 -r $rate $output.gif
  70.   fi
  71.  
  72. else
  73.   echo "Bad selection"
  74.   exit 1
  75. fi
  76.  
  77. $open $output.gif
  78.  
  79. rm $pal
  80. clear
  81. ls -lh $output.gif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement