video-download

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

video-download

视频下载

Download video and audio from URLs using yt-dlp directly. No wrapper scripts needed.
直接使用yt-dlp从URL下载视频和音频,无需包装脚本。

Prerequisites

前置要求

  • yt-dlp:
    brew install yt-dlp
    or
    pip install yt-dlp
  • ffmpeg:
    brew install ffmpeg
    or
    apt install ffmpeg
    (required for merging video+audio streams)
Update yt-dlp periodically to keep up with site changes:
yt-dlp -U
or
pip install -U yt-dlp
.
  • yt-dlp
    brew install yt-dlp
    pip install yt-dlp
  • ffmpeg
    brew install ffmpeg
    apt install ffmpeg
    (合并视频+音频流时必需)
定期更新yt-dlp以适配平台变化:
yt-dlp -U
pip install -U yt-dlp

Commands

命令说明

Download best quality

下载最佳画质视频

bash
yt-dlp "URL" -o "%(title)s.%(ext)s" --merge-output-format mp4
bash
yt-dlp "URL" -o "%(title)s.%(ext)s" --merge-output-format mp4

Download specific resolution

下载指定分辨率视频

bash
undefined
bash
undefined

720p

720p

yt-dlp "URL" -f "bestvideo[height<=720]+bestaudio/best[height<=720]" --merge-output-format mp4
yt-dlp "URL" -f "bestvideo[height<=720]+bestaudio/best[height<=720]" --merge-output-format mp4

1080p

1080p

yt-dlp "URL" -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" --merge-output-format mp4
undefined
yt-dlp "URL" -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" --merge-output-format mp4
undefined

Audio only

仅下载音频

bash
yt-dlp "URL" -x --audio-format mp3 --audio-quality 0
bash
yt-dlp "URL" -x --audio-format mp3 --audio-quality 0

Download subtitles

下载字幕

bash
undefined
bash
undefined

Download video with English subtitles

下载带英文字幕的视频

yt-dlp "URL" --write-subs --sub-langs en --merge-output-format mp4
yt-dlp "URL" --write-subs --sub-langs en --merge-output-format mp4

Download video with multiple subtitle languages

下载带多语言字幕的视频

yt-dlp "URL" --write-subs --sub-langs "en,es,fr" --merge-output-format mp4
yt-dlp "URL" --write-subs --sub-langs "en,es,fr" --merge-output-format mp4

Download only subtitles (no video)

仅下载字幕(不下载视频)

yt-dlp "URL" --write-subs --sub-langs en --skip-download
undefined
yt-dlp "URL" --write-subs --sub-langs en --skip-download
undefined

Get metadata (no download)

获取元数据(无需下载)

bash
yt-dlp "URL" --dump-json --no-download
bash
yt-dlp "URL" --dump-json --no-download

List available formats

列出可用格式

bash
yt-dlp "URL" -F
bash
yt-dlp "URL" -F

Specify output directory

指定输出目录

bash
yt-dlp "URL" -o "./downloads/%(title)s.%(ext)s" --merge-output-format mp4
bash
yt-dlp "URL" -o "./downloads/%(title)s.%(ext)s" --merge-output-format mp4

Quality Presets

画质预设

QualityFormat flag
Best
-f "bestvideo+bestaudio/best"
(default)
1080p
-f "bestvideo[height<=1080]+bestaudio/best[height<=1080]"
720p
-f "bestvideo[height<=720]+bestaudio/best[height<=720]"
480p
-f "bestvideo[height<=480]+bestaudio/best[height<=480]"
Worst
-f "worstvideo+worstaudio/worst"
画质格式参数
最佳
-f "bestvideo+bestaudio/best"
(默认)
1080p
-f "bestvideo[height<=1080]+bestaudio/best[height<=1080]"
720p
-f "bestvideo[height<=720]+bestaudio/best[height<=720]"
480p
-f "bestvideo[height<=480]+bestaudio/best[height<=480]"
最差
-f "worstvideo+worstaudio/worst"

Output Template Variables

输出模板变量

Common variables for
-o
templates:
VariableDescription
%(title)s
Video title
%(ext)s
File extension
%(id)s
Video ID
%(uploader)s
Channel/uploader name
%(upload_date)s
Upload date (YYYYMMDD)
%(duration)s
Duration in seconds
%(resolution)s
Video resolution
用于
-o
模板的常用变量:
变量说明
%(title)s
视频标题
%(ext)s
文件扩展名
%(id)s
视频ID
%(uploader)s
频道/上传者名称
%(upload_date)s
上传日期(YYYYMMDD)
%(duration)s
时长(秒)
%(resolution)s
视频分辨率

Tips

小贴士

  • Always use
    --merge-output-format mp4
    to avoid ending up with
    .webm
    or
    .mkv
    files.
  • Use
    --no-download
    with
    --dump-json
    for metadata-only queries -- no files written to disk.
  • If a download fails with HTTP errors, update yt-dlp first (
    yt-dlp -U
    ).
  • Use
    -f "bestvideo[height<=720]+bestaudio"
    to save bandwidth when full resolution is not needed.
  • yt-dlp automatically handles rate limiting and retries.
  • The
    --dump-json
    output includes
    title
    ,
    duration
    ,
    uploader
    ,
    view_count
    ,
    description
    ,
    formats
    ,
    subtitles
    , and much more.
  • 始终使用
    --merge-output-format mp4
    参数,避免生成
    .webm
    .mkv
    格式文件。
  • 搭配
    --no-download
    --dump-json
    参数仅查询元数据,不会向磁盘写入文件。
  • 如果下载时出现HTTP错误,先更新yt-dlp(
    yt-dlp -U
    )。
  • 无需全分辨率时,使用
    -f "bestvideo[height<=720]+bestaudio"
    以节省带宽。
  • yt-dlp会自动处理速率限制和重试。
  • --dump-json
    的输出包含
    title
    duration
    uploader
    view_count
    description
    formats
    subtitles
    等大量信息。

Troubleshooting

故障排查

  • "yt-dlp: command not found": Install it (
    pip install yt-dlp
    ) and ensure your PATH includes pip's bin directory.
  • "ffmpeg: command not found": Install ffmpeg. Without it, downloads fail when video and audio are separate streams (common on YouTube for HD).
  • Downloads fail or return errors: Run
    yt-dlp -U
    to update. Sites change frequently and yt-dlp ships fixes regularly.
  • "yt-dlp: command not found":安装yt-dlp(
    pip install yt-dlp
    )并确保你的PATH包含pip的bin目录。
  • "ffmpeg: command not found":安装ffmpeg。如果没有它,当视频和音频流分离时(YouTube高清视频常见情况),下载会失败。
  • 下载失败或返回错误:运行
    yt-dlp -U
    更新工具。平台会频繁变化,yt-dlp会定期发布修复补丁。