FileNotFoundError从Python子进程在Windows上运行ffmpeg

vawmfj5a  于 2023-04-07  发布在  Windows
关注(0)|答案(1)|浏览(201)

这是我的代码转换mkv到mp4我创建了资产和结果文件夹我添加ffmpeg到用户和环境变量路径

import os
import subprocess

if not os.path.exists("assets"):
    raise Exception("Please create and put all MKV files in assets folder. ")

mkv_list = os.listdir("assets")

if not os.path.exists("results"):
    os.mkdir("results")

for mkv in mkv_list:
    name, ext = os.path.splitext(mkv)
    if ext != ".mkv":
        raise Exception("Please add MKV files only!")

    output_name = name + ".mp4"

    try:
        subprocess.run(
            ['ffmpeg', '-i', f"assets/{mkv}", "-codec", "copy", f"results/{output_name}"], check=True
        )

    except:
        raise Exception(
            "Please, download, install and Add the path FFMPEG to Enviroment variables ")

print(f"{len(mkv_list)} video/s have ben converted")
os.startfile("results")

我得到这个错误消息,当我运行它

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[1], line 20
     19 try:
---> 20     subprocess.run(
     21         ['ffmpeg', '-i', f"assets/{mkv}", "-codec", "copy", f"results/{output_name}"], check=True
     22     )
     24 except:

File c:\Users\HP\anaconda3\envs\Projectvenv\Lib\subprocess.py:546, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    544     kwargs['stderr'] = PIPE
--> 546 with Popen(*popenargs, **kwargs) as process:
    547     try:

File c:\Users\HP\anaconda3\envs\Projectvenv\Lib\subprocess.py:1022, 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)
   1019             self.stderr = io.TextIOWrapper(self.stderr,
   1020                     encoding=encoding, errors=errors)
-> 1022     self._execute_child(args, executable, preexec_fn, close_fds,
   1023                         pass_fds, cwd, env,
   1024                         startupinfo, creationflags, shell,
   1025                         p2cread, p2cwrite,
   1026                         c2pread, c2pwrite,
   1027                         errread, errwrite,
   1028                         restore_signals,
   1029                         gid, gids, uid, umask,
   1030                         start_new_session, process_group)
   1031 except:
   1032     # Cleanup if the child failed starting.

File c:\Users\HP\anaconda3\envs\Projectvenv\Lib\subprocess.py:1491, 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)
   1490 try:
-> 1491     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1492                              # no special security
   1493                              None, None,
   1494                              int(not close_fds),
   1495                              creationflags,
   1496                              env,
   1497                              cwd,
   1498                              startupinfo)
   1499 finally:
   1500     # Child is launched. Close the parent's copy of those pipe
   1501     # handles that only the child should have open.  You need
   (...)
   1504     # pipe will not close when the child process exits and the
   1505     # ReadFile will hang.

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

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
Cell In[1], line 25
     20         subprocess.run(
     21             ['ffmpeg', '-i', f"assets/{mkv}", "-codec", "copy", f"results/{output_name}"], check=True
     22         )
     24     except:
---> 25         raise Exception(
     26             "Please, download, install and Add the path FFMPEG to Enviroment variables ")
     28 print(f"{len(mkv_list)} video/s have ben converted")
     29 os.startfile("results")

Exception: Please, download, install and Add the path FFMPEG to Enviroment variables

我检查了将ffmpeg添加到环境变量,它添加了我使用jupyter来了解特定行不起作用,它是子进程行

ovfsdjhp

ovfsdjhp1#

出现此错误是因为我下载了错误的文件。我从git master builds下载了我应该从release builds下载的文件

相关问题