问题描述
我制作了这个脚本来用Python 3压缩视频。
import os
import sys
import subprocess
result = subprocess.run('ffmpeg -i output.mp4 -b 800k output.mp4')
print(result)
运行上述命令时,会出现一些错误,例如System cannot find the file specified
:
result = subprocess.run('ffmpeg -i output.mp4 -b 800k output.mp4')
File "C:\Program Files\Python37\lib\subprocess.py",line 488,in run
with Popen(*popenargs,**kwargs) as process:
File "C:\Program Files\Python37\lib\subprocess.py",line 800,in __init__
restore_signals,start_new_session)
File "C:\Program Files\Python37\lib\subprocess.py",line 1207,in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
问题:如何修复代码以正确压缩视频?
解决方法
几乎正确!看起来您唯一需要的模块是子流程。您应该在run()
函数中运行命令。试试这个:
import subprocess
result = subprocess.run('ffmpeg -i output.mp4 -b 800k output.mp4')
print(result)