MoviePY UTF8 Error

时间:2017-08-04 12:19:35

标签: python utf-8 encode moviepy

I looked around before posting but the solution given here doesn't work :

moviepy stackOF solution

I use python 2.7.13 with ImageMagick-7.0.6-Q16

My code is like this :

# -*- coding: utf-8 -*-
#Installation de FFMPG.EXE s'il n'est pas déja installé
    try:
        import imageio
        imageio.plugins.ffmpeg.download()
    except Exception as e:
        print e.__doc__
        print e.message
    else:
        print u"FFMPG.EXE déjà installé"

from moviepy.editor import TextClip

txtclip = TextClip('TestText', fontsize=50, color='red')
txt_image = txtclip.get_frame(0)

i get this error :

=== RESTART: C:\Users\wanli\Desktop\Training python\Montage vidéo\Timo.py     ===
FFMPG.EXE déjà installé

[MoviePy] This command returned an error !
Traceback (most recent call last):
File "C:\Users\wanli\Desktop\Training python\Montage vidéo\Timo.py", line 14, in <module>
txtclip = TextClip('TestText', fontsize=50, color='red')
File "C:\Python27\lib\site-packages\moviepy\video\VideoClip.py", line 1220, in __init__
subprocess_call(cmd, verbose=False )
File "C:\Python27\lib\site-packages\moviepy\tools.py", line 50, in subprocess_call
raise IOError(err.decode('utf8'))
File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 202: invalid continuation byte 

I tried to make my TextClip like :

mytext="TestText"
mytext_utf=mytext.encode('utf8')
txtclip = TextClip(mytext_utf, fontsize=50, color='red')

But it doesn't work...

I also tried to go in

C:\Python27\Lib\site-packages\moviepy\video\VideoClip.py

I went to line 1173

if txt is not None:

I added on line 1174 :

txt.encode('utf8')

It doesn't work either...

I ALWAYS get this UTF8 error ! This is driving me crazy ! :)

Thanks for helping me to understand ! :)

2 个答案:

答案 0 :(得分:1)

Ok i solved this was not about my text but about the PATH where my ".py" file is....

"C:\Users\wanli\Desktop\Training python\Montage vidéo\Timo.py"

I changed it to :

"C:\Users\wanli\Desktop\Training python\Montage video\Timo.py"

No more error....

答案 1 :(得分:0)

In moviepy/tools.py, line 49 (well that's line 49 in the current master branch at least), replace this:

raise IOError(err.decode('utf8'))

with

raise IOError(err.decode('utf-8', 'replace')

or simply:

raise IOError(err)

This won't solve the underlying problem but at least you should will get the original error message, even if somewhat garbled.

You may also want to post a bug report on the project's git - decoding from any arbitrary encoding is a mistake in itself.