Sharing pixel art as animated gifs on social media sucks. Uploading animated gifs will typically get automatically converted to a video format with blurry results. We can manually do the conversion ourselves to get much nicer results.
ffmpeg -i input.gif -movflags faststart -pix_fmt yuv420p -vf scale=1920:1080:flags=neighbor output.mp4
ffmpeg is the command line tool we are using to do the conversion. It can be downloaded from https://www.ffmpeg.org or acquired from various package managers (apt, brew, winget, etc). To perform the conversion we need to provide ffmpeg several command line parameters.
-i input.gif
Specifies which file to use as input. Hereinput.gif
is the file we wish to convert.-movflags faststart
Enables fast start for online playback.-pix_fmt yuv420p
Specifies output pixel format. Theyuv420p
format is widely compatible with most media players.-vf scale=1920:1080:flags=neighbor
Applies a filter to video. Here the filter isscale=1920:1080:flags=neighbor
. Which scales the output resolution to 1920x1080. The magic bit isflags=neighbor
which indicates to use nearest neighbor scaling. This is exactly what we want for pixel perfect upscaling.output.mp4
Specifies name of output file. Hereoutput.mp4
is the file we want to get.
blurry.mp4
Blurry upscaling
pixel_perfect.mp4
Pixel perfect upscaling
ffmpeg -i input.gif -movflags faststart -pix_fmt yuv420p -vf scale=iw*3:ih*3:flags=neighbor output.mp4
You can use a little bit of math inside the filter to calculate the output resolution for you. Here scale=iw*3:ih*3:flags=neighbor
will scale the original image up by 3x. Where iw
is the input image width and ih
is the input image height.
The scale filter has quite a few options. You can read about them at FFmpeg Filters Documentation.
thank you!!! I've been looking for this for a while now