Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the image resolution for animations?

how can I set the resolution of an animation saved as mp4 movie with "matplotlib.animation" module?

On the web I only found examples using "animation.FuncAnimation". For example the nice tutorial from http://jakevdp.github.com/blog/2012/08/18/matplotlib-animation-tutorial/ used:

anim = animation.FuncAnimation(fig, animate, init_func=init,
                           frames=200, interval=20, blit=True)
anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])

From the matplotlib.animation module reference I found the "animation.Animation.save" method providing a "dpi"-argument, but I don't know how to apply this function properly

matplotlib.animation.Animation.save(filename, writer=None, fps=None, dpi=None, codec=None, bitrate=None, extra_args=None, metadata=None, extra_anim=None)

A small example code may be helpful.

Many thanks.

Johannes

PS: By the way, how can you insert Python-code with sytax-highlighting?

like image 711
mr_endres Avatar asked Feb 02 '13 20:02

mr_endres


People also ask

What resolution should I use for animation?

Animation resolutions should be 720 x 480, 960 x 540 or 1280 x 720 pixels. Still image resolutions should be minimum of 1920 x 1080 pixels – larger preferred for printing purposes up to 4k size.

What does resolution mean in animation?

The resolution is the number of pixels that a screen can show. For example, a screen with a resolution of 720p will show 720 pixels vertically. At LiFang, all of our renderings come standard at 4K resolution and animation come standard 720p resolution, great for most marketing purposes.

How do you determine image resolution?

Image resolution is typically expressed as a horizontal x vertical measurement. So, an image resolution of 6000 x 4000 tells us that the image measures 6000 pixels in width and 4000 pixels in height. Multiplying the two figures together gives us the second way this is commonly stated, namely as megapixels.


2 Answers

You can control the resolution in a round-about way. The resolution, figure size, and dpi are not all independent, if you know two of them, then the third is fixed.

You can set the dpi in the save argument, and before you save it, set the size of the figure with

fig.set_size_inches(w_in_inches, h_in_inches, True). 

Your resolution is then dpi * w_in_inches X dpi * h_in_inches.

dpi = 100
writer = animation.writers['ffmpeg'](fps=30)
ani.save('test.mp4',writer=writer,dpi=dpi)

You may need do upgrade to a newer version of mpl (debian is great because it is so conservative and awful because it is so conservative) from source.

like image 107
tacaswell Avatar answered Sep 29 '22 17:09

tacaswell


bitrate is the parameter used to specify the quality of a movie. The higher the value you set it to, the higher the quality of the movie will be.

like image 31
David Avatar answered Sep 29 '22 17:09

David