亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號