2 minute read

If a picture is worth a thousand words. What is the value of an animated GIF?

If anyone knew the answer to this question it was Eadweard Muybridge who was an 19th century photographer and the grandfather of today’s biomechanical scientists. He used sequences of photographs to analyze human and animal motion. At Muybridge’s time the work created lots of attention, and even today his short animations are iconic.

Muybridge animated horse
Galloping horse by Eadweard Muybridge.

In a previous post I introduced an AnyScript class-template to create awesome videos of your musculoskeletal simulations with a single click. But sometimes videos are just not enough.

If we want something that loops continuously and runs automatically, then we must create animated GIF files. Small animations accomplish something, which Eadweard Muybridge discovered long ago. They immediately convey the message and spell bind the viewer by allowing them to dwell on the details.

New feature to create animated GIFs

Today I just added a new feature to the video plugin. The ability to create good looking GIF files directly from the video. After producing the video, it can be converted into a GIF file. Just run the operation Operations.Convert_video_to_animated_gif

Convert GIF operation

Creating good looking GIF is more tricky than it may seem. The number of possible colors is limited to 256 in a GIF file. Thus, it is important to specify a color palette, otherwise, the image quality will suffer.

The video plugin uses FFmpeg in two passes. The first pass generates a global color palette from the entire video. The second pass encodes the GIF file with the generated palette. You can read more on the approach in this excellent blog post

The video plugin does not create animated GIF by default. For several reasons. Not all videos work well as an animated GIF file, and GIF files can take up a lot of space. But if you want to avoid the manual step, when generating the GIF file add the CREATE_GIF=1 argument to the AnyScript class template:

  VideoLookAtCamera  MyCam (UP_DIRECTION = y, CREATE_GIF = 1) = 
  {
       CameraLookAtPoint = Main.MyModel.Femur.Knee.r;  
       CameraFieldOfView  = 1;
       CameraDirection  = {1, 1, -1};
       BackgroundColor = {1, 1, 1};
       VideoInputFrameRate  = 10;
       VideoResolution = {1920, 1080};
       Analysis = {
          AnyOperation &ref = Main.MyStudy.Kinematics;
       };
  };

Find the code on GitHub

The AnyScript template is hosted on GitHub, where you can also find a few examples that show how it works. The repository also has documentation on the class_template and its options.

Human gif file
Animated GIF file, where the camera is spinning around the model.

Leave a comment