Last active
June 21, 2023 02:34
-
-
Save superdaigo/bbf884fdd1336b8c3d0987f91a2537d2 to your computer and use it in GitHub Desktop.
Convert movie file to GIF animation using ffmpeg and jq
This file contains 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
#!/usr/bin/env bash | |
# Convert movie file to GIF animation using ffmpeg and jq | |
set -e -o pipefail | |
MAX_WIDTH=1200 | |
MAX_HEIGHT=1200 | |
# ffprobe | |
stream_info=$(ffprobe -v quiet -print_format json -show_streams "$1") | |
width=$(echo "$stream_info" | jq '.streams[0].width') | |
height=$(echo "$stream_info" | jq '.streams[0].height') | |
# resize | |
if [ ${width} -gt ${height} ]; then | |
out_width=$width | |
out_height=-1 | |
if [ ${width} -gt ${MAX_WIDTH} ]; then | |
out_width=$MAX_WIDTH | |
fi | |
else | |
out_height=$height | |
out_width=-1 | |
if [ ${height} -gt ${MAX_HEIGHT} ]; then | |
out_height=$MAX_HEIGHT | |
fi | |
fi | |
scale="$out_width:$out_height" | |
# ffmepg | |
ffmpeg -i "$1" -vf scale="$scale" -r 10 "$1".gif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment