Mac之转换mov为gif
1. 安装ffmpeg、gifsicle:
brew install ffmpeg
brew install gifsicle
2. 执行转换命令
ffmpeg -i in.mov -pix_fmt rgb8 output.gif && gifsicle -O3 output.gif -o output.gif
添加-s 640x360,可以设置图像的大小为 640x360。添加-r 10,可以设置帧率为10:
ffmpeg -i in.mov -pix_fmt rgb8 -s 640x360 -r 10 output.gif && gifsicle -O3 output.gif -o output.gif
3. (可选)设置快捷执行命令
3.1 基础
alias v2g='function v2g(){ ffmpeg -i "$1" "${1%.*}.gif" && gifsicle -O3 "${1%.*}.gif" -o "${1%.*}.gif" && osascript -e "display notification \"${1%.*}.gif successfully converted and saved\" with title \"VIDEO to GIF SUCCESS!\""};v2g'
在命令行执行:v2g input_video.mov 即可
3.2 如果想自定义输出的gif文件名称,可以使用:
alias v2g='function v2g(){ ffmpeg -i $1 $2.gif && gifsicle -O3 $2.gif -o $2.gif && osascript -e "display notification \"$2.gif successfully converted and saved\" with title \"VIDEO to GIF SUCCESS!\""};v2g'
在命令行执行:v2g input_video.mov output_name即可,可以保存一个output_name.gif的文件
3.3 如果想有更多可选参数
function v2g() { src="" # required target="" # optional (defaults to source file name) resolution="" # optional (defaults to source video resolution) fps=10 # optional (defaults to 10 fps -- helps drop frames) while [ $# -gt 0 ]; do if [[ $1 == *"--"* ]]; then param="${1/--/}" declare $param="$2" fi shift done if [[ -z $src ]]; then echo -e "\nPlease call 'v2g --src <source video file>' to run this command\n" return 1 fi if [[ -z $target ]]; then target=$src fi basename=${target%.*} [[ ${#basename} = 0 ]] && basename=$target target="$basename.gif" if [[ -n $fps ]]; then fps="$fps" fi if [[ -n $resolution ]]; then # resolution="-s $resolution" echo "ffmpeg -i "$src" -pix_fmt rgb8 -r $fps -s $resolution "$target" && gifsicle -O3 "$target" -o "$target"" ffmpeg -i $src -pix_fmt rgb8 -r $fps -s $resolution "$target" && gifsicle -O3 "$target" -o "$target" else echo "ffmpeg -i "$src" -pix_fmt rgb8 -r $fps "$target" && gifsicle -O3 "$target" -o "$target"" ffmpeg -i $src -pix_fmt rgb8 -r $fps "$target" && gifsicle -O3 "$target" -o "$target" fi # echo "ffmpeg -i "$src" -pix_fmt rgb8 -r $fps $resolution "$target" && gifsicle -O3 "$target" -o "$target"" # ffmpeg -i $src -pix_fmt rgb8 -r $fps $resolution "$target" && gifsicle -O3 "$target" -o "$target" echo "\"$target successfully converted and saved\"" }
在命令行执行 v2g --src input_video.mp4 --target output_name --resolution 800x400 --fps 30, 其中target,resolution和fps是可选参数,当不传入的时候,output_name默认为输入文件的名字,分辨率默认为视频的分辨率,帧率默认为10帧。