首页 > 解决方案 > FileNotFoundError: [WinError 2] 使用ffmpeg-python时系统找不到指定的文件怎么解决?

问题描述

我正在尝试使用 ffmprg 将视频和音频文件合并在一起,但我一直收到此错误

错误:

Traceback (most recent call last):
  File "C:\Users\Geo\youtubedownloader\test.py", line 9, in <module>
    ffmpeg.concat(video,audio, v=1 , a=1).output("C:/Users/Geo/output_video/mergedretweett.mp4/").run()
  File "C:\Users\Geo\AppData\Local\Programs\Python\Python39\lib\site-packages\ffmpeg\_run.py", line 313, in run
    process = run_async(
  File "C:\Users\Geo\AppData\Local\Programs\Python\Python39\lib\site-packages\ffmpeg\_run.py", line 284, in run_async
    return subprocess.Popen(
  File "C:\Users\Geo\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Geo\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

代码:



video = ffmpeg.input("C:/Users/Geo/File.mp4")

audio = ffmpeg.input("C:/Users/Geo/File_audio.mp4")


ffmpeg.concat(video,audio, v=1 , a=1).output("C:/Users/Geo/output_video/outputvideo.mp4").run()```


标签: pythonpython-3.xffmpeg

解决方案


您看到的 WindowsError 不是指视频文件,而是指 ffmpeg 可执行文件本身。对 subprocess.call 的调用不知道 File.mp4 是您传递的文件名。Windows 知道第一个参数应该是一个可执行文件,并向解释器报告它找不到它。

仔细检查 ffmpeg 是否可以在您的解释器运行的环境中执行。您可以将其添加到您的 PATH 或指定 ffmpeg.exe 的完整路径。


推荐阅读