The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Create High Quality GIFs with ffmpeg

TODO: Pull subtitle into page object

### TL;DR

This command uses ffmpeg to convert a video into a high quality GIF:

code_start_default_section code_end_default_section

### Making The GIF

The command produces a high quality GIF at a reasonable size. You'll need ffmpeg installed to run it. Once you have that, change the `INPUT_PATH.mp4` and `OUTPUT_PATH.gif` to whatever filenames you want and you'll be good to go.

The example is an .mp4, but ffmpeg can read most anything you throw at it.

### Settings

Here are the different ways you can tweak the command:

- `fps`: is for the frames per second. Setting the value larger make the GIF smoother but bigger. Smaller values reduce the file size but make it choppier. - `scale`: sets the pixel size of the output. The format is "width:height". The example uses `scale=600:-2` which sets the width to 600 pixels and then automatically sets the height based off the original image. (The -2 means the height will be set to a even number of pixels.) Reverse the numbers if you'd rather set the height (e.g. `scale=-2:600). - `max_colors`: GIFs can have to up to 256 colors. ffmpeg will use all of them by default. If you lower the number it reduces the files size as a trade off being the reduced color pallet. Most GIFs work fine with 128 and lots work well with 64. It's all about how dynamic the original color pallet is.

### Clipping Videos

You use the flags to set the start and end points for clipping the video if you want to go that route.

- `ss`: The starting second to begin the clip at. This can be an integer, a decimal, or a timestamp. For example, "1", "1.4", or "1:15", respectively. - `t`: The length of time in seconds that you want the clip to be. This can be either an integer (e.g. "7") or a decimal (e.g. "4.2")

### GIF Away

All of these settings are a matter of personal taste and where you're going to publish them. The defaults work great for most thing. If you want to try to reduce file size or deal with an image with a huge color pallet they're worth messing around with.

And, if you're interested here are some examples.

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Create High Quality GIFs with ffmpeg

-- p

### TL;DR

-- p

This command uses ffmpeg to convert a video into a high quality GIF:

-- code/
-- bash

ffmpeg -i "INPUT_PATH.mp4" \
-vf "fps=16,scale=600:-2:flags=lanczos,split[s0][s1];\
[s0]palettegen=max_colors=128:reserve_transparent=0[p];\
[s1][p]paletteuse" \
-y "OUTPUT_PATH.gif"

-- /code

-- p

This is the same thing, but it clips out a section of the video starting at 2.3 seconds that's 1.3 seconds long instead of processing the entire clip:

-- code/
-- bash

ffmpeg -i "INPUT_PATH.mp4" -ss 2.3 -t 1.3 \
-vf "fps=16,scale=600:-2:flags=lanczos,split[s0][s1];\
[s0]palettegen=max_colors=128:reserve_transparent=0[p];\
[s1][p]paletteuse" \
-y "OUTPUT_PATH.gif"

-- /code

-- p

### Making The GIF

-- p

The command produces a high quality GIF at a reasonable size. You'll need <<link|ffmpeg|https://ffmpeg.org>> installed to run it. Once you have that, change the `INPUT_PATH.mp4` and `OUTPUT_PATH.gif` to whatever filenames you want and you'll be good to go.

-- p

The example is an .mp4, but ffmpeg can read most anything you throw at it.

-- p

### Settings

-- p

Here are the different ways you can tweak the command:

-- p

- `fps`: is for the frames per second. Setting the value larger make the GIF smoother but bigger. Smaller values reduce the file size but make it choppier.
- `scale`:  sets the pixel size of the output. The format is "width:height". The example uses `scale=600:-2` which sets the width to 600 pixels and then automatically sets the height based off the original image. (The -2 means the height will be set to a even number of pixels.) Reverse the numbers if you'd rather set the height (e.g. `scale=-2:600).
- `max_colors`: GIFs can have to up to 256 colors. ffmpeg will use all of them by default. If you lower the number it reduces the files size as a trade off being the reduced color pallet. Most GIFs work fine with 128 and lots work well with 64. It's all about how dynamic the original color pallet is.

-- p

### Clipping Videos

-- p

You use the flags to set the start and end points for clipping the video if you want to go that route.

-- p

- `ss`: The starting second to begin the clip at. This can be an integer, a decimal, or a timestamp. For example, "1", "1.4", or "1:15", respectively. 
- `t`: The length of time in seconds that you want the clip to be. This can be either an integer (e.g. "7") or a decimal (e.g. "4.2")

-- p

### GIF Away

-- p

All of these settings are a matter of personal taste and where you're going to publish them. The defaults work great for most thing. If you want to try to reduce file size or deal with an image with a huge color pallet they're worth messing around with.

-- p

And, if you're interested <<link|here are some examples|/animated-gifs-from-adobe-premiere-and-ffmpeg>>.


-- categories
-- Miscellaneous

-- metadata
-- date: 2021-02-12 00:00:00
-- id: 20envmzo
-- status: published
-- type: post
-- SCRUBBED_NEO: false
-- site: aws