如何使用 youtube_dl select 分辨率作为 YouTube 视频的输入

How to select resolution as an input for a YouTube video using youtube_dl

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {}
url = input("Enter your URL:")
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    if
    ydl.download([url])
print("Downloaded!")

默认情况下,它正在下载 360p 视频。但是,我想下载该特定视频的最佳分辨率。谁能帮帮我?谢谢。

使用 format 选项

如果您想要最好的视频格式,请使用 bestvideo.

示例:

url = input("Enter your URL:")

ydl = youtube_dl.YoutubeDL({
    'outtmpl': '/tmp/testvideo.mp4',
    'format':' bestvideo+bestaudio'
})

ydl.download([url])

编辑: 如果您想要将视频和音频放在一个文件中,请执行:

'format':' bestvideo[ext=mp4]+bestaudio[ext=mp4]/mp4'

而不是

'format':' bestvideo+bestaudio'