gpt4 book ai didi

python-3.x - 如何在 python 中使用 ffmpeg 压缩视频?

转载 作者:行者123 更新时间:2023-12-04 23:05:42 25 4
gpt4 key购买 nike

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

关于python-3.x - 如何在 python 中使用 ffmpeg 压缩视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64421177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com