This post is the fourth of six, and it is about making animation files that are not videos, called Animated GIFs (pronounced with a J like Jeff, not G like Garry).
For a couple of reasons, making an animated gif is not as easy as we would like, but with a few tips below, it is not so difficult.
Animated GIFs explained
The GIF image file, Graphics Interchange Format, was invented in 1987 when color computing was new and the internet was not around yet. It is compact and allows only 256 colors (remember that part) and supported animation. The animated format was very popular on dial-up services and the early internet. They then fell out of favor until their use in messaging apps and social media to send animations to people that did not require a player. Everyone could see your cat falling off the table, instantly.
Or their dog being woken up in the middle of an afternoon nap. I just took my iPhone, turned around in my chair, and took this video. Then I converted it to a GIF. It took me less than 30 seconds to make and share this gem:
For those of us in the world of simulation, they have been a popular format for the same reason—almost all applications, from email to web browsers to Microsoft Powerpoint, support animated GIFs. The file contains as many images as you want and a tag for each layer documenting how long to display each frame. The difference is we are not capturing our overweight mutt struggling to roll over. We have specific information we are trying to convey.
Ansys Mechanical Default
If you read the post about making videos, you will remember that one of the output options was GIF. Well, here is what you get when you use that option. Note, it only plays once, to play it again.
And by default, the file does not repeat. Also, to make things worse, the way Ansys stores the GIF is an order of magnitude larger than a video.
As a contrast, here is the same result as a video played through YouTube
Video to GIF is much better
So, unless you need something in 30 seconds, don’t use the default save video as GIF in Ansys Mechanical. A much better option is to convert a good video to a GIF.
So, go back to the article on making videos and get what you want for your animation using that info and save it to *.mp4 format. Then use one of the methods below to convert that to GIF.
If I take the video above that I posted on YouTube and run it through the free conversion tool, ezgif.com, I get this:
It is not as nice as the video, but it does not need a player. It just plays. Ezgif.com is free (lots of advertising) but has a lot of options. Not only does it covert quickly, but it also lets you crop, resize, add effects, change the speed, add text, and overlay.
The downside, if you have proprietary information you are letting someone else see it. My guess is uploading to a free server in the cloud will violate any NDA or security you have in place. But if not, ezgif.com is the simplest way to get a GIF from a video.
The first option, if you can’t use a free cloud-based tool like ezgif.com, is the Photoshop suite. Photoshop is the defacto tool for image editing and processing, and it has a lot of tools for making sophisticated animated GIFs, including importing a video, editing the frames from the video, and outputting a GIF.
Here is the process:
- Open Adobe Photoshop
- Chose File > Import > Vidio to Layers
- Chose your MP4 file
- In the “Import Video to Layers” dialog, make sure “From Beginning to End” is chosen and “Make Frame Animation” is checked on.
- Click OK
- At this point, you can do a huge amount of modifying and editing. But that is way beyond the scope of this post. We just want a GIF made. But if you know Adobe Photoshop, have at it. I often crop and change the size here. Maybe even run some filters on it. Or, if I’m getting really fancy, delete the background from each frame to have a transparent animation.
- Go to File > Export > Save for Web (Legacy)
- Chose GIF as the file format.
- Set colors to 256
- I like to set Dither to 100%
- Make sure Animation > Looping Options at the bottom is set to Forever.
- Click Save… and give it a file name.
Here is what the result looks like:
Adobe Premiere is, well, the premier tool for video editing and creation. Many professional videos are made with this tool. It is massive, powerful, and made for people who speak video. If you want to add to your animation, do fancy things with it, use Premiere. Otherwise, stick with Photoshop or an open-source or cloud tool.
But, if you want to use Premier, here is that basic process without any bells or whistles (literally and figuratively) added in:
- Open a new Project
- Specify a good directory for the project
- Drop your MP4into the Project Window
- The drag it to the Timeline
- Here is where you do your editing magic on the video.
- When you are ready to make your file, click File > Export > Media
- Chose Animated GIF for the format
- Do not pick GIF. That will make an image of every frame.
- Click on the name next to “Output Name” to set the name and directory.
- Make any other changes you feel are correct if you know Premier.
- Click Export
This is what you get.
if you don’t have access to any Adobe tools, I recommend GifTuna. Yes, the name is stupid. But it works and it is free.
Go to giftuna.io and download the app. it comes as a ZIP file. Just extract the zip file and run the executable, GifTuna.exe. It will then ask you to install FFMPEG. This is the same library that ezgif.com uses.
Once everything is installed:
- Click “Select File”
- Select the video you saved in Ansys Mechanical.
- Change the size if you want to
- Keep all the other defaults for your first pass.
- Click Export
You get a pretty nice video. Play with the dither options if it looks kind of fuzzy.
Making an Animated GIF out of Images
In all the examples above, we created animations by converting a good video into an animated GIF format. What if we just have a bunch of images and want to make a slide show out of them. Or maybe we want to show a series of geometry changes. Maybe the various steps in an animation.
In that case, save an image to a PNG or JPEG file for each frame you want, then use ezgif.com or PhotoShop to make your animation.
A word about APNG
The only real problem with Animated GIFS is that the GIF format only supports 256 colors. In many ways, PNG took over for GIF as the preferred file format. It is compact, handles transparency, and has the advantage of not being restricted on colors. The problem, only browsers support APNG. PowerPoint and most mail programs do not. And many tools like the Adobe Suite do not output in that format. But, ezgif.com does.
In fact, WordPress does not support the format. To view the APNG file, download this file and then open it in a browser:
Maybe someday this will be supported better. Hopefully in Microsoft products soon.
Moving from Motion to 3D
This should help you get a nice animation that you can put on a website and not have to worry about hosting so people can see it. The same goes for Email and PowerPoint. If you can live with fewer colors, it really is the best format for animations of results when you need to show them anywhere.
Now it’s time to move from 2D results to 3D. We will cover how to create 3D objects of your results in “5 – An update on outputting results in Ansys Mechanical: 3D Result Objects.“