[TUTORIAL] yt-dlp (CLI YouTube Downloader) - .mp4 instead of WebM

For those who use yt-dlp to download YouTube videos

  • yt-dlp defaults to .webm when downloading. Here’s how to get .mp4.
  • In addition to yt-dlp, make sure you have ffmpeg installed. It’s available in the Arch Extra Repo
  1. Example YouTube Video Link: The standard, default for using yt-dlp would be…
    yt-dlp https://www.youtube.com/watch?v=3Q6uCrpzbPY
    This provides a .webm file.

  2. I researched how to get an .mp4 instead. If you would like to have an .mp4 instead, add -S res,ext:mp4:m4a --recode mp4 to the download command. So the full command for the example video above would be…
    yt-dlp https://www.youtube.com/watch?v=3Q6uCrpzbPY -S res,ext:mp4:m4a --recode mp4
    This downloads mp4/m4a if available, and if not, will download the best available format(s) and recode/merge to mp4.

  3. I’ve tried 7 YouTube videos using this and, so far, it’s worked 100% of the time.

  4. As with any tutorial, your mileage may vary.

RELEVANT EDITS -

  • EDIT: If you’re using the fish shell, you’ll need a single ' and the beginning and end of the desired YouTube video link in the command. Like this…
    yt-dlp 'https://www.youtube.com/watch?v=3Q6uCrpzbPY' -S res,ext:mp4:m4a --recode mp4

  • EDIT 2: These also work well (using the example video above).

  1. From @pebcak -
    yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]' https://www.youtube.com/watch?v=3Q6uCrpzbPY

  2. From @thefrog -
    yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' -o storepath'%(title)s.%(ext)s' https://www.youtube.com/watch?v=3Q6uCrpzbPY

9 Likes

How about yt-dlp --format mp4 <URL> ?

Yes, yt-dlp --format mp4 'https://www.youtube.com/watch?v=3Q6uCrpzbPY' works. But it downloads either 360p or 480p, not the best available quality as yt-dlp 'https://www.youtube.com/watch?v=3Q6uCrpzbPY' -S res,ext:mp4:m4a --recode mp4 does.

Perhaps I misunderstood

So if mp4/m4a is available, will the download default to 360p or 480p?

If 360 or 480 is the best available quality for the video in question, then yes.

I’m up to 11 test downloads using the method I showed. All have been best quality available. Two were at 4k (3840x2160), one was at 2k (2560x1440) seven were at 1080p and one at 720p.

yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' -o $storepath'%(title)s.%(ext)s' $url

the above has always given me the best downloads

2 Likes

Alright.

Were these available as mp4 already or they were converted to mp4 from other formats?

For best video and audio for mp4 (if available) the following should work as well:

yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]' <URL>

1 Like

Not sure, though from my OP if .mp4 isn’t available, it recodes to .mp4. Adding -S res,ext:mp4:m4a --recode mp4 downloads mp4/m4a if available, and if not, will download the best available format(s) and recode/merge to mp4.

1 Like

@pebcak, this does work well:
yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]' 'https://www.youtube.com/watch?v=kWB6PhByJ2s'

@thefrog, this also worked well:
yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' -o storepath'%(title)s.%(ext)s' 'https://www.youtube.com/watch?v=kWB6PhByJ2s'

2 Likes

Yes. I have actually tried your command and what I had was a low bitrate video.

1 Like