Gnuplotting

Create scientific plots using gnuplot

February 3rd, 2012 | 6 Comments

In the first post regarding animations we have created a bunch of png files and combined them to a single gif animation. Now we want to generate again a bunch of png files, but combine them to a movie.

Fig. 1 Video animation of Huygens principle (code to produce this figure, loop function)

We create the png files in analogy to the gif example, hence we will discuss only the generation of the movie here. In order to compose a avi file from the png files we are using Mencoder. Gnuplot is able to directly start Mencoder by its system command.

# Create movie with mencoder
ENCODER = system('which mencoder');
if (strlen(ENCODER)==0) print '=== mencoder not found ==='; exit
CMD = 'mencoder mf://animation/*.png -mf fps=25:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o huygen.avi'
system(CMD)

The first two lines check if Mencoder is available and quit gnuplot if not. The Mencoder command itselfs gets the directory containing the png files mf://animation/*.png, frames per second and input type-mf fps=25:type=png, video -ovc and audio -oac options, and finally of course the output file -o huygen.avi.

In order to generate a webm video file for a web site, ffmpeg can be used to convert the video.

$ ffmpeg -i huygen.avi huygen.webm

6 Comments

  1. Jose Nicolas says:

    This animation series has been extremely helpful. Thank you so much for sharing!

  2. Gabriele says:

    Hi, is there any package needed to call sprintf?

  3. Navneet says:

    I am doing a simulation in which,no of lattice points are increasing with time, is there any method in gnuplot animations so that, i can see the evolution of the lattice with no. of points increasing in it ?

  4. Arthur says:

    Nothing happens when I try to change the frame rate – that is, changing “fps=25” to “fps=3” does absolutely nothing. The .avi video is made at a set frame rate that I can’t seem to change. Any advice?

  5. Arthur says:

    Edit (to initial comment above): I found that the problem was that I deleted “mf://” before “*.png”. As soon as I included that again it worked.

  6. Maxi says:

    Hello, I was trying this but ran into problems with installing mencoder on Windows 10. I struggled through all the readmes and help documents, but it seems I am too stupid to get this running. I have the the source and the codecs unpacked in a “mencoder” folder in :C//. What do I have to do that the Program will be found by Windows, so that the given code works?