I do have the following path in the memory:
video_path = u'C:\\Documents and Settings\\user\\My Documents\\Downloads\\\xf5iv - Neon Phoenix [Free DL].mp3'
I’m trying to use it as a parameter in cmd, so I have to encode it.
video_path = video_path.encode(sys.getfilesystemencoding())
cmd = 'ffmpeg -y -i "%s" -vn -ac 2 -f mp3 audio.mp3' % video_path
subprocess.Popen(cmd)
However the string is not encoded in the right way – it converts the \xf5 to ? instead of õ. Therefore the file could not be found.
How can this happen? I’m using the default filesystem encoding (which is mbcs).
From an answer here:
Therefore,
subprocess.Popencan’t handle unicode right at Python 2.x versions.My solution was renaming the input file to something random (with
os.rename, which supports unicode), convert withffmpegthat i launch withsubprocess.Popen, and then rename it back.