def get_exe(): """ Get ffmpeg exe """ # Is the ffmpeg exe overridden? exe = os.getenv('IMAGEIO_FFMPEG_EXE', None) if exe: # pragma: no cover return exe # Check if ffmpeg is in PATH try: with open(os.devnull, "w") as null: sp.check_call(["ffmpeg", "-version"], stdout=null, stderr=sp.STDOUT) return "ffmpeg" # ValueError is raised on failure on OS X through Python 2.7.11 # https://bugs.python.org/issue26083 except (OSError, ValueError, sp.CalledProcessError): pass plat = get_platform() # Check if ffmpeg is installed in Python environment # (e.g. via conda install ffmpeg -c conda-forge) exe = None if plat.startswith('win'): exe = os.path.join(sys.prefix, 'Library', 'bin', 'ffmpeg.exe') else: exe = os.path.join(sys.prefix, 'bin', 'ffmpeg') # Does the found Python-ffmpeg work? if exe and os.path.isfile(exe): try: with open(os.devnull, "w") as null: sp.check_call([exe, "-version"], stdout=null, stderr=sp.STDOUT) return exe except (OSError, ValueError, sp.CalledProcessError): pass # Finally, try and use the executable that we provide if plat and plat in FNAME_PER_PLATFORM: try: exe = get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat], auto=False) os.chmod(exe, os.stat(exe).st_mode | stat.S_IEXEC) # executable return exe except NeedDownloadError: raise NeedDownloadError('Need ffmpeg exe. ' 'You can obtain it with either:\n' ' - install using conda: ' 'conda install ffmpeg -c conda-forge\n' ' - download by calling: ' 'imageio.plugins.ffmpeg.download()') except InternetNotAllowedError: pass # explicitly disallowed by user except OSError as err: # pragma: no cover logging.warning("Warning: could not find imageio's " "ffmpeg executable:\n%s" % str(err)) # Fallback, let's hope the system has ffmpeg return 'ffmpeg'
def download(): """ Download the ffmpeg exe to your computer. """ plat = get_platform() if not (plat and plat in FNAME_PER_PLATFORM): raise RuntimeError("FFMPEG exe isn't available for platform %s" % plat) get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat])
def get_avbin_lib(): """ Get avbin .dll/.dylib/.so """ LIBRARIES = { 'osx64': 'libavbin-11alpha4-osx.dylib', 'win32': 'avbin-10-win32.dll', 'win64': 'avbin-10-win64.dll', 'linux32': 'libavbin-10-linux32.so', 'linux64': 'libavbin-10-linux64.so', } platform = get_platform() try: lib = LIBRARIES[platform] except KeyError: # pragma: no cover raise RuntimeError('Avbin plugin is not supported on platform %s' % platform) return get_remote_file('avbin/' + lib)
def test_util_get_platform(): # Test get_platform platforms = "win32", "win64", "linux32", "linux64", "osx32", "osx64" assert core.get_platform() in platforms
def test_util_get_platform(): # Test get_platform platforms = 'win32', 'win64', 'linux32', 'linux64', 'osx32', 'osx64' assert core.get_platform() in platforms