GIF + MacOS Preview mystery
Hi. I’m Nik and I’m one of the creators of GifGun, the one-click GIF render engine for Adobe After Effects.
We released version 1.0 in December 2015. Just 10 months later and we’re at version 1.4. We’ve fixed lots of bugs, added tons of extra features, and have more than 2,000 users and growing.
In the last couple of weeks we’ve heard from several clients about issues they’d experienced with the Preview app on MacOS versions 10.10 and 10.11. Preview simply refused to show their gifs; only showing a loading gif of its own instead.
However, those using Chrome and Firefox didn’t have this problem. They solved the issue by dragging the image to their preferred browser’s window.
Those using Windows devices didn’t experience these problems at all.
So what happened? All troubled gifs had something in common — they were big. They were either rendered at a very large resolution (e.g. 1280 x 720) or had a duration of 30 seconds or more. Or both.
At first we dismissed the issue as a possible rare MacOS bug and thought no more of it. But then we received two more reports in a week. No more messing around! As a Macbook owner, with macOS 10.11 installed, I’d experienced the bug firsthand too. So I started digging…
To start off, we looked at all of our troubled gif projects and analyzed them in depth. They were fairly ordinary — similar to any other project you’d make in After Effects. Rendering a gif with the same dimensions and duration resulted in a similar result; regardless of the type of content used.
Testing our assumptions
We made a sample project with Origami, another tool we created for After Effects, and started rendering it in different resolutions, frame rates, and durations.
Each resolution failed at different durations. Here’s a graph showing what happened:
As you’d think, larger resolutions failed at lower durations. But to be absolutely sure, we rendered both with GifGun and Photoshop. The results were the same.
Then we discovered something: Preview first preloads the whole file, but individually, resolution, file size, and duration weren’t the problem. It was still possible to render huge gifs (like couple of frames at 4000 x 4000 or 200 x 200 and two minutes long). A two second gif cut from your favourite cable show might be 10–20 MB, but it’ll still play as smoothly as a 500 KB gif made with simple graphics. But there seemed to be a problem threshold; when things went wrong.
To determine the maximum size of a trouble-free gif file, I came up with a simple formula:
Limiting Criteria = Width (in pixels) x Height (in pixels) x Frame Rate (frames per second) x Duration (in seconds)
This is not exactly the size of gif file stored in RAM, but it shows how many pixels will load from all the frames in a gif file. Gif file size is mostly defined by its palette — less colors result in less size: even with the same duration, frame rate and resolution. This means that each gif pixel is described by its palette color from the LUT (lookup table). A gif’s color space is limited to 256 colors, so one byte should be enough to reference any color within that palette.
After calculating the limiting criteria for each of the test gif files, I came to a value of roughly 250 million pixels. So this is basically it: you can render gifs that are less that 250 million pixels and preview them freely in macOS, but exceeding this limit means your gifs won’t load.
But the question remained — why 250 million? Our best guess is that 250 million pixels multiplied x 8 (bits in byte for referencing palette colors) equals to 2 billion. This is very close to the number 2,147,483,647 — the absolute limit for signed long integer numbers on 32-bit systems. Remember, this is our guess, we could not prove it.
A Google search for ‘issues with Preview’ led us to a number of articles and forum topics discussing how Preview began slowing down on 10.10 from as early as 2014.   
In MacOS 10.10 Preview stopped showing not only large gifs, but large pdf files as well. However, the good news is that macOS 10.12 is not affected by this issue and we were able to playback super large gifs on it with only the slightest load time.
The gif mystery is solved! This is a great selling point for Sierra, so if you keep experiencing the same issues, go get that free update.
You may see all our test GIFs in this Dropbox folder