markdown 将webm文件转换为GIF(使用FFmpeg和Gifsicle)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 将webm文件转换为GIF(使用FFmpeg和Gifsicle)相关的知识,希望对你有一定的参考价值。

## Introduction

Sometimes I want to make a screencapture of a websites behaviour.

In Chrome, I am quite happy doing this with the [Awesome Screenshot: Screen Video Recorder][1] extension.

Besides screenshots, the extension offers the ability to make a recording. (Limited to 30 seconds in the free version).

The recording can be uploaded to Youtube or Google Drive. It can also be downloaded as WebM file.

Often, I want to share the recording with co-workers on Slack.

Besides the fact that Slack does not support WebM, I dislike uploading several MBs of recording.

To remedy this, I convert the recording to a (smaller) GIF and share that on Slack.

## Converting

To convert the WebM to GIF, I use [FFmpeg][2]. I then use [Gifsicle][3] to resize and optimize the created GIF.

I've found that 600 pixels height is a nice compromise between size and readablility (when text is involved).

The command I use for this is:

```bash
sInput='/path/to/file.webm';
sOutput="$(basename ${sInput%.*})";
ffmpeg -i "${sInput}" -pix_fmt rgb8 "${sOutput}.gif" \
    && gifsicle --optimize=3 --output "${sOutput}-optimized.gif" --resize-height 600 "${sOutput}.gif"
```

This will easily turn a 2.5M WebM file to a 600K GIF. Without optimization it would be roughly 3.5M.

I'm sure more optimizations are possible, I might add these later.

It would also be simple to turn the command into a function. I might do _that_ later as well.

<!-- TODO:
## Explaining the command

`--optimize[=level]` Optimize output GIF animations for space. Level determines how much optimization is done; higher levels take longer, but may have better results. There are currently three levels: 

- `-O1` Stores only the changed portion of each image. This is the default.
- `-O2` Also uses transparency to shrink the file further.
- `-O3` Try several optimization methods (usually slower, sometimes better results).
-->

[1]: https://chrome.google.com/webstore/detail/awesome-screenshot-screen/nlipoenfbbikpbjkfpfillcgkoblgpmj
[2]: https://www.ffmpeg.org
[3]: https://www.lcdf.org/gifsicle/

以上是关于markdown 将webm文件转换为GIF(使用FFmpeg和Gifsicle)的主要内容,如果未能解决你的问题,请参考以下文章

当我将透明度添加到 gif 并将其转换为 webm 时出现故障

sh 将GIF简单地转换为MP4(h264 / h265),WebM(vp8 / vp9)和WebP

使用 Python 将 WEBM 文件转换为 WAV 文件 [关闭]

markdown 将视频转换为Gif

使用PHP将视频文件转换为mp4、flv、webgl、webm、ogv等

如何在制作 gif FFMPEG WEBM TO GIF 之前覆盖帧