如何在python中使用ffmpeg合并音频和视频文件?



我需要在python 3.7中使用ffmpeg合并音频和视频,你能帮我解决这个问题吗?

在这里我使用了代码:

from pathlib import Path
glob_path = Path(r"D:t")
file_name = [str(pp) for pp in glob_path.glob(r'**/*.mp4')]
print(file_name)
video_stream = ffmpeg.input(file_name[0])
audio_stream = ffmpeg.input(file_name[1])
print(video_stream)
print(audio_stream)
ffmpeg.output(audio_stream, video_stream, 'out.mp4').run()

我得到这个放错误

['D:\t\audio.mp4', 'D:\t\video.mp4']
input(filename='D:\t\audio.mp4')[None] <b0ebefda3dca>
input(filename='D:\t\video.mp4')[None] <388c87446fd1>

Traceback (most recent call last):
File "C:UsersLENOVOPycharmProjectscalc_newudownlod.py", line 18, in <module>
ffmpeg.output(audio_stream, video_stream, 'out.mp4').run()
File "C:UsersLENOVOPycharmProjectscalc_newvenvlibsite-packagesffmpeg_run.py", line 320, in run
overwrite_output=overwrite_output,
File "C:UsersLENOVOPycharmProjectscalc_newvenvlibsite-packagesffmpeg_run.py", line 285, in run_async
args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream
File "C:UsersLENOVOAnaconda3libsubprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:UsersLENOVOAnaconda3libsubprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

似乎找不到其中一个文件。最好的办法是检查两个文件是否存在于指定位置。

FileNotFoundError: [WinError 2] The system cannot find the file specified

即使显示路径错误,该错误在安装包中,我使用

conda install -c menpo ffmpeg 

在 https://anaconda.org/menpo/ffmpeg,解决了我的问题

最新更新