Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set ffmpeg for matplotlib in mac os x

I want to animate some plots with matplotlib. The version I have is the Enthough Canopy distribution (Version: 1.1.0.1371), running in a mac os x 10.8 (Mountain Lion). I have used the FuncAnimation routine from the animation package of matplotlib. My problem comes saving the animation. I want to save in mp4 format:

anim.save('test.mp4',fps=30)

The error I get is:

UserWarning: MovieWriter ffmpeg unavailable 
warnings.warn("MovieWriter %s unavailable" % writer)

So I installed ffmpeg via Macports. But I am still having the same error. Do you know how to setup matplotlib in order to recognise ffmpeg? Do I have to change the matplotlibrc file? Thanks.

EDIT: I have realized that I can manually put '/opt/local/bin' in the PYTHONPATH, but it does not change the PATH in Enthough Canopy. Do anyone know how to change the PATH in canopy?

like image 200
AlexNoir Avatar asked Sep 16 '13 17:09

AlexNoir


People also ask

Where is Ffmpeg Mac?

Go to https://ffmpeg.org/download.html and click the Apple logo in the "Get packages & executable files" section. Click "Static builds for macOS 64-bit". You'll see two options for downloading ffmpeg.

How to enable FFmpeg for Matplotlib animation?

To enable ffmpeg for matplotlib.animation, we can take the following steps − Set the figure size and adjust the padding between and around the subplots. Set the ffmpeg directory. Create a new figure or activate an existing figure, using figure () method. Add an 'ax1' to the figure as part of a subplot arrangement.

How to plot random data on a 2D image using FFmpeg?

Set the ffmpeg directory. Create a new figure or activate an existing figure, using figure () method. Add an 'ax1' to the figure as part of a subplot arrangement. Plot the divider based on the pre-existing axes. Create random data to be plotted, to display the data as an image, i.e., on a 2D regular raster.

How do I install FFmpeg on Ubuntu?

All you need to do is execute the FFmpeg installation command. You can also get the installation command from this Github page. Just copy the code from the second line, paste it in your Homebrew terminal and hit enter. That’s it!

How to add an 'Ax1' to an existing figure using FFmpeg?

Set the ffmpeg directory. Create a new figure or activate an existing figure, using figure () method. Add an 'ax1' to the figure as part of a subplot arrangement.


3 Answers

I had the same problem. My solution was very simple.

Download the binary from here.

Then do

sudo mv ~/Downloads/ffmpeg /usr/bin/
like image 72
user2158166 Avatar answered Nov 16 '22 02:11

user2158166


I had success when installing with homebrew: brew install ffmpeg

After that set up the FFMpegWriter yourself by:

mywriter = animation.FFMpegWriter()
anim.save('mymovie.mp4',writer=mywriter)
like image 31
JnBrymn Avatar answered Nov 16 '22 02:11

JnBrymn


I think the solution can be found in the workaround in this and this post.

It seems that the path of the shell is not loaded by matplotlib, and since macports are installed in /opt/local/bin, ffmpeg can't be found.

Either go for the hack described above, try making a symlink in /bin for ffmpeg, or try adding the path to ffmpeg to the python path as suggested in the comments of the second link

like image 24
gg349 Avatar answered Nov 16 '22 02:11

gg349