首先,我在终端中输入了以下命令来安装必要的软件包:
pip install moviepy
pip install ffmpeg然后,当我试图运行以下代码时,我得到了以下内容:
from moviepy.editor import *错误: RuntimeError:找不到ffmpeg exe。在系统上安装ffmpeg,或者设置IMAGEIO_FFMPEG_EXE环境变量。
为了修复错误,我在前面的代码行上输入了以下代码:
import os
os.environ["IMAGEIO_FFMPEG_EXE"] = "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffmpeg"
from moviepy.editor import *这解决了我之前遇到的问题,并且我能够导入它。在代码中键入的位置是在我键入时直接从location属性的输出中复制的,在终端中显示ffmpeg。但是,当我实际尝试使用这个库时,会发现以下错误:
import os
os.environ["IMAGEIO_FFMPEG_EXE"] = "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffmpeg"
from moviepy.editor import *
clip = VideoFileClip("master_video.mp4") Error:
---------------------------------------------------------------------------
PermissionError Traceback (most recent call last)
Input In [2], in <cell line: 5>()
2 os.environ["IMAGEIO_FFMPEG_EXE"] = "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffmpeg"
3 from moviepy.editor import *
----> 5 clip = VideoFileClip("master_video.mp4")
7 for x in range(0,10):
8 print(randint(0, 2420))
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/moviepy/video/io/VideoFileClip.py:88, in VideoFileClip.__init__(self, filename, has_mask, audio, audio_buffersize, target_resolution, resize_algorithm, audio_fps, audio_nbytes, verbose, fps_source)
86 # Make a reader
87 pix_fmt = "rgba" if has_mask else "rgb24"
---> 88 self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,
89 target_resolution=target_resolution,
90 resize_algo=resize_algorithm,
91 fps_source=fps_source)
93 # Make some of the reader's attributes accessible from the clip
94 self.duration = self.reader.duration
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_reader.py:35, in FFMPEG_VideoReader.__init__(self, filename, print_infos, bufsize, pix_fmt, check_duration, target_resolution, resize_algo, fps_source)
33 self.filename = filename
34 self.proc = None
---> 35 infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
36 fps_source)
37 self.fps = infos['video_fps']
38 self.size = infos['video_size']
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_reader.py:257, in ffmpeg_parse_infos(filename, print_infos, check_duration, fps_source)
254 if os.name == "nt":
255 popen_params["creationflags"] = 0x08000000
--> 257 proc = sp.Popen(cmd, **popen_params)
258 (output, error) = proc.communicate()
259 infos = error.decode('utf8')
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py:969, 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)
965 if self.text_mode:
966 self.stderr = io.TextIOWrapper(self.stderr,
967 encoding=encoding, errors=errors)
--> 969 self._execute_child(args, executable, preexec_fn, close_fds,
970 pass_fds, cwd, env,
971 startupinfo, creationflags, shell,
972 p2cread, p2cwrite,
973 c2pread, c2pwrite,
974 errread, errwrite,
975 restore_signals,
976 gid, gids, uid, umask,
977 start_new_session)
978 except:
979 # Cleanup if the child failed starting.
980 for f in filter(None, (self.stdin, self.stdout, self.stderr)):
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py:1845, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1843 if errno_num != 0:
1844 err_msg = os.strerror(errno_num)
-> 1845 raise child_exception_type(errno_num, err_msg, err_filename)
1846 raise child_exception_type(err_msg)
PermissionError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffmpeg'提前谢谢你
https://stackoverflow.com/questions/72892657
复制相似问题