Youtube-dl: Difference between revisions

From Leo's Notes
This page was last edited on 30 December 2021, at 02:30.
m Text replacement - "Category:Linux" to "Category:Linux{{Navbox Linux}}"
Added info on yt-dlp
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Basic Usage ==
Youtube-dl is a python based utility that downloads Youtube videos. As of 2021, there is a fork called yt-dlp (https://github.com/yt-dlp/yt-dlp) which includes additional features such as SponsorBlock integration as well as fixes that is causing youtube-dl to download at a slow speed (~50kb/s).
 
==Basic Usage==
To download a video with {{code|youtube-dl}}, just pass the YouTube URL as an argument. This will download the video in the highest quality.
To download a video with {{code|youtube-dl}}, just pass the YouTube URL as an argument. This will download the video in the highest quality.
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
Line 5: Line 7:
}}
}}


=== Listing All Available Formats ===
===Listing All Available Formats===
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
$ youtube-dl -F "http://youtube.com/watch?v=xxx"
$ youtube-dl -F "http://youtube.com/watch?v=xxx"
}}
}}


=== Download a Specific Format ===
===Download a Specific Format===
Say you want to download just the DASH audio from a video:
Say you want to download just the DASH audio from a video:
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
Line 16: Line 18:
}}
}}


== Downloading Audio ==
===Downloading Audio===
When downloading DASH audio using {{code|youtube-dl}}, you must convert the audio in order to play it using an audio player using {{code|ffmpeg}}.
When downloading DASH audio using {{code|youtube-dl}}, you must convert the audio in order to play it using an audio player using {{code|ffmpeg}}.
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
Line 24: Line 26:
This is needed since the MP4 container from youtube is set to dash rather than m4a and isn't recognized by most players.
This is needed since the MP4 container from youtube is set to dash rather than m4a and isn't recognized by most players.


== Other ==
===Download with (auto-generated) subtitles===
=== Merging Audio / Video ===
List all subtitles that are available for a video with:{{highlight|lang=terminal|code=
$ youtube-dl --list-subs "http://youtube.com/watch?v=xxx"
Available automatic captions for xxx
Language formats
af      vtt, ttml, srv3, srv2, srv1
...
}}To retrieve autogenerated subtitles, specify the desired language(s) and pass in the --write-auto-sub:{{highlight|lang=terminal|code=
$ youtube-dl --write-auto-sub --sub-lang de,en "http://youtube.com/watch?v=xxx"
}}You may also download a subtitle after the fact separately, but you may want to also convert the .vtt file to a .srt with ffmpeg:{{highlight|lang=terminal|code=
$ youtube-dl --write-sub --sub-lang de "http://youtube.com/watch?v=xxx"
## This creates a .vtt subtitle. Convert with:
$ ffmpeg -i *vtt out.srt
}}
 
==Other==
===Merging Audio / Video===
This is the command {{code|youtube-dl}} invokes in order to merge audio and video.
This is the command {{code|youtube-dl}} invokes in order to merge audio and video.
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
Line 31: Line 48:
}}
}}


[[Category:Linux]]{{Navbox Linux}}
== Troubleshooting ==
 
=== Youtube-dl is downloading videos very slowly ===
This is a known issue which has recently started happening. Users report that this issue is fixed by using yt-dlp (https://github.com/yt-dlp/yt-dlp<nowiki/>).{{Navbox Linux}}
[[Category:Linux]]
[[Category:LinuxUtilities]]

Latest revision as of 02:30, 30 December 2021

Youtube-dl is a python based utility that downloads Youtube videos. As of 2021, there is a fork called yt-dlp (https://github.com/yt-dlp/yt-dlp) which includes additional features such as SponsorBlock integration as well as fixes that is causing youtube-dl to download at a slow speed (~50kb/s).

Basic Usage

To download a video with youtube-dl, just pass the YouTube URL as an argument. This will download the video in the highest quality.

$ youtube-dl "http://youtube.com/watch?v=xxx"

Listing All Available Formats

$ youtube-dl -F "http://youtube.com/watch?v=xxx"

Download a Specific Format

Say you want to download just the DASH audio from a video:

$ youtube-dl -f 141 "http://youtube.com/watch?v=xxx"

Downloading Audio

When downloading DASH audio using youtube-dl, you must convert the audio in order to play it using an audio player using ffmpeg.

$ ffmpeg -i input.m4a -vn -acodec copy output.m4a

This is needed since the MP4 container from youtube is set to dash rather than m4a and isn't recognized by most players.

Download with (auto-generated) subtitles

List all subtitles that are available for a video with:

$ youtube-dl --list-subs "http://youtube.com/watch?v=xxx"
Available automatic captions for xxx
Language formats
af       vtt, ttml, srv3, srv2, srv1
...

To retrieve autogenerated subtitles, specify the desired language(s) and pass in the --write-auto-sub:

$ youtube-dl --write-auto-sub --sub-lang de,en "http://youtube.com/watch?v=xxx"

You may also download a subtitle after the fact separately, but you may want to also convert the .vtt file to a .srt with ffmpeg:

$ youtube-dl --write-sub --sub-lang de "http://youtube.com/watch?v=xxx"
## This creates a .vtt subtitle. Convert with:
$ ffmpeg -i *vtt out.srt

Other

Merging Audio / Video

This is the command youtube-dl invokes in order to merge audio and video.

$ ffmpeg command line: ffmpeg -y -i 'file:V.webm' -i 'file:A.m4a' -c copy -map 0:v:0 -map 1:a:0 'file:AV.mkv'

Troubleshooting

Youtube-dl is downloading videos very slowly

This is a known issue which has recently started happening. Users report that this issue is fixed by using yt-dlp (https://github.com/yt-dlp/yt-dlp).