Skip to content

Instantly share code, notes, and snippets.

@br4instormer
Last active September 24, 2024 17:02
Show Gist options
  • Save br4instormer/33c68d83cbe9e6d7166d52e00cf42eb9 to your computer and use it in GitHub Desktop.
Save br4instormer/33c68d83cbe9e6d7166d52e00cf42eb9 to your computer and use it in GitHub Desktop.
Download one video from youtube in mkv container with chapters and metadata

How to download one video from youtube in mkv container with chapters and metadata

We will use yt-dlp application

Dependencies

  • python-3
  • yt-dlp
  • ffmpeg

Install

We asume python is already installed

pip install -U yt-dlp[default,curl_cffi]
yt-dlp --version

To download Youtube Shorts you must install nightly version of yt-dlp

pip install -U yt-dlp[default,curl_cffi]
yt-dlp --version

Collect info about video

yt-dlp -F $'<yt-video>'

Downloading

We download best quality audio track and best quality video track

--add-chapters - add chapters into container --embed-thumbnail - add thumbnail as cover --embed-subs - add subs into container if it possible --remux-video 'mp4/mkv' - remux source video into mkv -N 3 - use n threads to download chunks

You may use

  • --windows-filenames to convert filename into windows-compatible. Or --restrict-filenames to convert into ASCII characters

  • --compat-options no-live-chat to avoid downloading livechat

  • --proxy socks5://server:port to use proxy

  • -o '%(title)s' to exact filename is just video title

yt-dlp -N 3 -f 'bv[ext=mp4]+ba[ext=webm]' --embed-thumbnail --add-chapters --embed-subs --remux-video 'mp4/mkv' --compat-options no-live-chat -o '%(title)s' $'<yt-video>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment