moviepy TextClipでエラーになる (2021/01/01)

Top

MoviePyでTextClipを使うのは、結構大変だった! こんなエラーがでたら!

OSError: MoviePy Error: creation of None failed because of the following error:

[WinError 2] 指定されたファイルが見つかりません。

This error can be due to the fact that ImageMagick is not installed on your computer, 
or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, 
or that the path you specified is incorrect
>>> txt_clip = TextClip("testMoji")
Traceback (most recent call last):
  File "C:\Users\kobay\AppData\Local\Programs\Python\Python38\lib\site-packages\moviepy\video\VideoClip.py", line 1137, in __init__
    subprocess_call(cmd, logger=None)
  File "C:\Users\kobay\AppData\Local\Programs\Python\Python38\lib\site-packages\moviepy\tools.py", line 46, in subprocess_call
    proc = sp.Popen(cmd, **popen_params)
  File "C:\Users\kobay\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\kobay\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Users\kobay\AppData\Local\Programs\Python\Python38\lib\site-packages\moviepy\video\VideoClip.py", line 1146, in __init__
    raise IOError(error)
OSError: MoviePy Error: creation of None failed because of the following error:

[WinError 2] 指定されたファイルが見つかりません。.

.This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
    moviepyの設定ファイルの場所
    フォルダ C:\Users\ユーザー名\AppData\Local\Programs\Python\Python38\Lib\site-packages\moviepy
    ファイル config_defaults.py
    
    ここのにIMAGEMAGICK_BINARYを設定し直す
    
    
    import os

    FFMPEG_BINARY = os.getenv('FFMPEG_BINARY', 'ffmpeg-imageio')
    IMAGEMAGICK_BINARY = os.getenv('IMAGEMAGICK_BINARY', 'auto-detect')
    
    ここに、IMAGEMAGICK_BINARYの設定をやり直す
    

先に結論から、portableを
使うといい感じ!(その他ではできなかった)

「portableとは、インストーラなしのstatic版」

DLL版では、convert.exeがあったが、動かすと落ちてしまった
static版では、convert.exeがない


そして、
修正方法は、2つあり

config_defaults.pyでIMAGEMAGICK_BINARYのパスを修正

2番目は、プログラムの先頭に2行挿入
もちろん、参照先のホルダーは自分がインストールした場所(convert.exeがあるか確認!)

<<挿入するもの>>
    import os    
    os.environ["IMAGEMAGICK_BINARY"] = "/Users/kobay/Downloads2/ImageMagick-7.0.10-52-portable-Q16-HDRI-x64/convert.exe"
あれあれ!
今日は、令和3年(2021年)の元旦ですが

以下によると(2017年だけど)
バージョンは、 ImageMagick-7.0.4-Q16なので(現在(2021年) ImageMagick-7.0.10-Q16)

ウインドウズは、
convert.exeがインストールされていないので、magick.exeにしてもできるようです。
(convert.exeのコマンドが衝突する為の配慮かな?)







https://github.com/Zulko/moviepy/issues/378
    Windows: specifying path to ImageMagick in config_defaults.py #378
     Closed
    WDBell opened this issue on 4 Jan 2017 · 8 comments
     Closed
    Windows: specifying path to ImageMagick in config_defaults.py
    #378
    WDBell opened this issue on 4 Jan 2017 · 8 comments
    Comments
    @WDBell
    WDBell commented on 4 Jan 2017
    IMAGEMAGICK_BINARY
        For linux users, 'convert' should be fine.
        For Windows users, you must specify the path to the ImageMagick
        'convert' binary. For instance:

        IMAGEMAGICK_BINARY = r"C:\Program Files\ImageMagick-6.8.8-Q16\convert.exe"

    """

    FFMPEG_BINARY = 'ffmpeg-imageio'
    #~ IMAGEMAGICK_BINARY = 'auto-detect'
    IMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick-7.0.4-Q16\\magick.exe"
    The final few lines of config_defaults.py indicate how the location of ImageMagick should be specified for use by moviepy. However, 
    often when Image ImageMagick is installed these days (apparently with versions numbered 7x) convert.exe is not included. 
    Fortunately, ImageMagick can be specified as shown here.

    Suggest change to config_defaults.py.
    
日本語
    WDBellは2017年1月4日にコメントしました
    IMAGEMAGICK_BINARY
         Linuxユーザーの場合、「convert」で問題ありません。
         Windowsユーザーの場合、ImageMagickへのパスを指定する必要があります
         バイナリを「変換」します。 例えば:

         IMAGEMAGICK_BINARY = r "C:\ Program Files \ ImageMagick-6.8.8-Q16 \ convert.exe"

    "" "

    FFMPEG_BINARY = 'ffmpeg-imageio'
    #〜IMAGEMAGICK_BINARY = '自動検出'
    IMAGEMAGICK_BINARY = "C:\\ Program Files \\ ImageMagick-7.0.4-Q16 \\ magick.exe"
    config_defaults.pyの最後の数行は、
    moviepyで使用するためにImageMagickの場所を指定する方法を示しています。 
    ただし、最近Image ImageMagickがインストールされている場合(明らかにバージョン番号が7xの場合)、
    convert.exeは含まれていません。 
    幸い、ImageMagickはここに示すように指定ができます。

    config_defaults.pyへの変更を提案します。
    

まとめ

ウインドウズ版について イメージマジックをインストール ImageMagick (https://imagemagick.org) ダウンロード ウインドウズ版のところにで、以下を参考に選んでダウンロードしてインストール ・win32, win64(自分のPCによる) ・static ・16 bits-per-pixel(こちらで) ImageMagick-7.0.10-53-Q16-x64-static.exe(PCが64ビットの場合) ImageMagick-7.0.10-53-Q16-x86-static.exe(PCが32ビットの場合) 以下のファイルを修正 フォルダ C:\Users\ユーザー名\AppData\Local\Programs\Python\Python38\Lib\site-packages\moviepy ファイル config_defaults.py 修正のやり方 IMAGEMAGICK_BINARYがある行をコメントして、インストールされた「magick.exe」を指定 # //IMAGEMAGICK_BINARY = os.getenv('IMAGEMAGICK_BINARY', 'auto-detect') IMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick-7.0.10-Q16\\magick.exe" 2番目の修正方法は、TextClipを使うプログラムの先頭にIMAGEMAGICK_BINARYのパスを設定するようにする しかし、config_defaults.pyを修正しておけば簡単ですね! ※古いバージョンでは、convert.exeが使われていたが、今は「magick.exe」で大丈夫という事ですね。 確認は、コマンドラインでpythonを入力して 以下を入力、エラーがでなけらばOKです。
from moviepy.editor import *
txt_clip = TextClip("abc")
参考URL I code therefore...(ImageMagick (1) インストール編)
©2020 Kenji Kobayashi YouTube