从这个线程获得帮助:download only audio from youtube video using youtube-dl in python script
import youtube_dl #installed youtube_dl file
options = {
'format':'bestaudio/best',
'extractaudio':True, #extracting audio
'audioformat':'mp3', #file options and format
'outtmpl':'%(id)s.%(ext)s', #name the file the ID of the video
'noplaylist':True,
'nocheckcertificate':True,
'postprocessors': [{
'key': 'FFmpegExtractAudio',# Used ffmpeg for converting the file to mp3
'preferredcodec': 'mp3',
'preferredquality': '192',
}]
}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download(['https://youtu.be/BZP1rYjoBgI']) #final downloading
Python console output
最佳答案
很可能,您没有完全安装 ffmpeg;它必须在您的 PATH
中.您可以通过键入 ffmpeg
进行检查在一个终端。
这里有多种可能的解决方案:
PATH
,例如通过将二进制文件复制到 /usr/bin/
.ffmpeg
二进制到您的PATH
中的目录.PATH
以便它包含您安装 ffmpeg 的目录。在 Linux 和 macOS 上,this likely involved editing ~/.profile
or /etc/environment
并再次登录。在 Windows 上,editing the registry works .'ffmpeg_location': '/replace/this/with/the/real/path/to/your/ffmpeg'
在您的配置中指定精确的 ffmpeg 位置到您的 youtube-dl 配置。当然,这只会解决 youtube-dl 的问题,而不是其他依赖 ffmpeg 的应用程序。关于python - 我已经安装了 ffmpge 但收到以下 DownloadError : ERROR: ffprobe/avprobe and ffmpeg/avconv not found. 请安装一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63204915/