从此线程寻求帮助: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
答案 0 :(得分:0)
很可能您没有完全安装ffmpeg;它必须在您的PATH
中。您可以通过在终端中输入ffmpeg
进行检查。
这里有多种可能的解决方案:
将ffmpeg安装到PATH
中,例如,将二进制文件复制到/usr/bin/
中。
将ffmpeg
二进制文件符号链接到PATH
中的目录。
设置PATH
,使其包含安装ffmpeg的目录。在Linux和macOS上,this likely involved editing ~/.profile
or /etc/environment
,然后再次登录。在Windows上,editing the registry works。
通过在您的youtube-dl配置中添加'ffmpeg_location': '/replace/this/with/the/real/path/to/your/ffmpeg'
来指定配置中ffmpeg的确切位置。自然,这只会解决youtube-dl的问题,而不能解决其他依赖ffmpeg的应用程序。