python-3.x 系统找不到指定的文件

klsxnrf1  于 2023-04-22  发布在  Python
关注(0)|答案(1)|浏览(188)

我试图用Python生成一个缩略图。但是,我面临一个错误,说文件无法指定。我想使用的MP4视频在同一目录中可用。使用以下代码:

import requests
import ffmpeg
import sys
import os

in_filename = "ddd.mp4"
out_filename = "THUMBNAIL.jpg"

def generate_thumbnail(in_filename, out_filename):
    probe = ffmpeg.probe(in_filename)
    time = float(probe["streams"][0]["duration"]) // 2
    width = probe["streams"][0]["width"]
    try:
        (
            ffmpeg.input(in_filename, ss=time)
                .filter("scale", width, -1)
                .output(out_filename, vframes=1)
                .overwrite_output()
                .run(capture_stdout=True, capture_stderr=True)
        )
    except ffmpeg.Error as e:
        print(e.stderr.decode(), file=sys.stderr)
        sys.exit(1)

generate_thumbnail(in_filename, out_filename)

我得到这个错误:

Traceback (most recent call last):
  File "D:/Job/ExTrac_Chat_DB/Thumbnail FFMPEG.py", line 27, in <module>
    generate_thumbnail(in_filename, out_filename)
  File "D:/Job/ExTrac_Chat_DB/Thumbnail FFMPEG.py", line 11, in generate_thumbnail
    probe = ffmpeg.probe(in_filename)
  File "C:\ProgramData\Anaconda3\envs\practice\lib\site-packages\ffmpeg\_probe.py", line 20, in probe
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "C:\ProgramData\Anaconda3\envs\practice\lib\subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\ProgramData\Anaconda3\envs\practice\lib\subprocess.py", line 1311, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

有什么解决办法吗?

rxztt3cl

rxztt3cl1#

您必须将ffmpeg.exe文件(Download FFmpeg)与python文件(.py)放在同一目录下。

相关问题