0

I have observed that the size of mp4 videos are larger than webm for a same resolution video. Which makes me wonder that either there is some quality loss or compression in webm.

youtube-dl -F url

Generally using the above code the 4k videos are shown in webm quality. Can we force download 4k videos as mp4 instead of webm?

1
  • 1
    Some formats simply have better compression than others so they can be smaller without any loss in quality. – jesse_b Aug 19 '20 at 21:23
6

You can find the available mp4 resolutions available for a video with:

youtube-dl --list-formats https://youtu.be/LXb3EKWsInQ | grep mp4

... 401 mp4 3840x2160 2160p60 18167k , av01.0.13M.10.0.110.09.16.09.0, 60fps, video only, 460.07MiB ...

For this example, you can find that 401 is the format number you need.

Then, use the -f flag:

youtube-dl -f 401 https://youtu.be/LXb3EKWsInQ

3
  • I tried this and found out that 4k mp4 video was 486 MB while 4k webm video was 1.22 GB. Which is contradicting my description that webm videos are smaller in size. While for another 1080p mp4 video was 80 MB in size while 1080p webm was 62 MB which supports my description. It's weird. – Vin Raghav Aug 19 '20 at 22:32
  • It's probably linked to the encoding method used for each format. – Hugh Aug 19 '20 at 23:16
  • This works perfectly and should be set as the correct solution. – Guenter Jan 27 at 15:47
1

You can use the --format/-f flag to specify the output format:

youtube-dl -f mp4 -F <url>

You can and probably should also specify that you want the best quality available:

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]' ...

By default youtube-dl uses -f bestvideo+bestaudio/best

If the video isn't available in 4k mp4 you can use the --recode-video postprocessing option to convert it: --recode-video mp4

8
  • This downloads 1080p mp4 video. – Vin Raghav Aug 19 '20 at 21:35
  • @VinRaghav: That means that video isn't available in 4k in mp4 format, so you would have to convert it post processing with the edit I made or using ffmpeg – jesse_b Aug 19 '20 at 21:36
  • The OP wanted the best video quality possible and you're offering to reencode it? Sounds weird. – Artem S. Tashkinov Aug 19 '20 at 21:39
  • @ArtemS.Tashkinov: I don't see where op said that, OP wants 4k mp4s which you can achieve by reencoding...re-encoding from webm to mp4 will be a loss in quality but you would never be able to notice it, it will be an increase in size though. – jesse_b Aug 19 '20 at 21:40
  • The OP said: "Which makes me wonder that either there is some quality loss or compression in webm." so he's asking something which is plain wrong - in other words you're trying to resolve an issue which isn't there. – Artem S. Tashkinov Aug 19 '20 at 21:45
-1

I have observed that the size of mp4 videos are larger than webm for a same resolution video. Which makes me wonder that either there is some quality loss or compression in webm.

Youtube's MP4 videos are encoded using the H.264/AVC codec.

Youtube's WEBM videos are usually encoded using the VP9 codec which is a much more efficient and newer codec which allows to compress video better (which means a smaller file size) while providing a perceptually better image quality.

Can we force download 4k videos as mp4 instead of webm?

Why force to download something which has a worse image quality and larger size? Also, YouTube has long stopped encoding >=4K videos into AVC/H.264 and they are now provided using VP9/AV1 codecs exclusively:

Here's an example (a video uploaded last week):

youtube-dl --list-formats https://www.youtube.com/watch?v=Cc5mchDdNdg | grep 2160
313          webm       3840x2160  2160p 17842k , vp9, 30fps, video only, 585.18MiB
315          webm       3840x2160  2160p60 26526k , vp9, 60fps, video only, 969.16MiB

No sight of AVC or MP4 - WEBM/VP9 only.

2
  • To answer the why question: some tvs and streaming devices wont support webm format. – jesse_b Aug 19 '20 at 21:35
  • Also if you look at Hugh's answer it does seem like some videos are available in 4k mp4 – jesse_b Aug 19 '20 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.