I See It, I Like It, I Want It, I youtube-dl It

youtube-dl is the best way to download high quality videos from YouTube. Instructions for how to install it are located here. The tool has a large API surface area and dense documentation which can result in a frustrating experience when you just want to download a video. If you see it, like it, want it, this guide will help you get it.

#List Available Formats

youtube-dl -F https://youtu.be/QYh6mYIJG2Y
[youtube] QYh6mYIJG2Y: Downloading webpage
[youtube] QYh6mYIJG2Y: Downloading video info webpage
[info] Available formats for QYh6mYIJG2Y:
format code  extension  resolution note
249          webm       audio only tiny   61k , opus @ 50k (48000Hz), 1.15MiB
250          webm       audio only tiny   79k , opus @ 70k (48000Hz), 1.50MiB
140          m4a        audio only tiny  130k , m4a_dash container, mp4a.40.2@128k (44100Hz), 2.86MiB
251          webm       audio only tiny  150k , opus @160k (48000Hz), 2.91MiB
394          mp4        256x144    144p   85k , av01.0.00M.08, 24fps, video only, 1.62MiB
278          webm       256x144    144p   98k , webm container, vp9, 24fps, video only, 1.94MiB
160          mp4        256x144    144p  110k , avc1.4d400c, 24fps, video only, 1.71MiB
395          mp4        426x240    240p  193k , av01.0.00M.08, 24fps, video only, 3.31MiB
242          webm       426x240    240p  221k , vp9, 24fps, video only, 3.52MiB
133          mp4        426x240    240p  294k , avc1.4d4015, 24fps, video only, 3.57MiB
396          mp4        640x360    360p  352k , av01.0.01M.08, 24fps, video only, 5.90MiB
243          webm       640x360    360p  408k , vp9, 24fps, video only, 6.27MiB
134          mp4        640x360    360p  573k , avc1.4d401e, 24fps, video only, 6.55MiB
397          mp4        854x480    480p  638k , av01.0.04M.08, 24fps, video only, 10.28MiB
135          mp4        854x480    480p  725k , avc1.4d401e, 24fps, video only, 8.95MiB
244          webm       854x480    480p  746k , vp9, 24fps, video only, 9.58MiB
136          mp4        1280x720   720p 1142k , avc1.4d401f, 24fps, video only, 13.73MiB
398          mp4        1280x720   720p 1279k , av01.0.05M.08, 24fps, video only, 20.58MiB
247          webm       1280x720   720p 1454k , vp9, 24fps, video only, 16.57MiB
399          mp4        1920x1080  1080p 2237k , av01.0.08M.08, 24fps, video only, 35.73MiB
248          webm       1920x1080  1080p 2659k , vp9, 24fps, video only, 41.98MiB
137          mp4        1920x1080  1080p 3965k , avc1.640028, 24fps, video only, 48.01MiB
18           mp4        640x360    360p  589k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 12.99MiB (best)

#Determine The Highest Quality Video+Audio Formats

Do not rely on the (best) note. Follow this simple algorithm instead.

  1. Find the largest video with the highest resolution in the desired format.
  2. Find the largest compatible audio.

Applying the algorithm to the example results in 248 and 251. I chose webm because I find it looks and plays better than mp4.


youtube-dl -f 248+251  https://youtu.be/QYh6mYIJG2Y
[youtube] QYh6mYIJG2Y: Downloading webpage
[youtube] QYh6mYIJG2Y: Downloading video info webpage
[download] Destination: Ariana Grande - 7 rings-QYh6mYIJG2Y.f248.webm
[download] 100% of 41.98MiB in 00:00
[download] Destination: Ariana Grande - 7 rings-QYh6mYIJG2Y.f251.webm
[download] 100% of 2.91MiB in 00:00
[ffmpeg] Merging formats into "Ariana Grande - 7 rings-QYh6mYIJG2Y.webm"
Deleting original file Ariana Grande - 7 rings-QYh6mYIJG2Y.f248.webm (pass -k to keep)
Deleting original file Ariana Grande - 7 rings-QYh6mYIJG2Y.f251.webm (pass -k to keep)

I used ffmpeg, a dependency of youtube-dl, to make the loop above.

ffmpeg -i input.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" -map "[v]" output.mp4

The command concatenates a reversed version of the clip to itself.