Skip to main content
Welcome guest. | Register | Login | Post

Create Animations with Inkscape, ImageMagick and FFmpeg

One way to create animations in Linux is to use the GIMP Animation Package (GAP). It allows you to create each GIMP layer as a frame and export it as an animation. This is great, but what if you wanted the flexibility of vector graphics while designing your frames? That's where this tutorial comes in. You can use Inkscape to create the frames, ImageMagick to stitch them together into a gif animation, and ffmpeg (or avconv) to create a video from them.

So let's begin.

0. Requirements

You will need the following:

You will also also need a Linux or UNIX based operating system, any where all of these programs work, and a lack of fear of the command line.

1. Creating frames

Drawing frames in a vector graphics program such as Inkscape gives you some amount of extra flexibility, and makes it easier and quicker to draw cool things. As we go along we'll use my example, but your animation can be anything you can imagine.

First we need to create a background of the size which we want our final animation to be. Let's make it 220x180 px here. Just draw a square, select it and in your "W" (width) and "H" (height) areas enter "220.000" and "180.000" respectively. The ".000" are to make sure that it is exactly of that size.

You can make the background of any color or gradient you wish. Here is mine.

Animation Background

It's probably a good idea to export this square as the first frame of your animation. It is best to create a folder in a convenient place called something like "animation", and export all your frames there as files named by a number. So the first frame can be a frame "0" and should be exported as 0.png.

To do an export click on the square and go to File > Export bitmap. In the dialog that pops up make sure a "selection" tab is pressed and use the browse button to browse to the location you wish to save your frames in (that would be the animation folder mentioned above) and the file name you wish to save it under (0.png). Once you're done with the browse dialog click the "export" button.

Export bitmap dialog

Treat the background square just created as a stage. Anything that is positioned within that square is what will appear in the animation. That said, now we have to introduce the object that we want to be in the animation first which can be an image, text, a drawing etc. You can create this object by drawing or typing it yourself or you can import an existing one.

For this animation let's start with a blue circle without fill color and with a fairly fat stroke paint (border), like this:

Blue circle

Great. Now what I would like to do in this animation is for this circle to draw itself. The way we can accomplish that is by selecting the circle and switch to the "Edit paths by node" mode (second button on the left, or accessible by pressing F2). This will allow you to "undraw" the circle, so to speak, make only a desired part of it display. See the following image to get the idea.

Un-drawing a circle

"Un-drawing" it is basically setting it to the beginning position, where the circle is either not visible at all or only a very small part is visible. Export this as the next frame using the exact same process as above for the background square. Even this time, as for every other frame, it is the background square that needs to be selected as you are exporting your frame. Then everything that is within it will be exported as too.

I think you might already be getting the idea of where this is going. For the next frame you reveal a little more of the circle, export as frame 2.png and then draw a little more again and export as frame 3.png and so on until the full circle is complete. The less you reveal per step the more steps or frames it takes for your circle to be drawn and the smoother will its final animation be.

To make it less daunting though, you can leave the export bitmap dialog open all the while you're exporting, and then just change the number in the file name and hit export every time you make a modification to the circle (and reselect the background).

In this example, I'm going to make a fade in effect using Inkscape's opacity feature. Here's a next object we have here:

Shiny! What we're to do now is superimpose this shiny element over the now completed circle to get this:

Then select it, open "Fill and stroke" settings (Object > Fill and Stroke) and move the opacity slider to near zero and then export the frame as above again, continuing to count numbers in file names. So the idea is to move a slider a little further towards 100% and export as next frame.

So far we have a circle drawing itself and then starting to glow. Now you can write something in there, like your name or whatever you wish. I will write "Nuxified". You can use the same fade in effect with your text or you can make the typing effect by writing the first letter, exporting the frame, then the second, and so on. So, for example, first frame would be "N", then "Nu", then "Nux", then "Nuxi" etc.

The result of all this frame making and exporting should be a folder full of PNG files named from 0.png to XX.png, depending on how many you ended up making. The next step is to just put them together into an actual animation.

2. Sticking the frames together into an animation.

Open a terminal and go into the directory where your frames are. For example if your frames are in a folder called "animation" inside your home folder, just type this:

cd animation

Assuming you have the ImageMagick package installed all you need to do now is type something like this:

animate -coalesce -delay 9 0.png 1.png 2.png 3.png 4.png 5.png 6.png 7.png 8.png 9.png 10.png 11.png 12.png 13.png 14.png 15.png -delay 45 16.png -delay 9 17.png 18.png 19.png 20.png 21.png 22.png 23.png 24.png 25.png 26.png 27.png 28.png 29.png 30.png 31.png -delay 90 32.png

The -coalesce option is what sticks together the frame images specified. The -delay option sets how long should it pause between each frame, therefore setting the actual speed of the animation. Above it is set to "9", but you can experiment with your own values. After that we are specifying the frame files we want to stick together into an animation. This is where it helps that we have all the files named by a number. You can use tab completion to string them together faster, and if you are trying multiple times you can use the up arrow to retry.

If the command is too big you can even select, copy and paste it into a text file where you can more easily tamper with it and then paste it back into the terminal for exection. You can even make it into a script, in which case you'd basically just have to save it as a, make it executable (chmod +x and execute it as ./ (assuming you're executing it from the same directory).

Also notice the -delay 45 option before 16.png, -delay 9 after it, and -delay 90 before 32.png. This makes the frame 16 display five times longer, and the frame 32 ten times longer than the rest, which are set to -delay 9. The reason why -delay 9 displays again after 16.png is to return the delay setting back to 9 since the command will follow the last set delay. This allows you to control the flow of your animation.

An alternative way to control the flow is to just repeat a single frame multiple times. If you repeat the frame 16.png five times it will amount to -delay 45. This may in fact be a good idea if you want to convert this GIF into a video, as explained below, because then when you convert the GIF back to PNG it will instantly output each of the repeating frames as a new frame (in this example a total of 45) that can then be easily put together into a video. So this is what such a command in this example would look like:

animate -coalesce -delay 9 0.png 1.png 2.png 3.png 4.png 5.png 6.png 7.png 8.png 9.png 10.png 11.png 12.png 13.png 14.png 15.png 16.png 16.png 16.png 16.png 16.png 17.png 18.png 19.png 20.png 21.png 22.png 23.png 24.png 25.png 26.png 27.png 28.png 29.png 30.png 31.png 32.png 32.png 32.png 32.png 32.png 32.png 32.png 32.png 32.png 32.png

Whichever command you choose to run, once you run it, after a little while it will show the final animation in a window. To save it as a GIF file just click on that window and an ImageMagick window menu will appear.

ImageMagick window

Click animate and choose "save", and in the browse window that appears select location where to save, and the file name, and then click the "format" button to bring up the format selection dialog.

ImageMagick window

Choose GIF and click select. Make sure your file name ends in .gif and then click save. ImageMagick should render the GIF animation to the location you specified.

And here it is:

Nuxified animation

3. Converting to video

Finally, we can use the same frames we've created to make a video of the same animation. Then it can be used as a piece of a larger video. In this example the animation is basically a simple logo, so we can imagine it being shown at the beginning or the end of a larger video presentation.

To stitch these PNG files into a video we can use this ffmpeg command in the same directory:

ffmpeg -r 24 -i %01d.png -an nuxified.avi

The -r 24 option sets the frame rate (hence the -r), and 24 stands for 24 frames per second (FPS), which means that 24 of our 33 frames (including 0.png) will be displayed in one second. The -i represents the input location. The -an means there's no audio to be added. And the %01d within the file name just means it will match files 0.png to 32.png whereas if it was set to %02d it would match 00.png to 32.png (2 numerical places in the file name).

You might notice that this doesn't set different delays to different frames like in the gif file. A way to get around that is to use the second animate command above where we create the GIF, in which we repeat frames rather than adding custom delays to them, and then use the following command to split the GIF back into PNG files:

convert nuxified.gif nuxified%02d.png

This will output each of the repeating frames as its own PNG file, in this example resulting in 45 PNG files rather than only 32 that there were initially. That's because now the repeating frames from the GIF have their own file. Now we can run the command to create a video out of those new PNG files:

ffmpeg -r 24 -i %02d.png -an nuxified.avi

And there it goes, a video with the built in delays we wanted!

Now you can use some video editing tool to add sound to it or even put it in a larger video that you might be making. For instance, the first half of this video was done using the exact method described here. It was merged together with other parts using kdenlive. Other great video editing tools include PiTiVi and OpenShot.

Updated and republished on June 1. 2014.


I recommend making the

I recommend making the jpegs directly from the pngs. If your original contains more than 256 different colors (which is very likely with gradients), the conversion to gif format will cause quality loss.

Also, (I didn't test this) ffmpeg appears to accept png files as input. As you probably know conversion to jpeg causes quality loss too...

lots of info

Now that I think of it,

Now that I think of it, that might be possible while still allowing a given frame to last longer, which was above accomplished by repeating a PNG file input into animate.. Basically I'd just have to create multiple of the same JPEG's from before putting them together. So yeah, you're right, though that seems to be a little more daunting because then you can't have jpegs autogenerated and have to do more manually.

About using PNGs as input directly to ffmpeg, one thing I wonder is if you can repeat a single PNG multiple times like I do to the animate command (so that the frame lasts longer).

Anyway, I might experiment with it and I'll check out that link.

Thanks for the tips! Smiling

Interesting tutorial. I


Interesting tutorial. I took a slightly different approach with Inkscape animations. Although my screencast was recorded on Windows everything should work just fine on Linux.

Link to my screencast (You can download the avi or click the monitor image to watch the flash)

Link to swftools

There is also a tool called AnimEasy which adds animation functionality to Inkscape.

Link to AnimEasy

There's absolutely nothing wrong with your tutorial but perhaps you might be interested in other ways to achieve the same thing. You can use FFMpeg to convert the swf to avi if you would like. Smiling

Hi Heathenx, sorry for the

Hi Heathenx, sorry for the delayed response. I watched the screencast and I like your method as well. It might actually be a way to create animations with less quality loss. I'm gonna try it out next time I do an animation.

Your screencasts site is pretty cool. I'm gonna check some more of them out.

AnimEasy also sounds great, thanks for the links! Smiling



I saw some coments on how to do to a frame last longer than others. And i found i easy way to do it. Whenever you want to do it you just put -delay, and a specific time, longer than the first one in front of the frame. From this frame on all the others will last this specific and longer time. And if you want to your frames return to the previous time, you just use the same comand. like this:

animate -coalesce -delay 9 0.png 1.png 2.png 3.png 4.png -delay 45 5.png 6.png 7.png - this way 5.png 6.png and 7.png - will last 5 times more than the first four frames

animate -coalesce -delay 9 0.png 1.png 2.png 3.png 4.png -delay 45 5.png -delay 9 6.png 7.png - this way 5.png will last time more than all the others.

I really enjoyed this way of doing animations,

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.