如果您想要以最佳质量且不进行任何转换下载 opus
格式的音频
在大多数情况下,YouTube 提供的最佳质量音频原始格式为 opus
。 您可以使用以下命令以最高可能的质量下载它:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0
然而,opus
格式可能因为许多原因不太方便。例如,一些媒体播放器,特别是汽车和手机上的播放器,可能不支持它。也许您只想要一个mp3
文件中的音频。下面介绍了如何使用一个命令来下载音频并将其转换为可能最流行的mp3
格式,并尽量减少损失质量。
如果您想要下载音频并将其转换为mp3或任何其他有损格式。
要从单个电影中下载音频:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-quality 0 --audio-format mp3 https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0
执行此命令需要安装
ffmpeg
(音视频转换器,youtube-dl使用它进行转换)。该命令仅下载
音频(不带视频)并将其转换为
mp3
。
在此设置中,选项--audio-quality 0
非常重要!没有此选项,在
mp3
压缩期间会失去很多声音质量。
--audio-quality 0
告诉youtube-dl以最佳质量保存音频文件(转换为
mp3
时)。如果没有此选项,默认情况下,
mp3
的音质设定为
0-9范围内的5
,其中0是最佳音质,9是最差的音质。因此,默认情况下质量较差。 面向非付费用户的Youtube流具有可变比特率,达到
160kbps
的
opus
格式。
Opus
格式比
mp3
更新,并具有更好的压缩性,同时保持相同的质量。因此,
160kbps
的opus =
〜256kbps
的mp3。当audio-quality为默认值(
0-9范围内的5
)时,mp3比特率受到限制,最高达
160kbps
,这意味着在压缩过程中会丢失一些声音质量。当audio-quality设置为
0
时,mp3可达到
300kbps
,保留几乎原始的质量。几乎原始的质量是因为
mp3
是有损格式,所以在转换为它时会丢失一些东西。通过使用
--audio-quality 0
选项,我们只需确保在此转换过程中损失尽可能少的内容即可。因此,原始
opus
音频文件和转换为
mp3
的音频文件之间的差异非常小,可能很难用耳朵听出来。
要从渠道下载所有电影的音频:
命令相同,但您应该放置渠道链接而不是单个视频链接。
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-quality 0 --audio-format mp3 https://www.youtube.com/c/someChannelName1232143/videos
下载播放列表中的音频:
您需要添加--yes-playlist
选项。
您可以将指向播放列表(包含单词playlist
的链接)的链接放置在此处:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format mp3 --audio-quality 0 --yes-playlist https://www.youtube.com/playlist?list=c29tZVZpZGVvVVJMUGFy
在播放播放列表时,或者链接到播放列表中的一首歌曲(带有 list
单词的链接):
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format mp3 --audio-quality 0 --yes-playlist "https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0&list=c29tZVZpZGVvTGlzdFBhcnRzc29tZVZpZGVvTGlzdFBhcnRz&index=4"
如果您想下载音频并将其转换为flac或任何其他无损格式
在这种情况下,您不必指定--audio-quality
选项,因为在转换为无损格式时,youtube-dl会忽略它。
要从单个电影中下载音频:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format flac https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0
从一个频道下载所有电影的音频:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format flac https://www.youtube.com/c/someChannelName1232143/videos
从播放列表下载音频:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format flac --yes-playlist https://www.youtube.com/playlist?list=c29tZVZpZGVvVVJMUGFy
或者
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format flac --yes-playlist "https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0&list=c29tZVZpZGVvTGlzdFBhcnRzc29tZVZpZGVvTGlzdFBhcnRz&index=4"
命令选项解释:
-f "bestaudio/best" <- Choose the best audio format.
As there is only audio format listed only the audio is downloaded.
-c <- (--continue) Force resume of partially downloaded files.
By default, youtube-dl will resume downloads if possible.
As docs state maybe it is default, but I put it to make sure it is set.
-i <- (--ignore-errors) Continue on download errors,
for example to skip unavailable videos in a playlist.
-w <- (--no-overtwrites) Do not overwrite files
(If something was already downloaded
and is present in the directory then continue with the next video)
-o "
in this case it gives you file named movieTitle.mp3
where movieTitle is the title of the video on youtube.
-v <- (--verbose) Print various debugging information
--extract-audio <- (-x) Convert video files to audio-only files
(requires ffmpeg or avconv and ffprobe or avprobe)
--audio-quality 0 <- Specify ffmpeg/avconv audio quality,
insert a value between 0 (better) and 9 (worse) for VBR or a specific
bitrate like 128K (default 5).
Youtube streams for nonpremium users with variable bitrate up to 160kbps in opus format.
Opus format is newer than mp3 and has better compression than mp3
preserving the same quality. So 160kbps opus = ~ 256kbps mp3.
When audio-quality is default (5 in 0-9 scale) mp3 bitrate
is limited to 160kbps which means that some sound quality is lost during compression.
When audio-quality is set to 0 mp3 goes up to 300kbps preserving original quality.
--audio-format mp3 <- Specify audio format: "best", "aac", "flac", "mp3", "m4a",
"opus", "vorbis", or "wav"; "best" by default; No effect without -x (--extract-audio).
In this case we choose mp3.
Alternatively you could choose for example flac which is loseless codec.
我提供的所有链接都是虚假的。 我只是在其中放置了一些使用base64编码的随机单词。 因此,您必须将它们替换为自己的链接才能使其正常工作。
提示:
Youtube-dl gives you opportunity to use your own youtube account to download stuff.
If your account is a premium account you can get
higher 320kbps opus bitrate which is equivalent of ~512kbps mp3.
Using your own account might be possible by setting --username and --pasword
(See Authentication Options in --help)
注意:
以上内容与youtube-dl版本2021.12.17
有关。较新版本可能会改变某些内容,请注意。
171
vorbis@128k是此视频可用的最佳音频。对于其他视频可能会有所不同。重新编码将会丢失更多数据,无论在何种比特率下!为什么不自己进行测试,比较输出,在耳机、汽车等场景下听一下,看看哪种适合您的需求。 - NVRM