> ## Content Index
> Fetch the complete content index at: https://yinguobing.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# 视频转高质量动图
- URL: https://yinguobing.com/blog/ffmpeg-video-to-gif/
- Published: 2018-04-13T09:29:01.000Z
- Updated: 2018-04-13T09:29:01.000Z
- Description: 如何使用FFMPEG将视频转换为GIF动图
- Author: 尹国冰
- Tags: 图像处理

写博客的时候有时会遇到需要从视频中截取一部分作为图片嵌入到网页中。此时FFMPEG就派上用场了。

[这篇博客](http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html?ref=yinguobing.com)对转换方式以及参数做了详细的介绍，如果感兴趣可以仔细研究下。下边贴出一份我自己使用的脚本。

```
#!/bin/sh
# Original author: http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

start_time=00:15
duration=2

palette="/tmp/palette.png"

filters="fps=15,scale=320:-1:flags=lanczos"

ffmpeg -v warning -ss $start_time -t $duration -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -ss $start_time -t $duration -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2

```