FileNotFoundError: [WinError 2] 系统找不到指定的文件 - FFMPEG

问题描述 投票:0回答:1

我正在 Windows 上使用 conda 环境运行脚本并收到此错误(下面的堆栈跟踪),这显然是由 python 可执行文件无法找到 ffmpeg.exe 引起的。对此有很多问题,但不幸的是,没有一个解决方案对我有用,所以我希望有人有新的想法。

我尝试过的:

  • conda install -c conda-forge ffmpeg
    (之后我可以在命令行中运行ffmpeg,但仍然收到错误)
  • pip install ffmpeg-python
  • 将 conda env 中 ffmpeg.exe 所在的文件夹添加到 Windows 路径以及 python 中的 sys.path。
  • 将相同的 ffmpeg.exe 复制到 conda env 中 python.exe 的位置,b) 复制到我正在运行的脚本的位置,c) 复制到 subprocess.py 的位置。
  • 下载 ffmpeg windows 二进制文件并使用该文件重复最后两个步骤。

还有什么我可以尝试让它发挥作用吗?

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[10], line 22
     19 truncate_second = 8.2         # Video end = start_second + truncate_second
     21 # Extract Video CAVP Features & New Video Path:
---> 22 cavp_feats, new_video_path = extract_cavp(video_path, start_second, truncate_second, tmp_path=tmp_path)

File D:\Software\Anaconda\envs\diff_foley\Lib\site-packages\torch\nn\modules\module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
   1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1517 else:
-> 1518     return self._call_impl(*args, **kwargs)

File D:\Software\Anaconda\envs\diff_foley\Lib\site-packages\torch\nn\modules\module.py:1527, in Module._call_impl(self, *args, **kwargs)
   1522 # If we don't have any hooks, we want to skip the rest of the logic in
   1523 # this function, and just call forward.
   1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1525         or _global_backward_pre_hooks or _global_backward_hooks
   1526         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527     return forward_call(*args, **kwargs)
   1529 try:
   1530     result = None

File D:\Software\Anaconda\envs\diff_foley\Lib\site-packages\torch\utils\_contextlib.py:115, in context_decorator.<locals>.decorate_context(*args, **kwargs)
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)

File D:\Work\DIff-Foley\Diff-Foley\inference\demo_util.py:131, in Extract_CAVP_Features.forward(self, video_path, start_second, truncate_second, tmp_path)
    129 print("truncate second: ", truncate_second)
    130 # Load the video, change fps:
--> 131 video_path_low_fps = reencode_video_with_diff_fps(video_path, self.tmp_path, self.fps, start_second, truncate_second)
    132 video_path_high_fps = reencode_video_with_diff_fps(video_path, self.tmp_path, 21.5, start_second, truncate_second)
    134 # read the video:

File D:\Work\DIff-Foley\Diff-Foley\inference\demo_util.py:42, in reencode_video_with_diff_fps(video_path, tmp_path, extraction_fps, start_second, truncate_second)
     31 def reencode_video_with_diff_fps(video_path: str, tmp_path: str, extraction_fps: int, start_second, truncate_second) -> str:
     32     '''Reencodes the video given the path and saves it to the tmp_path folder.
     33 
     34     Args:
   (...)
     40         str: The path where the tmp file is stored. To be used to load the video from
     41     '''
---> 42     assert which_ffmpeg() != '', 'Is ffmpeg installed? Check if the conda environment is activated.'
     43     # assert video_path.endswith('.mp4'), 'The file does not end with .mp4. Comment this if expected'
     44     # create tmp dir if doesn't exist
     45     os.makedirs(tmp_path, exist_ok=True)

File D:\Work\DIff-Foley\Diff-Foley\inference\demo_util.py:26, in which_ffmpeg()
     20 def which_ffmpeg() -> str:
     21     '''Determines the path to ffmpeg library
     22 
     23     Returns:
     24         str -- path to the library
     25     '''
---> 26     result = subprocess.run(['which', 'ffmpeg'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     27     ffmpeg_path = result.stdout.decode('utf-8').replace('\n', '')
     28     return ffmpeg_path

File D:\Software\Anaconda\envs\diff_foley\Lib\subprocess.py:548, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    545     kwargs['stdout'] = PIPE
    546     kwargs['stderr'] = PIPE
--> 548 with Popen(*popenargs, **kwargs) as process:
    549     try:
    550         stdout, stderr = process.communicate(input, timeout=timeout)

File D:\Software\Anaconda\envs\diff_foley\Lib\subprocess.py:1026, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group)
   1022         if self.text_mode:
   1023             self.stderr = io.TextIOWrapper(self.stderr,
   1024                     encoding=encoding, errors=errors)
-> 1026     self._execute_child(args, executable, preexec_fn, close_fds,
   1027                         pass_fds, cwd, env,
   1028                         startupinfo, creationflags, shell,
   1029                         p2cread, p2cwrite,
   1030                         c2pread, c2pwrite,
   1031                         errread, errwrite,
   1032                         restore_signals,
   1033                         gid, gids, uid, umask,
   1034                         start_new_session, process_group)
   1035 except:
   1036     # Cleanup if the child failed starting.
   1037     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File D:\Software\Anaconda\envs\diff_foley\Lib\subprocess.py:1538, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session, unused_process_group)
   1536 # Start the process
   1537 try:
-> 1538     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1539                              # no special security
   1540                              None, None,
   1541                              int(not close_fds),
   1542                              creationflags,
   1543                              env,
   1544                              cwd,
   1545                              startupinfo)
   1546 finally:
   1547     # Child is launched. Close the parent's copy of those pipe
   1548     # handles that only the child should have open.  You need
   (...)
   1551     # pipe will not close when the child process exits and the
   1552     # ReadFile will hang.
   1553     self._close_pipe_fds(p2cread, p2cwrite,
   1554                          c2pread, c2pwrite,
   1555                          errread, errwrite)

FileNotFoundError: [WinError 2] The system cannot find the file specified
python ffmpeg path anaconda subprocess
1个回答
0
投票

您需要通过环境变量或在 Python 运行时操作

sys.path
将 ffmpeg.exe 放入路径中。

我知道有一些方便的选择。

  1. ffmpeg-downloader
    (我是开发者。)

此软件包为您提供了一个类似 pip 的命令来下载最新(和其他版本)的 ffmpeg。此命令将 ffmpeg 安装到用户的 AppData 目录,以便在多个 Python venv 中使用(或其他常规用途)。

快速使用:

pip install ffmpeg-downloader
ffdl install --add-path

有关其他用法,请参阅存储库自述文件。

  1. static-ffmpeg

另一方面,这个将 ffmpeg 下载到当前的 venv。

如果您不使用 venv,那么任何一个都应该适合您。如果你在多个项目中使用 ffmpeg 和 venv,我建议使用前者。

© www.soinside.com 2019 - 2024. All rights reserved.