我用这个抓头已经好几个小时了。
我试图编写一个简单的脚本,将.AVI格式的旧视频转换为带有HandbrakeCLI的.mp4,但是我无法让手制动器注册正确的参数,我一直得到“丢失的输出文件名。运行C:/Program / Handbrake /HandbrakeCLI.exe-帮助语法。\r\n”错误。
这是我目前所拥有的
import glob
import os
import handbrake
hb = handbrake.HandbrakeEncode
mydir = "C:\\Path\\To\\MyVids\\"
os.chdir(mydir)
filesList = []
for files in glob.glob("*.avi"):
filesList.append(mydir + files)
print(mydir + files)
#this prints the correctly assembled path and file as expected
for files in filesList:
print("Encoding file: " + files)
hb(files)hb函数是:
def HandbrakeEncode(filepath):
import subprocess
import os
from subprocess import Popen, PIPE
outputPath, fileExtension = os.path.splitext(filepath)
outputPath += ".mp4"
args = '-i ' + filepath + ' -o '+ outputPath
cmd = ['C:\\Program Files\\Handbrake\\HandbrakeCLI.exe', args]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = p.communicate()
print(stdout)谢谢你能提供的帮助..。
发布于 2013-10-27 20:20:39
subprocess.Popen期望命令被分割成可以逃避的块:
['foo', '-a', 'bar', '--baz']您的命令应该是一个参数列表:
cmd = [
'C:\\Program Files\\Handbrake\\HandbrakeCLI.exe',
'-i', filepath,
'-o', outputPath
]https://stackoverflow.com/questions/19623023
复制相似问题