Skip to content

Unclear error when saving Animation using FFMpeg #12357

Closed
@AJJLagerweij

Description

@AJJLagerweij

Bug report

Bug summary

Something goes wrong when I try to use the FFMpeg writer to write an animation. It used to work for me a couple of weeks ago and the error does not help to much either.

Code for reproduction

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

writer = anim.FFMpegWriter(fps=30, codec='libx264')

fig = plt.figure()
l, = plt.plot([], [], 'k-o')

plt.xlim(-5, 5)
plt.ylim(-5, 5)

x0, y0 = 0, 0

with writer.saving(fig, "writer_test.mp4", 100):
    for i in range(100):
        x0 += 0.1 * np.random.randn()
        y0 += 0.1 * np.random.randn()
        l.set_data(x0, y0)
        writer.grab_frame()

Actual outcome

 Traceback (most recent call last):

  File "<ipython-input-19-d9a5977378d9>", line 1, in <module>
    runfile('/home/bram/Documenten/TUDelft/Thesis/Phyton/test.py', wdir='/home/bram/Documenten/TUDelft/Thesis/Phyton')

  File "/home/bram/.anaconda3/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

  File "/home/bram/.anaconda3/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/bram/Documenten/TUDelft/Thesis/Phyton/test.py", line 31, in <module>
    writer.grab_frame()

  File "/home/bram/.anaconda3/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)

  File "/home/bram/.anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 232, in saving
    self.finish()

  File "/home/bram/.anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 358, in finish
    self.cleanup()

  File "/home/bram/.anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 395, in cleanup
    out, err = self._proc.communicate()

  File "/home/bram/.anaconda3/lib/python3.6/subprocess.py", line 843, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)

  File "/home/bram/.anaconda3/lib/python3.6/subprocess.py", line 1505, in _communicate
    selector.register(self.stdout, selectors.EVENT_READ)

  File "/home/bram/.anaconda3/lib/python3.6/selectors.py", line 351, in register
    key = super().register(fileobj, events, data)

  File "/home/bram/.anaconda3/lib/python3.6/selectors.py", line 237, in register
    key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)

  File "/home/bram/.anaconda3/lib/python3.6/selectors.py", line 224, in _fileobj_lookup
    return _fileobj_to_fd(fileobj)

  File "/home/bram/.anaconda3/lib/python3.6/selectors.py", line 39, in _fileobj_to_fd
    "{!r}".format(fileobj)) from None

ValueError: Invalid file object: <_io.BufferedReader name=55>

Expected outcome

I expect to obtain an .mp4 file which shows all the plots at 30fps. It does not do anything except giving the ValueError: Invalid file object: <_io.BufferedReader name=55> error. I might have used an older matlabcode previously but am not sure, I therefore tried an older version with conda but it did not help, it resulted in the same error.

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 3.0.0 (from anaconda)
  • Matplotlib backend: Qt5Agg
  • Python version: 3.6.6
  • Other libraries: ffmpeg 3.4.1 and 4.0.2, x264

I use conda to manage my environment using the default channel, for ffmpeg I tried both the standard and conda-forge channel.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions