Artisanal GIF Ripping


/dʒɪf/ is the format, /ɡɪf/ is the handball club in Eskilstuna, Sweden.

GIF, the graphics interchange format, is probably the most inefficient representation for animated images in quality/size that is widespread today. However, it does live up to its name, being also the most portable format for animated graphics exchange. If a device has a color display and is connected to the Internet, tis likely to support GIF out of the box.

Like with incandescent light bulbs, it'd be wasteful to have not switched to more efficient alternatives, though GIF still has its charms. Not having to worry about codec compatibility is one thing, the nostalgia induced by the .gif file extension is another. For years, I got an Internet folder full of those (along with still images and short videos) for offline viewing, shitposting and reaction.

More recently, I began to make my own animated images and take pride in them. This tutorial will step-by-step lay out my process in cutting out a high-quality GIF from a video, so you can be just like me!

  1. Decide on the Format
  2. Extract Frames
  3. Crop and Resize
  4. Combine

Decide on the Format

Just because you can doesn't mean that you should.

Good things often don't come out of desire, but necessity. GIF is cool because tis portable, but plain text is even more portable. Multimedia weigh hundreds of kilobytes each, so they better best convey whatever information they're meant to communicate. Don't replace the audio with a subtitle just so it can be an animated image. Don't loop anything longer than a few seconds.

There is an old saying: if tis doing fine being a video, let it be a video. Videos don't need each frame to be perfect, and thus all the following steps can be done in a single ffmpeg command. Work smart, even just for shitposting.

Extract Frames

Open the source video in mpv, seek then spam s. repeatedly. That's all, y waste time write lot word wen few word do trick?

Aight, maybe there's a bit more to it. Operating on the level of frames will allow you to skip redundant ones in case of misencoded sources or duplicate and reverse a subsequence for a closer-to-perfect loop, but really, there's not much to talk about.

Crop and Resize

Ripping a GIF from a video is taking a sequence of frames out of context. Framing and some objects in the scene might not make sense in the target animated image. Some also like to export videos with giant black bars just to fuck with us. That's where cropping comes into play. For measuring I use GIMP, which doesn't seem to be the right tool for the job, so please let me know of anything lighter that has a ruler.

In addition, videos from social media (and space-efficient movies) are heavily compressed and look pretty bad for their resolution. Usually I have to shrink them down to two third or a half of their original width for them to look decently sharp. When you have the geometry in mind, summon the image wizard:

crop="-crop ${w}x${h}+${dx}+${dy}"
resize="-resize ${width}x${height}"
parallel -i sh -c "convert $crop $resize"\
' {} $(basename {} .jpg).png' -- mpv-shot*.jpg

In case you don't have moreutils/GNU parallel, or if you are rocking a single-CPU machine, run:

mogrify $crop $resize -format png mpv-shot*.jpg

For resizing, image processing expert Nicolas Robidoux wrote a long article on resampling filters. Although I can't spot any distinction for this use case, it doesn't hurt to give it a read and play around with different options.

Pam stating that they are the same picture


We are going to encode in best quality possible using gifski. The reason we converted from JPEG to PNG earlier is that our precious encoder refuses to touch any other image format, and that mpv take screenshots in JPEG by default (you can configure it to write in lossless format but in my experience, the source videos are often too heavily compressed for it to make any difference). Anyhow, invoking gifski is rather straightforward:

gifski -r $fps -Q 100 -o $name.gif mpv-shot*.png

Note that it optionally takes width and height as an argument and yield better quality than with pre-shrunken images, but at the cost of a significantly larger file size. Choose wisely.

Tags: fun recipe Nguyễn Gia Phong, 2023-03-16


Follow the anchor in an author's name to reply. Please read the rules before commenting.