Special characters/kanji problems using Python unicode
<p>I want to use videofileclip(), but a UnicodeDecodeError occurs.
The videofiles include japanese kanji or special characters.</p>

<p>My example code:</p>

<pre><code>#-*- coding: utf-8 -*-
import sys  
from moviepy.editor import VideoFileClip

reload(sys)  
sys.setdefaultencoding('utf-8')

a='H:\\kittens.mkv'
clip1=VideoFileClip(a)

b='H:\\âÄÄ«â â.mp4'
clip2=VideoFileClip(b)

if clip1.fps &gt;= clip2.fps:
    os.remove(b)
else:
    os.remove(a)        
</code></pre>

<p>'a' works fine:</p>

<pre><code>&gt;&gt;&gt; a='H:\\kittens.mkv'
&gt;&gt;&gt; clip=VideoFileClip(a)
&gt;&gt;&gt; 
</code></pre>

<p>but 'b' doesn't work:   </p>

<pre><code>&gt;&gt;&gt; b='H:\\âÄÄ«â â.mp4'
&gt;&gt;&gt; clip=VideoFileClip(b)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Python27\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 5
5, in __init__
    reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt)
  File "C:\Python27\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 3
2, in __init__
    infos = ffmpeg_parse_infos(filename, print_infos, check_duration)
  File "C:\Python27\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 2
70, in ffmpeg_parse_infos
    filename, infos))
UnicodeDecodeError: 'utf8' codec can't decode byte 0xa1 in position 54: invalid
start byte
&gt;&gt;&gt; b
'H:\\\xa1\xb0??\xa8\xe7\xa1\xb1.mp4'
&gt;&gt;&gt; print b
H:\â??â â.mp4
&gt;&gt;&gt; print b.decode('cp949')
H:\â??â â.mp4
&gt;&gt;&gt;
</code></pre>

<p>I've tried this, but it also doesn't work.</p>

<pre><code>b=b.decode('cp949')
b=b.decode('cp949').encode('utf-8')
b=unicode(b.decode('cp949'))
</code></pre>

<p>I think that Windows 7 supports Unicode file names (in Japanese kanji or special characters), but the character set of Python (2.x) (cp949) does not support special characters. What can I do for this problem?</p>

<p>Here's a workaround using the <a href="https://sourceforge.net/projects/pywin32" rel="nofollow">pywin32</a> extensions.
Basically, you use the <a href="http://timgolden.me.uk/pywin32-docs/win32api__GetShortPathName_meth.html" rel="nofollow"><code>GetShortPathName</code></a> function to generate a legacy <a href="https://en.wikipedia.org/wiki/8.3_filename" rel="nofollow">8.3 filename</a> from a unicode path.</p>

<pre><code># -*- coding: utf-8 -*-

import os
import win32api
from moviepy.editor import VideoFileClip


def short_path(unicode_path):
    return win32api.GetShortPathName(unicode_path)


v1 = 'âÄÄ«â â.mp4'
print os.path.isfile(v1)  # False

v2 = u'âÄÄ«â â.mp4'
print os.path.isfile(v2)  # True

# clip = VideoFileClip(v1)  # IOError
# clip = VideoFileClip(v2)  # UnicodeEncodeError
clip = VideoFileClip(short_path(v2))  # OK
print clip.duration
</code></pre>

python unicode special-characters moviepy