Skip to content

Instantly share code, notes, and snippets.

@takashicompany
Last active January 6, 2023 07:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takashicompany/a6722a37dc5d4a3c9a3afe3c541e9169 to your computer and use it in GitHub Desktop.
Save takashicompany/a6722a37dc5d4a3c9a3afe3c541e9169 to your computer and use it in GitHub Desktop.
動画ファイルをキレイなgifにしてくれるコマンドライン
#!/bin/bash
CMDNAME=`basename $0`
while getopts i:s:f:e: OPT
do
case $OPT in
"i" ) is_import="TRUE" ; import="$OPTARG";;
"s" ) is_size="TRUE" ; size="$OPTARG" ;;
"f" ) is_fps="TRUE" ; fps="$OPTARG" ;;
"e" ) is_export="TRUE" ; export="$OPTARG" ;;
* ) echo "Usage: $CMDNAME [-a] [-b VALUE] [-c VALUE]" 1>&2
exit 1 ;;
esac
done
if [ $# -eq 0 ]; then
echo "下記の引数を指定してください"
echo "-i : インポートする動画ファイル"
echo "-s : 縦横のサイズ。縦:横のピクセルで指定。-1を指定すると、他のサイズを元に縦横比を維持する\n例 : 600:-1"
echo "-f : fps。整数を入れてください"
echo "-e : エクスポート先のファイルパス"
exit 1
fi
if [ "$is_import" = "TRUE" ]; then
:
else
echo "インポートする動画ファイルが選択されてません"
exit 1
fi
if [ "$is_export" = "TRUE" ]; then
:
else
echo "ファイルの書き出し先が指定されていません"
exit 1
fi
if [ "$is_size" = "TRUE" ]; then
:
else
size="-1:-1"
fi
if [ "$is_fps" = "TRUE" ]; then
:
else
fps=12
fi
ffmpeg -i ${import} -vf "palettegen" -y palette.png
ffmpeg -i ${import} -i palette.png -lavfi "fps=${fps},scale=${size}:flags=lanczos [x]; [x][1:v] paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" -y ${export}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment