Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

Python ffmpeg won't accept path, why?

everytime i launch the code and set the correct path it gives me this error, I tried including ffmpeg path, uninstalling and installing the library back but no luck. I've also tried using diffrent ways to set the path like putting it directly without saving it to a variable, this is getting me crazy please help me with a solution .


                                                     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:UsersmessaDesktopupcoming projectvideodownloader.py", line 65, in <module>
    hd1080p()
  File "c:UsersmessaDesktopupcoming projectvideodownloader.py", line 26, in hd1080p
    ffmpeg
  File "E:UsersmessaAppDataLocalProgramsPythonPython39libsite-packagesffmpeg\_run.py", line 313, in run
    process = run_async(
  File "E:UsersmessaAppDataLocalProgramsPythonPython39libsite-packagesffmpeg\_run.py", line 284, in run_async
    return subprocess.Popen(
  File "E:UsersmessaAppDataLocalProgramsPythonPython39libsubprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "E:UsersmessaAppDataLocalProgramsPythonPython39libsubprocess.py", line 1416, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
question from:https://stackoverflow.com/questions/65836756/python-ffmpeg-wont-accept-path-why

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The simplest solution in Windows OS, is placing ffmpeg.exe in the same folder as the Python script.

The reason you are getting the error, is that ffmpeg.exe is not in the execution path of your operating system.
Note: Executing pip install ffmpeg-python does not download FFmpeg application (but the Python package requires FFmpeg executable for functioning).

Assuming you are using Windows:

You can install FFmpeg as descried here: How to Install FFmpeg on Windows.

My suggestion:

  • Download the latest stable release from https://github.com/BtbN/FFmpeg-Builds/releases.
    Static build in preferred (static build applies single executable file).
    You may download a GPL licensed version (GPL versus LGPL is not relevant for executables).
    The latest stable release up to date (Jan 23 2021) is 4.3.1
    Assuming you are using Windows x64, download: ffmpeg-n4.3.1-29-g89daac5fe2-win64-gpl-4.3.zip
  • Extract the ZIP file, and copy ffmpeg.exe to the same folder as your Python script.
  • In case it's working, you may also put ffmpeg.exe someplace else (like C:ffmpegin), and update the Windows path.

Update:

There is an option to execute ffmpeg.exe, without adding it to the system path.

The method ffmpeg.run() accepts the optional argument cmd.
The default value of cmd is ffmpeg.
You can set the value of cmd to the full execution path.

Example:

(
    ffmpeg
    .concat(input_video, merged_audio, v=1, a=1)
    .output("mix_delayed_audio.mp4")
    .run(overwrite_output=True, cmd=r'c:FFmpeginffmpeg.exe')
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...