在 youtube-dl 上仅下载格式 mp4

Edg*_*ira 126 youtube-dl

如何使用下载-dl 通过 url 播放列表下载视频 仅格式 mp4 而不是格式.mkv或.webm?

我使用此命令下载视频: youtube-dl -itcv --yes-playlist https://www.youtube.com/playlist?list=....

此命令的结果是带有扩展名的视频.mp4,.mkv或.webm

小智 165

像这样(来源):

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' url
Run Code Online (Sandbox Code Playgroud)

  • 如果您不关心 OP 要求的特定格式,那么值得注意的是,自 2015 年以来,youtube-dl 的默认设置为 `-f bestvideo+bestaudio/best`,因此它已经设置为下载 bestvideo 和 bestaudio(和在生成的文件中自动将它们混合在一起)。来源:https://github.com/rg3/youtube-dl/blob/master/README.md#format-selection (8认同)
  • @s4y youtube-dl 确实会在需要时进行转码(`--audio-format` 选项),但您就在这里:该行不应该是这种情况,因为您正在强制 youtube-dl 下载两个文件( bestaudio[ext=mp4] 和 bestvideo[ext=m4a]) 具有相同类型的容器 (mp4),因此无论它们的内容如何,​​在重新混合时,它们都将堆叠在另一个 mp4 中,无需任何转码。 (2认同)

GAD*_*D3R 121

列出可用的格式类型:

youtube-dl -F url
Run Code Online (Sandbox Code Playgroud)

然后您可以通过输入格式代码的数字来选择下载某种格式类型(在下面的示例中11):

youtube-dl -f 11 url 
Run Code Online (Sandbox Code Playgroud)

来自webupd8 的示例

youtube-dl -F http://www.youtube.com/watch?v=3JZ_D3ELwOQ
Run Code Online (Sandbox Code Playgroud)

示例输出:

[youtube] Setting language
[youtube] 3JZ_D3ELwOQ: Downloading webpage
[youtube] 3JZ_D3ELwOQ: Downloading video info webpage
[youtube] 3JZ_D3ELwOQ: Extracting video information
[info] Available formats for 3JZ_D3ELwOQ:
format code extension resolution  note 
171         webm      audio only  DASH webm audio , audio@ 48k (worst)
140         m4a       audio only  DASH audio , audio@128k
160         mp4       192p        DASH video 
133         mp4       240p        DASH video 
134         mp4       360p        DASH video 
135         mp4       480p        DASH video 
136         mp4       720p        DASH video 
137         mp4       1080p       DASH video 
17          3gp       176x144     
36          3gp       320x240     
5           flv       400x240     
43          webm      640x360     
18          mp4       640x360     
22          mp4       1280x720    (best)
Run Code Online (Sandbox Code Playgroud)

您可以选择best并输入

youtube-dl -f 22 http://www.youtube.com/watch?v=3JZ_D3ELwOQ
Run Code Online (Sandbox Code Playgroud)

要获得最佳视频质量(1080p DASH - 格式“137”)和最佳音频质量(DASH 音频 - 格式“140”),您必须使用以下命令:

youtube-dl -f 137+140 http://www.youtube.com/watch?v=3JZ_D3ELwOQ
Run Code Online (Sandbox Code Playgroud)

编辑

您可以在此处获得更多选择

视频选择:

--playlist-start NUMBER          Playlist video to start at (default is 1)
--playlist-end NUMBER            Playlist video to end at (default is last)
--playlist-items ITEM_SPEC       Playlist video items to download. Specify
                             indices of the videos in the playlist
                             separated by commas like: "--playlist-items
                             1,2,5,8" if you want to download videos
                             indexed 1, 2, 5, 8 in the playlist. You can
                             specify range: "--playlist-items
                             1-3,7,10-13", it will download the videos
                             at index 1, 2, 3, 7, 10, 11, 12 and 13.
--match-title REGEX              Download only matching titles (regex or
                             caseless sub-string)
--reject-title REGEX             Skip download for matching titles (regex or
                             caseless sub-string)
--max-downloads NUMBER           Abort after downloading NUMBER files
--min-filesize SIZE              Do not download any videos smaller than
                             SIZE (e.g. 50k or 44.6m)
--max-filesize SIZE              Do not download any videos larger than SIZE
                             (e.g. 50k or 44.6m)
--date DATE                      Download only videos uploaded in this date
--datebefore DATE                Download only videos uploaded on or before
                             this date (i.e. inclusive)
--dateafter DATE                 Download only videos uploaded on or after
                             this date (i.e. inclusive)
--min-views COUNT                Do not download any videos with less than
                             COUNT views
--max-views COUNT                Do not download any videos with more than
                             COUNT views
--match-filter FILTER            Generic video filter (experimental).
                             Specify any key (see help for -o for a list
                             of available keys) to match if the key is
                             present, !key to check if the key is not
                             present,key > NUMBER (like "comment_count >
                             12", also works with >=, <, <=, !=, =) to
                             compare against a number, and & to require
                             multiple matches. Values which are not
                             known are excluded unless you put a
                             question mark (?) after the operator.For
                             example, to only match videos that have
                             been liked more than 100 times and disliked
                             less than 50 times (or the dislike
                             functionality is not available at the given
                             service), but who also have a description,
                             use --match-filter "like_count > 100 &
                             dislike_count <? 50 & description" .
--no-playlist                    Download only the video, if the URL refers
                             to a video and a playlist.
--yes-playlist                   Download the playlist, if the URL refers to
                             a video and a playlist.
--age-limit YEARS                Download only videos suitable for the given
                             age
--download-archive FILE          Download only videos not listed in the
                             archive file. Record the IDs of all
                             downloaded videos in it.
--include-ads                    Download advertisements as well
                             (experimental)
Run Code Online (Sandbox Code Playgroud)

  • @EdgarOliveira 播放列表中经常有一些已删除的视频,但 YouTube 继续包含在播放列表中......这是否导致了问题 (2认同)

Fra*_*ing 28

根据glenn-slayden的这篇评论,获得视频质量最高的mp4格式如下:

我意识到这个线程有点旧,但我认为情况有所改变。为了我的目标:

  • 首先,无论格式如何,始终采用最佳的可用视频质量;
  • 但是永远不要让音频格式单独导致您丢失mp4。

以前,我使用的是bestvideo+bestaudio/best,但我发现以下变体更适合减少mkv,(显然)消除webm,但仍然保证最高质量的视频(使用--merge-output-format时不要使用该选项):

--format bestvideo+bestaudio[ext=m4a]/bestvideo+bestaudio/best 
Run Code Online (Sandbox Code Playgroud)

请注意,在第一项中,ext过滤器是为音频而不是视频指定的,我在上面的讨论中没有看到这种技术。如果这似乎与我既定的目标背道而驰,那可能是因为,考虑到我们正在努力确保视频格式为mp4,为什么要为音频提供约束?

关键是每个回退条款(由斜线分隔)如果其要求的任何部分失败,都会失败,进入下一个条款。使用 时bestvideo+bestaudio,许多获得非 mp4 容器的情况只会出现,因为该格式选择明确坚持bestaudio,这可能意味着混合格式。那是因为bestvideo+bestaudio命令太坚持了,你被迫退出mp4.

但是,如果您更关心获得一个mp4 容器而不是音频质量呢?通过坚持m4a音频第一-但随后就只是部分缓和了,而发行bestvideo一次- (使用格式选择以上)基本上只是表达一个灵活的偏好为mp4在其他容器; 如果可能,您肯定确实想要mp4,但不能以降低视频质量为代价。

正如我所说,您可能仍然会得到一些mkv,但它们的数量将大大减少,并且仅在需要提供(据称)更好的视频时使用。到目前为止,使用这种配置,我还没有看到任何webm东西,因为248+140 之类的东西最终会变成mkv.

在后一种情况下,--merge-output-format mp4如果需要,添加将转换为 mp4。所以完整的命令是:

youtube-dl --format "bestvideo+bestaudio[ext=m4a]/bestvideo+bestaudio/best" --merge-output-format mp4
Run Code Online (Sandbox Code Playgroud)


fel*_*the 6

您可以使用youtube-dl -f mp4 <url>.

我不确定这样做是否合适,只是它可以工作,并为 mp4 格式提供具有最高质量音频和视频的 mp4 文件。

此文件与使用 获得的文件略有不同-f <the best options>,尽管流似乎相同。我在视频上都尝试了:-f mp4,然后-f 137+140(手动选择最佳音频和视频)。ffprobe 对通过以下方式获得的文件进行了说明-f mp4:

Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2019-06-23T18:39:33.000000Z
    Duration: 00:00:56.01, start: 0.000000, bitrate: 906 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 775 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
      creation_time   : 2019-06-23T18:39:33.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 06/23/2019.
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
      creation_time   : 2019-06-23T18:39:33.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 06/23/2019.
Run Code Online (Sandbox Code Playgroud)

这是关于通过以下方式获得的文件-f 137+140:

  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.9.100
  Duration: 00:00:56.05, start: 0.000000, bitrate: 909 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 775 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Run Code Online (Sandbox Code Playgroud)

因此视频和音频流看起来相同,但使用了不同的复用器(如果我正确使用该术语)将它们组合在一起形成最终文件。