Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving animation with mencoder fails if bitrate is specified #4003

Closed
pupssman opened this issue Jan 15, 2015 · 8 comments
Closed

Saving animation with mencoder fails if bitrate is specified #4003

pupssman opened this issue Jan 15, 2015 · 8 comments
Assignees

Comments

@pupssman
Copy link
Contributor

Here is a basic test script:

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

fig = plt.figure()

ax = plt.axes()

patch = plt.Circle((0, 0), 0)


def update(i):
    patch.set_radius(np.sin(np.radians(i)))


def init():
    ax.add_patch(patch)

ani = animation.FuncAnimation(fig, update, init_func=init, interval=10, frames=100)

ani.save('1.mp4', writer='mencoder_file', fps=25, bitrate=500)

It crashes as follows:

Traceback (most recent call last):
  File "/home/pupssman/git/ado-ft/ado/tests/a.py", line 21, in <module>
    ani.save('1.mp4', writer='mencoder_file', fps=25, bitrate=500)
  File "/home/pupssman/venv/pytest/local/lib/python2.7/site-packages/matplotlib/animation.py", line 752, in save
    writer.grab_frame(**savefig_kwargs)
  File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__
    self.gen.next()
  File "/home/pupssman/venv/pytest/local/lib/python2.7/site-packages/matplotlib/animation.py", line 177, in saving
    self.finish()
  File "/home/pupssman/venv/pytest/local/lib/python2.7/site-packages/matplotlib/animation.py", line 365, in finish
    + ' Try running with --verbose-debug')
RuntimeError: Error creating movie, return code: 1 Try running with --verbose-debug

Verbose reveals that it generates following command:

MovieWriter.run: running command: mencoder mf://_tmp*.png -frames 100 -mf type=png:fps=25 -o 1.mp4 -ovc lavc -lavcopts vcodec=mpeg4 vbitrate=500

And MEncoder fails with:

MEncoder 1.1-4.8 (C) 2000-2012 MPlayer Team
  ...
File not found: 'vbitrate=500'
Failed to open vbitrate=500.
Cannot open file/device.
 ...

And all the docs about MEncoder specify that mencoder's lavcopts should be given joined via :, as in http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-libavcodec.html:

-lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:autoaspect:vpass=1

Looks like the problem in with this bit of code (animation.py's MencoderBase):

        args = ['-o', self.outfile, '-ovc', 'lavc', '-lavcopts',
                'vcodec=%s' % self.codec]
        if self.bitrate > 0:
            args.append('vbitrate=%d' % self.bitrate)

Changing this to following fixes the failure:

        lavcopts = {'vcodec': self.codec}
        if self.bitrate > 0:
            lavcopts.update(vbitrate=self.bitrate)

        args = ['-o', self.outfile, '-ovc', 'lavc', '-lavcopts', ':'.join(itertools.starmap('{0}={1}'.format, lavcopts.items()))]

Could anyone of maintainers plz look into the issue and say if this is a proper fix? I would be glad to send a PR.

@mavlyutov
Copy link

this!

@WeatherGod
Copy link
Member

neat little trick with starmap. Never used it before. Yeah, please do
submit a PR. We probably did not fully test this when we originally made
it. I think we even have some smoke tests that may benefit from exercising
this option.

On Thu, Jan 15, 2015 at 10:55 AM, Marat Mavlyutov notifications@github.com
wrote:

this!


Reply to this email directly or view it on GitHub
#4003 (comment)
.

@tacaswell
Copy link
Member

Please send a PR.

Did memcoder change their CLI interface? Did our memconder writer just never work?

attn @dopplershift @WeatherGod

@WeatherGod
Copy link
Member

The default bitrate is -1, which just means to let the encoder
auto-determine the bitrate. We probably just never exercised this codepath.

On Thu, Jan 15, 2015 at 11:15 AM, Thomas A Caswell <notifications@github.com

wrote:

Please send a PR.

Did memcoder change their CLI interface? Did our memconder writer just
never work?

attn @dopplershift https://github.com/dopplershift @WeatherGod
https://github.com/WeatherGod


Reply to this email directly or view it on GitHub
#4003 (comment)
.

@tacaswell
Copy link
Member

Sorry, my last comment comes across as way more hostile than I intended. My worry is that memconder has changed their CLI and by fixing it here, we well break it for users with older version of memcoder.

There are some animation smoke tests and the memcoder versions are marked as knownfail (https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/tests/test_animation.py#L37) so that should probably be addressed.

@pupssman
Copy link
Contributor Author

I did look a bit throught the mencoder doc and found no trace of another cmd format. Do you guys have a CI environment for one to find the latest successful launch of this test?

@tacaswell
Copy link
Member

The smoke test running on travis were added in #2679 as far as I know the answer to the last time it passed in a CI environment is 'never' .

dopplershift added a commit to dopplershift/matplotlib that referenced this issue Jan 15, 2015
This should help catch more problems in commandline argument handling,
like matplotlib#4003.
@dopplershift dopplershift self-assigned this Jan 15, 2015
@tacaswell
Copy link
Member

Closed as #4004 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants