使用youtube-dl下载YouTube视频

  • 3
  • 23,729 views
  • A+
所属分类:Linux

会用梯子的同学很多喜欢看油管(YouTube)视频,确实油管的视频质量比国内高很多,而且广告也很短,有的广告甚至不想跳过。想下载油管视频怎么办,有VPS的同学我们可以通过youtube-dl这个工具。youtube-dl是一个使用python编写的脚本,可以下载youtube等热门视频网站的视频,使用起来也很简单。

安装youtube-dl

youtube-dl直接下载最新版到/usr/local/bin/目录下并赋予权限即可使用。命令:

wget http://youtube-dl.org/latest/youtube-dl -O /usr/local/bin/youtube-dl
chmod a+x /usr/local/bin/youtube-dl

youtube-dl用法

查看使用帮助

youtube-dl -h

一些常用的参数:

youtube-dl --list-extractors  #查看支持网站列表
youtube-dl -U  #程序升级
youtube-dl --get-format URL #获取视频格式
youtube-dl -F URL #获取所有格式(目前仅支持YouTube),例如:
youtube-dl -F https://www.youtube.com/watch?v=nCfrfCzaB2A
[youtube] Setting language
[youtube] n-BXNXvTvV4: Downloading video webpage
[youtube] n-BXNXvTvV4: Downloading video info webpage
[youtube] n-BXNXvTvV4: Extracting video information
格式编号
format code extension resolution  note
171         webm      audio only  DASH audio , audio@ 48k (worst)
140         m4a       audio only  DASH audio , audio@128k
160         mp4       144p        DASH video , video only
242         webm      240p        DASH video , video only
133         mp4       240p        DASH video , video only
243         webm      360p        DASH video , video only
134         mp4       360p        DASH video , video only
244         webm      480p        DASH video , video only
135         mp4       480p        DASH video , video only
247         webm      720p        DASH video , video only
136         mp4       720p        DASH video , video only
248         webm      1080p       DASH video , video only
137         mp4       1080p       DASH video , video only
271         webm      1440p       DASH video , video only
264         mp4       1440p       DASH video , video only
272         webm      2160p       DASH video , video only
138         mp4       2160p       DASH video , video only
100         webm      360p        3D
82          mp4       360p        3D
84          mp4       720p        3D
17          3gp       176x144
36          3gp       320x240
5           flv       400x240
43          webm      640x360
18          mp4       640x360
22          mp4       1280x720    (best)
--max-quality 下载的是上面的(best) 
如果你想下真正的最高画质需要分别下上面的138和140,然后用视频软件合成。
下载普通的视频只需要youtube-dl https://www.youtube.com/watch?v=nCfrfCzaB2A 默认下载下来的格式为webm
youtube-dl -f format URL #下载指定格式的视频,这里以下载1080p原画质量的视频格式为例:
youtube-dl -f 137 http://www.youtube.com/watch?v=n-BXNXvTvV4

注意一点:1080以上的视频音视频是分离的,需要装一下FFmpeg,debian下安装详见https://past.cmsky.org/debian-install-ffmpeg/ 然后-f 后面的数字之间选视频和音频部分用加号连着,例如youtube-dl -f 137+140,视频一定要在音频前面,FFmpeg会自动合并。
本文部分内容参考了秋水逸冰的文章。

weinxin
我的微信公众号
我的微信公众号扫一扫

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:3   其中:访客  0   博主  0

    • wtks1 wtks1 4

      Warning: Use of undefined constant auto - assumed 'auto' (this will throw an Error in a future version of PHP) in /www/wwwroot/past.cmsky.org/wp-content/themes/begin5.2/inc/inc.php on line 911

      实际测试,2160p的代码均无法使用,1440p的一系列代码使用正常

        • 厘米 厘米 9

          Warning: Use of undefined constant auto - assumed 'auto' (this will throw an Error in a future version of PHP) in /www/wwwroot/past.cmsky.org/wp-content/themes/begin5.2/inc/inc.php on line 911

          @wtks1 谢谢测试,高清的我还没试过~

        • wtks1 wtks1 4

          Warning: Use of undefined constant auto - assumed 'auto' (this will throw an Error in a future version of PHP) in /www/wwwroot/past.cmsky.org/wp-content/themes/begin5.2/inc/inc.php on line 911

          上面列出来的代码有点过时了,这份是最新测试出来的
          139 m4a audio only DASH audio 50k , m4a_dash container, mp4a.40.5@ 48k (22050Hz), 10.48MiB
          249 webm audio only DASH audio 69k , opus @ 50k, 13.09MiB
          250 webm audio only DASH audio 91k , opus @ 70k, 17.25MiB
          140 m4a audio only DASH audio 129k , m4a_dash container, mp4a.40.2@128k (44100Hz), 27.99MiB
          171 webm audio only DASH audio 133k , vorbis@128k, 20.75MiB
          251 webm audio only DASH audio 173k , opus @160k, 33.21MiB
          278 webm 256×144 144p 111k , webm container, vp9, 30fps, video only, 18.69MiB
          160 mp4 256×144 DASH video 131k , avc1.4d400c, 30fps, video only, 24.27MiB
          242 webm 426×240 240p 242k , vp9, 30fps, video only, 34.48MiB
          133 mp4 426×240 DASH video 289k , avc1.4d4015, 30fps, video only, 52.89MiB
          243 webm 640×360 360p 458k , vp9, 30fps, video only, 71.75MiB
          134 mp4 640×360 DASH video 639k , avc1.4d401e, 30fps, video only, 97.26MiB
          244 webm 854×480 480p 902k , vp9, 30fps, video only, 142.90MiB
          135 mp4 854×480 DASH video 1170k , avc1.4d401f, 30fps, video only, 212.64MiB
          247 webm 1280×720 720p 1774k , vp9, 30fps, video only, 298.21MiB
          136 mp4 1280×720 DASH video 2349k , avc1.4d401f, 30fps, video only, 435.87MiB
          248 webm 1920×1080 1080p 3152k , vp9, 30fps, video only, 544.27MiB
          137 mp4 1920×1080 DASH video 4564k , avc1.640028, 30fps, video only, 838.01MiB
          271 webm 2560×1440 1440p 10323k , vp9, 30fps, video only, 1.74GiB
          264 mp4 2560×1440 DASH video 10474k , avc1.640032, 30fps, video only, 1.65GiB
          313 webm 3840×2160 2160p 21768k , vp9, 30fps, video only, 3.91GiB
          266 mp4 3840×2160 DASH video 23236k , avc1.640033, 30fps, video only, 3.11GiB
          17 3gp 176×144 small , mp4v.20.3, mp4a.40.2@ 24k
          36 3gp 320×180 small , mp4v.20.3, mp4a.40.2
          43 webm 640×360 medium , vp8.0, vorbis@128k
          18 mp4 640×360 medium , avc1.42001E, mp4a.40.2@ 96k
          22 mp4 1280×720 hd720 , avc1.64001F, mp4a.40.2@192k (best)