Last active
September 18, 2019 21:52
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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