0

我制作了这个脚本用于在 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

问题:如何修复代码以正确压缩视频?

4

1 回答 1

2

几乎正确!看起来您需要的唯一模块是子流程。您应该在run()函数中运行您的命令。尝试这个:

import subprocess
result = subprocess.run('ffmpeg -i output.mp4 -b 800k output.mp4')
print(result)
于 2020-10-20T06:19:41.023 回答