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

Setting conf.py ffmpeg path on the fly from python #66

Closed
bobatsar opened this issue Sep 24, 2014 · 5 comments
Closed

Setting conf.py ffmpeg path on the fly from python #66

bobatsar opened this issue Sep 24, 2014 · 5 comments

Comments

@bobatsar
Copy link
Contributor

Hi there,

at the moment it is not possible to modify the FFMPEG_BINARY or IMAGEMAGICK_BINARY from a running python environment. The only way to modify it is to hardcode it in the conf.py or set the PATH environment to let it find the binaries automaitcally.

The problem ist when trying to bundle an application with cx_freeze as Win32Gui (without console) app. In that case os.environ["PATH"] is ignored and the binaries can not be found. If bundled as a console app, the binaries can be found by appending the ffmpeg path to os.environ["PATH"].

The problem is, that conf.py can not be loaded and modified if ffmpeg can not be found.

A possible soultion would be not to raise the IOError.
Then it is possible to import first only moviepy.conf and modify it on the fly:

import moviepy.conf as movieconf
movieconf.FFMPEG_BINARY = os.path.join("my_path", "ffmpeg", "ffmpeg.exe")

All calls to moviepy after setting the path now work.

Additionally there could be a function to get the FFMPEG path for other moviepy modules.

def get_mffpeg_binary():
    if not try_cmd(FFMPEG_BINARY):
        raise IOError("FFMPEG binary not found...")
    return FFMPEG_BINARY

See also the pull request from @sanfx with the xml config which has the same target to not hardcode the ffmpeg paths.

@Zulko
Copy link
Owner

Zulko commented Sep 24, 2014

Thanks for the insight. I didn't know you could change the content of "conf" at run time, this is really nice.

@bobatsar @sanfx would the following implementation be ok for you ?

It should work like this:

import moviepy.conf as mpy_conf
mpy_conf.change_settings({'FFMPEG_BINARY': my_custom_path,
                'IMAGEMAGICK_BINARY':my_other_custom_path})

You could make a personal configuration file my_conf.py like that:

FFMPEG_BINARY= my_custom_path
IMAGEMAGICK_BINARY = my_other_custom_path
#etc...

and you would use it like this:

conf.change_settings(file="path/to/my_conf.py")

Then there will also be a get_setting function which will be used everywhere where the configuration values are needed, like you suggested with get_ffmpeg_binary, so that errors will be raised at write_video time if for instance FFMPEG wasn't found and wasn't set manually.

I just need some time to ensure that the error messages stay informative in all cases.

@bobatsar
Copy link
Contributor Author

Hi Zulko,

yes that sounds good for me.
I don't understand why one would need additionally the my_conf.py variant but perhaps @sanfx knows a usage scenario for that.

Thanks for the great work

@Zulko
Copy link
Owner

Zulko commented Sep 25, 2014

Ok, that will be done. The advantage of using my_conf.py is that if the program gets big with many parameters in the configuration, then some user will have a favorite configuration file that they can use in all of their script. It's common practice with matplotlib, where you ca define a "stylesheet" for all your plots which is actually a configuration file.

@Zulko
Copy link
Owner

Zulko commented Oct 9, 2014

Done ! At least on Github, not yet on PyPi. See the new moviepy/config_defaults.py for the details.

@Zulko Zulko closed this as completed Oct 9, 2014
@PlanPh
Copy link

PlanPh commented Feb 26, 2015

Dear guys,

i tried to implement your solutions for this issue. But it wont work for me. I got the "[Error 2] The system cannot find the file specified".
my start-code:
import os
import moviepy.config as mpy_conf
mpy_conf.FFMPEG_BINARY = os.path.join("C:\Program Files (x86)\ImageMagick-6.9.0-Q16", "ffmpeg", "ffmpeg.exe")
from moviepy.editor import VideoFileClip, ImageSequenceClip

Is their any else to consider? What could be wrong?

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

No branches or pull requests

3 participants