youtube-dl -f bestaudio --audio-quality 0 --audio-format mp3 https://www.youtube.com/playlist?list=PLYRruMbyFRcBVdVN8v4FNkIKkXvL-bZn_
可以告诉我如何使用
bestaudio
参数将YouTube视频下载为mp3
吗?youtube-dl -f bestaudio --audio-quality 0 --audio-format mp3 https://www.youtube.com/playlist?list=PLYRruMbyFRcBVdVN8v4FNkIKkXvL-bZn_
bestaudio
参数将YouTube视频下载为mp3
吗?man youtube-dl
中:
-x, --extract-audio Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)
--audio-format FORMAT Specify audio format: "best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "best" by default
--audio-quality QUALITY Specify ffmpeg/avconv audio quality, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default
youtube-dl -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 <Video-URL>
--audio-quality 0
使用最高的编码质量,但可能会增加文件大小而没有必要。默认值为5,根据源质量的不同可能是更好的选择。youtube-dl -f bestaudio[ext=m4a] --embed-thumbnail --add-metadata <Video-URL>
m4a
文件。youtube-dl -f bestaudio --extract-audio --embed-thumbnail --add-metadata <Video-URL>
ogg
文件。youtube-dl -F <Video-URL>
-f bestaudio
和 --audio-quality 0
的效果是一样的 - 下载只有音频的 webm
文件。 - rofrolffmpeg
才能获取mp3文件,否则文件仍然保持为webm格式。 - Sotsir-i
这样它就可以在出现错误时继续下载。 - Eduardo Santana--extract-audio
会导致生成 .ogg
文件,有什么特别的原因吗? - Hashim Azizyoutube-dl -f bestaudio "https://www.youtube.com/playlist?list=PLYRruMbyFRcBVdVN8v4FNkIKkXvL-bZn_" --exec "ffmpeg -i {} -codec:a libmp3lame -qscale:a 0 {}.mp3 && rm {} "
youtube-dl -f bestaudio "https://www.youtube.com/playlist?list=PLYRruMbyFRcBVdVN8v4FNkIKkXvL-bZn_" --exec "ffmpeg -i {} -codec:a libmp3lame -qscale:a 0 {}.mp3 "
#python3
import pafy
video = pafy.new('video id or video url')
bestaudio = video.getbestaudio()
bestaudio.bitrate #get bit rate
bestaudio.extension #extension of audio fileurl
...
bestaudio.url #get url
...
#download if you want
bestaudio.download()
man youtube-dl
的信息(在线副本可以在这里找到):youtube-dl -x URL
,因为它应该下载最佳质量的视频 :))youtube-dl -f bestaudio URL
也有效!但是,使用这两个选项时,大多数情况下您需要使用ffmpeg
或类似工具将其转换为MP3格式 - 因为您已经在编辑文件,您还可以给它打上标签(使用旧的ID3版本以实现最大设备兼容性!)。
默认情况下,youtube-dl会尝试下载最高质量的视频,但有时您可能想要下载其他格式。最简单的情况是请求特定的格式,例如-f 22
。您可以使用--list-formats
获取可用格式的列表,也可以使用文件扩展名(目前支持aac、m4a、mp3、mp4、ogg、wav、webm)或特殊名称best、bestvideo、bestaudio和worst。
如果您想要下载多个视频,并且它们没有相同的可用格式,您可以使用斜杠指定优先顺序,例如-f 22/17/18
。您还可以通过在括号中添加条件来过滤视频结果,例如-f "best[height=720]"
(或-f "[filesize>10M]"
)。这适用于filesize、height、width、tbr、abr、vbr、asr和fps的比较运算符<、<=、>、>=、=、!=,以及ext、codec、vcodec、container和protocol的比较运算符=、!=。对于值未知的格式,除非在运算符后面加上问号(?),否则将被排除在外。您可以组合格式过滤器,例如-f "[height <=? 720][tbr>500]"
选择高达720p的视频(或高度未知的视频),并且比特率至少为500 KBit/s。
使用逗号下载多个格式,例如-f 136/137/mp4/bestvideo,140/m4a/bestaudio
。您可以使用-f <video-format>+<audio-format>
(需要ffmpeg或avconv)将两种格式的视频和音频合并为单个文件,例如-f bestvideo+bestaudio
。
自2015年4月底和版本2015.04.26以来,youtube-dl默认使用-f bestvideo+bestaudio/best
作为格式选择(参见#5447,#5456)。如果安装了ffmpeg或avconv,则会分别下载bestvideo和bestaudio,并将它们混合到一个单独的文件中,从而获得最佳的整体质量。否则,它将回退到best,并下载作为单个文件提供的最佳可用质量。对于不来自YouTube的视频,因为它们不会提供音频和视频的两个不同文件,所以也需要best。如果您只想下载某些dash格式的视频(例如,如果您对分辨率高于1080p的视频不感兴趣),您可以在配置文件中添加-f bestvideo[height<=?1080]+bestaudio/best
。请注意,如果您使用youtube-dl流式传输到stdout(并且很可能将其传输到媒体播放器),即您明确指定输出模板为-o -
,youtube-dl仍然使用-f best
格式选择,以便立即开始向播放器传送内容,而不是等待bestvideo和bestaudio下载和混合。
如果您想保留旧的格式选择行为(youtube-dl 2015.04.26之前的版本),即您想要下载作为单个文件提供的最佳可用质量媒体,您应该明确指定您的选择-f best
。您可能希望将其添加到配置文件(#configuration)中,以便每次运行youtube-dl时无需键入它。
大多数提出这
avprobe
而不是ffprobe
),以查看哪个最好:$ ffprobe -hide_banner output-output-loads-of-options.webm
Input #0, matroska,webm, from 'output-output-loads-of-options.webm':
Metadata:
encoder : google
Duration: 00:04:02.63, start: 0.000000, bitrate: 118 kb/s
Stream #0:0(eng): Audio: vorbis, 44100 Hz, stereo, fltp (default)
$ ffprobe -hide_banner output_with_just_-x.ogg
Input #0, ogg, from 'output_with_just_-x':
Duration: 00:04:02.65, start: 0.000000, bitrate: 117 kb/s
Stream #0:0(eng): Audio: vorbis, 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
LANGUAGE : eng
ENCODER : Lavf56.4.101