gpt4 book ai didi

Python ffmpeg 不接受路径,为什么?

转载 作者:行者123 更新时间:2023-12-04 08:13:24 26 4
gpt4 key购买 nike

每次我启动代码并设置正确的路径时,它都会给我这个错误,我尝试包括 ffmpeg 路径,卸载并重新安装库但没有运气。我也尝试过使用不同的方法来设置路径,比如直接放置而不将其保存到变量中,这让我抓狂,请帮助我解决问题。

                                                     Code
from pytube import *
import ffmpeg

global str
userurl = (input("Enter a youtube video URL : "))
q = str(input("Which quality you want ? 360p,480p,720p,1080p,4K,Flh :")).lower()
yt = YouTube(userurl)
print ("Title of the video : ",yt.title)


def hd1080p():
print("Downloading a HD 1080p video...")
v = yt.streams.filter(mime_type="video/mp4", res="1080p", adaptive = True).first().download(filename = "HD1080P.mp4")
print("Video downloaded")
yt.streams.filter(mime_type="audio")
a = yt.streams.get_audio_only()
print("Downloading audio")
a.download(filename = "audio.mp4")
print("audio downloaded")
input_video = ffmpeg.input("HD1080P.mp4")
added_audio = ffmpeg.input("audio.mp4").audio.filter('adelay', "1500|1500")

merged_audio = ffmpeg.filter([input_video.audio, added_audio], 'amix')

(
ffmpeg
.concat(input_video, merged_audio, v=1, a=1)
.output("mix_delayed_audio.mp4")
.run(overwrite_output=True)
)


if q == "1080" or q == "1080p":
hd1080p()
elif q == "720" or q == "720p":
hd720p()
elif q == "480" or q == "480p":
l480p()
elif q == "360" or q == "360p":
l360p()
elif q == "4" or q == "4k":
hd4k()
else:
print("invalid choice")
                                                  THE ERROR
Traceback (most recent call last):
File "c:\Users\messa\Desktop\upcoming project\videodownloader.py", line 65, in <module>
hd1080p()
File "c:\Users\messa\Desktop\upcoming project\videodownloader.py", line 26, in hd1080p
ffmpeg
File "E:\Users\messa\AppData\Local\Programs\Python\Python39\lib\site-packages\ffmpeg\_run.py", line 313, in run
process = run_async(
File "E:\Users\messa\AppData\Local\Programs\Python\Python39\lib\site-packages\ffmpeg\_run.py", line 284, in run_async
return subprocess.Popen(
File "E:\Users\messa\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "E:\Users\messa\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

最佳答案

Windows 操作系统中最简单的解决方案是放置 ffmpeg.exe在与 Python 脚本相同的文件夹中。
您收到错误的原因是 ffmpeg.exe不在您的操作系统的执行路径中。
注意:执行pip install ffmpeg-python不下载 FFmpeg 应用程序(但 Python 包需要 FFmpeg 可执行文件才能运行)。
假设您使用的是 Windows:
您可以安装FFmpeg如此处所述:How to Install FFmpeg on Windows .
我的建议:

  • https://github.com/BtbN/FFmpeg-Builds/releases 下载最新的稳定版本.
    首选静态构建(静态构建应用单个可执行文件)。
    您可以下载 GPL 许可版本(GPL 与 LGPL 与可执行文件无关)。
    最新的稳定版本(2021 年 1 月 23 日)是 4.3.1
    假设您使用的是 Windows x64,请下载:ffmpeg-n4.3.1-29-g89daac5fe2-win64-gpl-4.3.zip
  • 解压 ZIP 文件,并复制 ffmpeg.exe到与您的 Python 脚本相同的文件夹。
  • 如果它工作正常,您也可以输入 ffmpeg.exe其他地方(如 C:\ffmpeg\bin\ ),并更新 Windows 路径。

  • 更新:
    有一个选项可以执行 ffmpeg.exe ,而不将其添加到系统路径中。
    方法 ffmpeg.run()接受可选参数 cmd . cmd的默认值是 ffmpeg .
    您可以设置 cmd的值到完整的执行路径。
    例子:
    (
    ffmpeg
    .concat(input_video, merged_audio, v=1, a=1)
    .output("mix_delayed_audio.mp4")
    .run(overwrite_output=True, cmd=r'c:\FFmpeg\bin\ffmpeg.exe')
    )

    关于Python ffmpeg 不接受路径,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65836756/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com