# youtube-dl - 下載 YouTube 影片神器

WARNING

youtube-dl 已經停止更新了,可以改用更強的 yt-dlp 新一代網路影片下載神器。

# 介紹

# 安裝

Mac 可以用 brew 安裝

brew install youtube-dl

Linux 直接下載 youtube-dl 並改成可執行

# 基本使用

只要輸入 YouTube 影片的網址就會開始下載。

youtube-dl https://www.youtube.com/watch?v=rkAfWfZkfyo

接著就會開始下載影片

[youtube] rkAfWfZkfyo: Downloading webpage
[youtube] rkAfWfZkfyo: Downloading video info webpage
[download] Resuming download at byte 31858886
[download] Destination: 4K UHD Video power of samsung 4k hdr demo test video for 4k tv-rkAfWfZkfyo.f313.webm
[download] 100% of 634.40MiB in 01:10
[download] Destination: 4K UHD Video power of samsung 4k hdr demo test video for 4k tv-rkAfWfZkfyo.f251.webm
[download] 100% of 5.43MiB in 00:00
[ffmpeg] Merging formats into "4K UHD Video power of samsung 4k hdr demo test video for 4k tv-rkAfWfZkfyo.webm"
Deleting original file 4K UHD Video power of samsung 4k hdr demo test video for 4k tv-rkAfWfZkfyo.f313.webm (pass -k to keep)
Deleting original file 4K UHD Video power of samsung 4k hdr demo test video for 4k tv-rkAfWfZkfyo.f251.webm (pass -k to keep)

# 下載 mp4 格式的影片

預設的下載格式是 webm (opens new window),如果要下載 mp4 格式可以用 -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' 指定聲音與影像的格式

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' https://www.youtube.com/watch?v=rkAfWfZkfyo

# 下載 mp3 檔

除了下載影片之外,也可以只下載 mp3 檔

youtube-dl --extract-audio --audio-format mp3 https://www.youtube.com/watch?v=rkAfWfZkfyo

# 下載不同畫質與格式

預設會下載最高畫質的影片,如果要不同畫質或格式可以用 -F 這個選項

youtube-dl -F https://www.youtube.com/watch?v=rkAfWfZkfyo

接著就會列出這個影片所有的畫質與格式

[youtube] rkAfWfZkfyo: Downloading webpage
[youtube] rkAfWfZkfyo: Downloading video info webpage
[info] Available formats for rkAfWfZkfyo:
format code  extension  resolution note
249          webm       audio only DASH audio   56k , opus @ 50k, 2.11MiB
250          webm       audio only DASH audio   75k , opus @ 70k, 2.79MiB
140          m4a        audio only DASH audio  128k , m4a_dash container, mp4a.40.2@128k, 5.14MiB
171          webm       audio only DASH audio  135k , vorbis@128k, 5.05MiB
251          webm       audio only DASH audio  141k , opus @160k, 5.43MiB
278          webm       256x144    144p   99k , webm container, vp9, 30fps, video only, 3.57MiB
160          mp4        256x144    144p  111k , avc1.4d400c, 30fps, video only, 2.79MiB
242          webm       426x240    240p  229k , vp9, 30fps, video only, 7.42MiB
133          mp4        426x240    240p  246k , avc1.4d4015, 30fps, video only, 5.85MiB
243          webm       640x360    360p  453k , vp9, 30fps, video only, 13.89MiB
134          mp4        640x360    360p  635k , avc1.4d401e, 30fps, video only, 16.18MiB
244          webm       854x480    480p  858k , vp9, 30fps, video only, 25.31MiB
135          mp4        854x480    480p 1337k , avc1.4d401f, 30fps, video only, 32.15MiB
247          webm       1280x720   720p 2100k , vp9, 30fps, video only, 52.51MiB
136          mp4        1280x720   720p 2673k , avc1.4d401f, 30fps, video only, 62.45MiB
248          webm       1920x1080  1080p 3857k , vp9, 30fps, video only, 94.03MiB
137          mp4        1920x1080  1080p 5017k , avc1.640028, 30fps, video only, 110.63MiB
271          webm       2560x1440  1440p 8886k , vp9, 30fps, video only, 281.05MiB
313          webm       3840x2160  2160p 18240k , vp9, 30fps, video only, 634.40MiB
43           webm       640x360    medium , vp8.0, vorbis@128k, 34.71MiB
18           mp4        640x360    medium  670k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 27.12MiB
22           mp4        1280x720   hd720 1670k , avc1.64001F, mp4a.40.2@192k (44100Hz) (best)

要下載不同格式只要使用 -f 'video code+audio code 就可以抓不同畫質與音質的影片,例如要抓 1280 x 720 的畫質,就選 video code 136 跟 audio code 140,這樣 youtube-dl 就會抓對應的畫質與音質的影片下來了

youtube-dl -f '136+140' https://www.youtube.com/watch?v=rkAfWfZkfyo

# 參考資料

command line - How to download an MP3 track from a YouTube video - Ask Ubuntu (opens new window)

Last Updated: 2023-9-25 5:40:47
贊助商連結
    贊助商連結
    (adsbygoogle = window.adsbygoogle || []).push({});