Skip to content

Instantly share code, notes, and snippets.

@shinmiy
Created September 24, 2020 08:49
Show Gist options
  • Save shinmiy/b2e77b71679338cfb6274b9081358ee1 to your computer and use it in GitHub Desktop.
Save shinmiy/b2e77b71679338cfb6274b9081358ee1 to your computer and use it in GitHub Desktop.
#!/bin/bash
#############################################################
# mp4togif.sh
# ========================================
# $ ./mp4togif.sh video_to_convert.mp4
# ========================================
# ffmpeg入ってること前提
# $ brew install ffmpeg
# (参考)
# FFmpegで動画をGIFに変換
# https://qiita.com/wMETAw/items/fdb754022aec1da88e6e
# ffmpegで動画を綺麗なgifに変換するコツ
# https://life.craftz.dog/entry/generating-a-beautiful-gif-from-a-video-with-ffmpeg
#############################################################
if [ "$1" != "" ]; then
echo "Converting $1"
else
echo "Parameter 1 is empty"
exit 0;
fi
ffmpeg -i $1 -vf "palettegen" -y $1_palette.png
filename=$(basename -- "$1")
extension="${filename##*.}"
name="${filename%.*}"
fps=15
aspect="-1:480" # 縦480pxで横はアス比キープ
ffmpeg -i $1 -i $1_palette.png -lavfi "fps=${fps},scale=${aspect}:flags=lanczos [x]; [x][1:v] paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" -y $name.gif
rm $1_palette.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment