Thanks to visit codestin.com
Credit goes to github.com

Skip to content

animation with 'ffmpeg' backend and 'savefig.bbox = tight' garbles video #6416

Closed
@chipmuenk

Description

@chipmuenk

Using

Setting savefig.bbox = tight either in matplotlibrc or as an rcParam garbles an mp4 video written by ffmpeg. Even starting the script with --verbose-debug gives no warning or message that something might be wrong.

I also cannot change the frame rate - neither interval nor fps has any effect, I always get 5 fps (this is consistent with the options passed to ffmpeg which always says '-r 5').

Example (slightly modded) taken from
https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/ :

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

plt.rcParams['animation.ffmpeg_path'] = 'D:/Programme/ffmpeg/bin/ffmpeg.exe'
plt.rcParams['savefig.bbox'] = 'tight'     # tight garbles the video!!!

movie_file = 'D:/Daten/basic_animation.mp4'
mywriter = animation.FFMpegWriter()

fig = plt.figure()
fig.set_size_inches(4, 5, True)
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)

def init():
    line.set_data([], [])
    return line,

def animate(i):
    x = np.linspace(0, 2, 1000)
    y = np.sin(2 * np.pi * (x - 0.01 * i))
    line.set_data(x, y)
    return line,

anim = animation.FuncAnimation(fig, animate, init_func=init,
                               interval = 1000, frames = 20, blit=True)

anim.save(movie_file, dpi=100, fps = 30, writer=mywriter, 
          extra_args=['-vcodec', 'libx264'])

plt.show()

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions