Skip to main content

ffmpegio plugin to create videos from matploglib Figures

Project description

PyPI PyPI - Status PyPI - Python Version GitHub License GitHub Workflow Status

This plugin enables Python ffmpegio package to output matplotlib’s Figure.

Installation

To enable it, install along with ffmpegio-core or ffmpegio package:

pip install ffmpegio-core # or ffmpegio if also performing media I/O
pip install ffmpegio-plugin-mpl

The plugin will be automatically loaded whenever ffmpegio package is imported.

Example

Create an MP4 video of Matplotlib’s animation example.

import ffmpegio
from matplotlib import pyplot as plt
import numpy as np


fig, ax = plt.subplots()

x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))

interval=20 # delay in milliseconds
save_count=50 # number of frames

def animate(i):
    line.set_ydata(np.sin(x + i / 50))  # update the data.
    return line


with ffmpegio.open(
  "output.mp4", # output file name
  "wv", # open file in write-video mode
  1e3/interval, # framerate in frames/second
  pix_fmt="yuv420p", # specify the pixel format (default is yuv444p)
) as f:
    for n in range(save_count):
        animate(n) # update figure
        f.write(fig) # write new frame

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ffmpegio-plugin-mpl-0.1.1.tar.gz (10.3 kB view hashes)

Uploaded Source

Built Distribution

ffmpegio_plugin_mpl-0.1.1-py3-none-any.whl (10.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page