Skip to content

Instantly share code, notes, and snippets.

@ruucm
Last active September 18, 2019 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruucm/db4b92e675978bcb4d378c4cf38f7887 to your computer and use it in GitHub Desktop.
Save ruucm/db4b92e675978bcb4d378c4cf38f7887 to your computer and use it in GitHub Desktop.
A simple bash script changing Video file to GIF using ffmpeg. It keeps aspect ratio of the video
#!/bin/bash
read -p "Input Video: " vid
read -p "Known Dimension(VID_WIDTH): " VID_WIDTH
read -p "Known Dimension(VID_HEIGHT): " VID_HEIGHT
# trim file name
x=${vid##*/}
y=${x%.*}
filename=${y##*/}
# keeps aspect ratio
MAX_WIDTH=640
if [ -z $VID_WIDTH ] || [ -z $VID_HEIGHT ]
then
echo "dimension(VID_WIDTH, VID_HEIGHT) is empty"
ffmpeg -ss 00:00:00.000 -i "$vid" -pix_fmt rgb24 -r 10 -vf scale=640:-1 "$filename".gif
else
VID_HEIGHT=$(echo "$MAX_WIDTH/$VID_WIDTH*$VID_HEIGHT" | bc -l)
VID_WIDTH=$MAX_WIDTH
dimension=$VID_WIDTH":"$VID_HEIGHT
echo $dimension
ffmpeg -ss 00:00:00.000 -i "$vid" -pix_fmt rgb24 -r 10 -vf scale="$dimension" "$filename".gif
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment