为了账号安全,请及时绑定邮箱和手机立即绑定

Ubuntu 上的 HandbrakeCLI 出现 Python 错误且未找到文件

Ubuntu 上的 HandbrakeCLI 出现 Python 错误且未找到文件

牛魔王的故事 2023-09-05 20:29:15
我正在尝试用 python3 编写一个程序,在我的 ubuntu 机器上使用 handbrakecli 来重新编码一些视频。我错过了一些愚蠢的东西,但我一生都无法弄清楚这一点,而且我已经为此花费了无数个小时。这是代码:def convertvideo(input_file):    hb_args = (" -i " + input_file + " -o " + handbraketempspace + " --preset-import-file "+handbrake_json_file_location + " -Z " + handbrake_profile_name)    print (hb_args) # for debug only    subprocess.Popen(handbrake + hb_args)    return()无论我如何重新排列“,我都会收到两个错误之一,要么手刹说找不到文件,要么找不到我的预设。这个确切的命令可以在命令行中完美运行。这是具体的错误:Traceback (most recent call last):  File "SubProcessing.py", line 161, in <module>    finalvideo = convertvideo(sys.argv[2])  File "SubProcessing.py", line 82, in convertvideo    subprocess.Popen(handbrake + hb_args)  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__    self._execute_child(args, executable, preexec_fn, close_fds,  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child    raise child_exception_type(errno_num, err_msg, err_filename)FileNotFoundError: [Errno 2] No such file or directory: "/usr/bin/HandBrakeCLI -i /root/Alone-S02E01-Once_More_Unto_the_Breach_HDTV-720p.mkv -o /root/tmp/tempvideo.mkv --preset-import-file /mnt/media/PlexTestFiles/handbrake_presets.json -Z 'h.265_Hardware'"在此先感谢您的帮助。再说一次,我不是 python 编码员,但我不认为这会这么难。
查看完整描述

1 回答

?
Qyouu

TA贡献1786条经验 获得超11个赞

您需要subprocess.Popen使用数组中的参数进行调用,而不是字符串。在您的情况下,相关部分将是:

subprocess.Popen([handbrake, "-i", input_file, "-o", handbraketempspace, "--preset-import-file", handbrake_json_file_location, "-Z", handbrake_profile_name])

或者,您可以指定shell=Trueto subprocess.Popen,但这会不必要地启动 shell,因此最好不要使用它。


查看完整回答
反对 回复 2023-09-05
  • 1 回答
  • 0 关注
  • 86 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信