【发布时间】:2019-10-15 17:16:35
【问题描述】:
我是第一次尝试 ffmpeg-python,而且我很早就遇到了一个看起来很复杂的错误。
这是我的完整代码:
from tkinter import filedialog
import ffmpeg
sourceFile = filedialog.askopenfile()
targetFile = filedialog.asksaveasfilename()
stream = ffmpeg.input(sourceFile, ss=0, format='mov')
stream = ffmpeg.output(stream, targetFile, format='mp4')
ffmpeg.run(stream)
在我看来,这应该很简单。用户浏览到现有的 MOV 文件(标准 h264 文件,“普通”FFmpeg.exe 可以在 Windows 命令行上处理没有问题),然后选择要保存的 MP4 的输出文件,然后调用 FFmpeg 并生成 MP4文件是从 MOV 转换而来的。
但是,无论我选择什么源文件,我总是遇到这个错误:
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\ffmpeg\_ffmpeg.py", line 85, in output
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\ffmpeg\_run.py", line 285, in run_async
args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\subprocess.py", line 1119, in _execute_child
args = list2cmdline(args)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\subprocess.py", line 530, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 41: character maps to <undefined>
位置编号因文件而异,但错误始终是 'charmap' codec can't decode byte 0x90 in position [x]: character maps to
请有人指出我在这个问题上可能出错的地方吗?我觉得答案正盯着我看,但我没有看到它。
【问题讨论】:
-
我不知道;文件名由 tkinter.filedialog 的 askopenfile() 和 asksaveasfilename() 方法生成,我正在浏览网络和本地 Windows 驱动器上的合法文件路径。也许我需要以某种方式清理输入?
-
感谢您的建议。最后问题不是 UTF-8 或 cp1252,我的 Python 项目已经为此正确设置。我刚刚发布了我自己对这个问题的回答。再次感谢您的帮助。