Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-f bestvideo+bestaudio with only mp4 codecs #4886

Closed
ericzutter opened this issue Feb 6, 2015 · 19 comments

Comments

Projects
None yet
9 participants
@ericzutter
Copy link

commented Feb 6, 2015

How to get best video + best audio for mp4 container format ?

  • the parameter "-f mp4" doesn't download highest video resolution and highest audio resolution because it doesn't work with DASH
  • the parameter "-f bestvideo+bestaudio" downloads sometimes webm codecs instead of mp4
    codecs
  • the parameter "-f bestvideo+bestaudio --merge-output-format mp4" doesn't force to download only mp4 codecs

The ideal parameter would be: -f "bestvideo[container=mp4]"+"bestaudio[container=mp4]"
But this parameter doesn't work.

Is there another way to use the parameter "-f bestvideo+bestaudio" and force to use only mp4 codecs and skip webm codecs ?

@mati8

This comment has been minimized.

Copy link

commented Feb 7, 2015

I have EXACTLY the same problem, and I don't know how to solve it.
I even tried with something like:

youtube-dl https://www.youtube.com/watch?v=..... -f 299/137/298/136+141 to let the youtube-dl download the best video from the format list, but it doesn't work.

So I tried youtube-dl https://www.youtube.com/watch?v=..... -f [299/137/298/136]+141
or
youtube-dl https://www.youtube.com/watch?v=..... -f "299/137/298/136"+141
or
youtube-dl https://www.youtube.com/watch?v=..... -f mp4+141

but don't work too.

How can we do?
Thank you!!

@chrisaljoudi

This comment has been minimized.

Copy link

commented Feb 8, 2015

youtube-dl -f 137+bestaudio https://www.youtube.com/watch?v=RS5mzvqWM-c

That should do it.

@mati8

This comment has been minimized.

Copy link

commented Feb 8, 2015

It doesn't work, because 137 is not always the best mp4 quality. 137 is 1080p 30fps.
If the video is at 60fps for example this doesn't work, same if the video has a highest resolution.

@chrisaljoudi

This comment has been minimized.

Copy link

commented Feb 8, 2015

@mati8 @ericzutter sure, but that's why you have youtube-dl -F https://www.youtube.com/watch?v=RS5mzvqWM-c

It lists the formats along with their identifier.

Something like bestvideo[container=mp4] would be starting to get pretty silly. If you must have "mp4" (which is to say the MP4 container with h264) and it must be the best you can get, transcode bestvideo after it's downloaded.

@mati8

This comment has been minimized.

Copy link

commented Feb 8, 2015

@chrisaljoudi you don't understand the problem.

  • If you want to download the best DASH video, and put it together with the best audio, there is no way to do it. 137+bestaudio will download the 1080p 30fps only and combine with bestaudio.
  • Sometimes youtube-dl downloads webm file if you write bestvideo+bestaudio, that you CAN'T merge webm with the best audio.

Of course it would be possible to transcode the webm file to mp4 and then merge it with audio, but at the moment it's not possible with youtube-dl.

Question:
how can I choose the video format from a list and merge it with the best audio?
[299/137/298/136]+bestaudio doesn't work. If I take away the brackets too, of course it doesn't work well.
Thank you!

@chrisaljoudi

This comment has been minimized.

Copy link

commented Feb 8, 2015

@mati8

If you want to download the best DASH video, and put it together with the best audio, there is no way to do it. 137+bestaudio will download the 1080p 30fps only.

I only mentioned that because the original post (and issue) said "mp4 only". Do you see that?

Sometimes youtube-dl downloads webm file, that you CAN'T merge with the best audio.

Why do you think you can't combine webm with audio?

If you want the best video and the best audio (from DASH), youtube-dl -f bestvideo+bestaudio will work.

If it doesn't, please share an example. It most certainly should.


On a completely separate note (you shouldn't have to do this), this works fine:

youtube-dl -f 136/244/278+bestaudio https://www.youtube.com/watch?v=FglqN1jd1tM
@mati8

This comment has been minimized.

Copy link

commented Feb 8, 2015

@chrisaljoudi DASH video can be mp4 too. "DASH" is not a video format.
This is the example that doesn't work:

youtube-dl https://www.youtube.com/watch?v=-da2L9wY-rc -f bestvideo+bestaudio

It downloads the webm, and it's not possible to combine it with the best audio.

@mati8

This comment has been minimized.

Copy link

commented Feb 8, 2015

It should be added a function to download the best mp4 DASH, to combine it with the best audio.

@chrisaljoudi
Just to be clear for other people who will read, what you said it's not correct, because this:
299/137/298/136+bestaudio doesn't work because it does something like:
download 299 OR 137 OR 298 OR [136+bestaudio]

Let's try:
youtube-dl https://www.youtube.com/watch?v=-da2L9wY-rc -f 299/137/134+bestaudio

It will download just the 137.
If 137 is not present, it will download the 134+audio and will combine them.

So it should be something like this:
youtube-dl https://www.youtube.com/watch?v=-da2L9wY-rc -f [299/137/134]+bestaudio
but of course this doesn't work becuase brackets in this case are not supported.

@chrisaljoudi

This comment has been minimized.

Copy link

commented Feb 8, 2015

@mati8 I never said anything to the effect that DASH is a video format.

DASH video can be mp4 too. "DASH" is not a video format.

I know that. The reason we're talking about mp4 is what this issue is. Did you read the original issue? Here's a quote:

How to get best video + best audio for mp4 container format ?

and

The ideal parameter would be: -f "bestvideo[container=mp4]"+"bestaudio[container=mp4]"

I get what you're saying, but you keep redefining the problem. There are two possible sources:

  • Stuff from the DASH manifest. Audio and video come separately — video can be in webm or mp4, and maybe others.
  • Stuff not from the DASH manifest. Those come with the audio/video premuxed. Typically mp4 for the highest bitrate one.

MP4 (a container) does not support webm as a video codec. Transcode, or use mkv instead.

because it does something like: download 299 OR 137 OR 298 OR [136+bestaudio]

Ah, you're right. 299+bestaudio/137+bestaudio/298+bestaudio/136+bestaudio should work — sorry. (I agree that's not great, though).

@mati8

This comment has been minimized.

Copy link

commented Feb 8, 2015

@chrisaljoudi what I think it would be great, it's to download the best "mp4" DASH, and combine it with the bestaudio.
because in this case it shows an error:
youtube-dl https://www.youtube.com/watch?v=-da2L9wY-rc -f bestvideo+bestaudio

Did you try it?
Thank you!

@chrisaljoudi

This comment has been minimized.

Copy link

commented Feb 8, 2015

@mati8 yes, indeed it will show an error — webm is video-only, and you didn't specify a container to use for merging. You can't merge webm into m4a or vice-versa. Specify a container, and it all works.

This, for example, works great:

youtube-dl -f bestvideo+bestaudio --merge-output-format mkv https://www.youtube.com/watch?v=-da2L9wY-rc

To warn you, this will fail in your case:

youtube-dl -f bestvideo+bestaudio --merge-output-format mp4 https://www.youtube.com/watch?v=-da2L9wY-rc

Because mp4 as a container does not support webm as a video codec.

@phihag

This comment has been minimized.

Copy link
Collaborator

commented Feb 8, 2015

@mati8 If there is an error, please do open a new issue (do not forget to include the output you get when you add -v). While adding a filter for mp4 only may solve your problem, we want to fix the error in the first place. For what it's worth, works fine for me:

$ youtube-dl https://www.youtube.com/watch?v=-da2L9wY-rc -f bestvideo+bestaudio -v
[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['https://www.youtube.com/watch?v=-da2L9wY-rc', '-f', 'bestvideo+bestaudio', '-v']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2015.01.30.1
[debug] Python version 2.7.9 - Linux-3.14.17-x86_64-with-debian-8.0
[debug] exe versions: ffmpeg 2.5.3-1, ffprobe 2.5.3-1, rtmpdump 2.4
[debug] Proxy map: {}
[youtube] -da2L9wY-rc: Downloading webpage
[youtube] -da2L9wY-rc: Extracting video information
[youtube] -da2L9wY-rc: Downloading DASH manifest
[debug] Invoking downloader on '*snip for length*'
[download] Destination: GoPro Hero3 Silver Edition 1080p 30fps--da2L9wY-rc.f137.mp4
[download] 100% of 66.71MiB in 00:07
[debug] Invoking downloader on '*snip for length*'
[download] Destination: GoPro Hero3 Silver Edition 1080p 30fps--da2L9wY-rc.f141.m4a
[download] 100% of 4.12MiB in 00:00
[ffmpeg] Merging formats into "GoPro Hero3 Silver Edition 1080p 30fps--da2L9wY-rc.mp4"
[debug] ffmpeg command line: ffmpeg -y -i 'GoPro Hero3 Silver Edition 1080p 30fps--da2L9wY-rc.f137.mp4' -i 'GoPro Hero3 Silver Edition 1080p 30fps--da2L9wY-rc.f141.m4a' -c copy -map 0:v:0 -map 1:a:0 'GoPro Hero3 Silver Edition 1080p 30fps--da2L9wY-rc.mp4'
@chrisaljoudi

This comment has been minimized.

Copy link

commented Feb 8, 2015

@phihag the error occurs when bestvideo resolves to a .webm file. At one level, it's not youtube-dl's fault per se; one is trying to merge a .webm with .m4a, and that's ambiguous for ffmpeg without a container format to contain both of them. This can be solved by setting --merge-output-format.

Furthermore, if the container is mp4 (so --merge-output-format mp4), that will fail with webm because mp4 does not support webm as a video codec.

--merge-output-format mkv should work fine for that, though.

@ericzutter

This comment has been minimized.

Copy link
Author

commented Feb 9, 2015

The following help info has been added to youtube-dl version 2015.02.09.1 :

youtube-dl.exe --help

You can filter the video results by putting a condition in brackets, as in -f "best[height=720]" (or -f "filesize>10M]"). This works for filesize, height, width, tbr, abr, vbr, asr, and fps and the comparisons <, <=, >, >=, =, != and for ext, acodec, vcodec, container, and protocol and the comparison =, != .

The following example worked (= download best video + audio codec for mp4 container) :

youtube-dl -f bestvideo[ext=mp4]+bestaudio https://www.youtube.com/watch?v=_YIae5mwmNU

I don't know what will happen if a video contains no DASH. Will the option "-f bestvideo[ext=mp4]+bestaudio" download the best video/audio for mp4 container when there are no DASH formats ?

In the help info they added the filters container/vcodec/acodec/protocol. But the following examples didn't work :

youtube-dl -f bestvideo[container=mp4]+bestaudio https://www.youtube.com/watch?v=_YIae5mwmNU
ERROR: requested format not available

youtube-dl -f bestvideo[container=mp4]+bestaudio[container=mp4] https://www.youtube.com/watch?v=_YIae5mwmNU
ERROR: requested format not available

youtube-dl -f bestvideo[vcodec=h264]+bestaudio https://www.youtube.com/watch?v=_YIae5mwmNU
ERROR: requested format not available

youtube-dl -f bestvideo[vcodec=avc]+bestaudio https://www.youtube.com/watch?v=_YIae5mwmNU
ERROR: requested format not available

youtube-dl -f bestvideo[vcodec=mp4]+bestaudio https://www.youtube.com/watch?v=_YIae5mwmNU
ERROR: requested format not available

How to use the new filter options container/vcodec/acodec/protocol ?

@Yhonay

This comment has been minimized.

Copy link

commented Apr 21, 2015

How does the bestvideo actually work? Because for this video:
https://www.youtube.com/watch?v=InxwGZ_PgC4
-f bestvideo[ext=mp4]+bestaudio downloads 240p version (while there is 1080p available)

$ youtube-dl -F https://www.youtube.com/watch?v=InxwGZ_PgC4
[youtube] InxwGZ_PgC4: Downloading webpage
[youtube] InxwGZ_PgC4: Extracting video information
WARNING: video doesn't have subtitles
[youtube] InxwGZ_PgC4: Downloading DASH manifest
[info] Available formats for InxwGZ_PgC4:
format code  extension  resolution note
140          m4a        audio only DASH audio  129k , m4a_dash container, aac  @128k (44100Hz), 4.20MiB
171          webm       audio only DASH audio  138k , audio@128k (44100Hz), 4.19MiB
141          m4a        audio only DASH audio  256k , m4a_dash container, aac  @256k (44100Hz), 8.35MiB
134          mp4        640x360    DASH video   28k , 30fps, video only, 766.85KiB
242          webm       426x240    DASH video   29k , 1fps, video only, 859.75KiB
135          mp4        854x480    DASH video   39k , 30fps, video only, 1.05MiB
243          webm       640x360    DASH video   44k , 1fps, video only, 1.26MiB
136          mp4        1280x720   DASH video   56k , 30fps, video only, 1.59MiB
160          mp4        256x144    DASH video   64k , 15fps, video only, 1.15MiB
244          webm       854x480    DASH video   69k , 1fps, video only, 1.90MiB
137          mp4        1920x1080  DASH video   83k , 30fps, video only, 2.37MiB
133          mp4        426x240    DASH video  111k , 30fps, video only, 2.13MiB
247          webm       1280x720   DASH video  118k , 1fps, video only, 2.98MiB
248          webm       1920x1080  DASH video  176k , 1fps, video only, 4.36MiB
17           3gp        176x144    
36           3gp        320x240    
5            flv        400x240    
43           webm       640x360    
18           mp4        640x360    
22           mp4        1280x720   (best)
@jaimeMF

This comment has been minimized.

Copy link
Collaborator

commented Apr 21, 2015

@Yhonay open anew issue for that.

@ericzutter Not all formats have the same info available, so some of the filters won't match anything. If you only want mp4 files, using -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4 is enough. Since that's what the issue was originally for, I'm closing it.

@jaimeMF jaimeMF closed this Apr 21, 2015

@glenn-slayden

This comment has been minimized.

Copy link

commented Oct 4, 2017

I realize this thread is a bit old, but I think the situation has changed somewhat. For my goal:

  • first and foremost always take the best available video quality regardless of format;
  • but then never let the audio format alone cause you to lose mp4.

Previously, I was using bestvideo+bestaudio/best, but I find the following variant works much better for reducing mkv, (apparently) eliminating webm, but yet still guaranteeing the highest quality video (don't use the --merge-output-format option when using this):

--format bestvideo+bestaudio[ext=m4a]/bestvideo+bestaudio/best 

Notice that, in the first term, the ext filter is specified for the audio but not the video, a technique which I didn't see mentioned in the discussion above. If that seems backwards for my stated goals, that might be because, considering that we're trying to ensure that the video format is mp4, why is the constraint given for the audio?

The key is that each fallback term (separated by the slashes) will fail if any part of its requirement fails, moving on to the next term. When using bestvideo+bestaudio, many cases of getting a non-mp4 container only show up because that format selection unequivocally insists on bestaudio, which may then mean a mixed format. It's because the bestvideo+bestaudio command is too insistent that you get forced out of mp4.

But what if you care more about getting a mp4 container than you do about the audio quality? By insisting on m4a audio first--but then relenting on just that part while issuing bestvideo again--(by using the the format selection above) you essentially express a flexible preference for mp4 over the other containers; you surely do want mp4 if possible, but not at the cost of reduced video quality.

As I said, you may still get some mkv, but they will be greatly reduced in number and only used when required to supply a (supposedly) better video. And so far with this configuration, I haven't seen any webm at all, because something like 248+140 works ends up as mkv.


Also... note that there is now a new youtube-dl issue that affects whether you get the best video. Unlike the issue discussed here (which concerns how youtube-dl operates), #14143 is caused by YouTube reporting false metadata.

@MiraBrozek

This comment has been minimized.

Copy link

commented Jan 14, 2018

Hello,
I cant figure out how to merge bestvideo(1080p) - which is actually only video, so if I will use
-f bestvideo[height=<1080]+bestaudio

it will download audio format 140, which is not best.. as you can see in format 22 (720p) it has mp4a @ 192kb .

Is there anyway how to extract audio from 720p and merged with video 1080p ?
https://s25.postimg.org/yt3jops3z/snap048.jpg

@Hrxn

This comment has been minimized.

Copy link

commented Jan 14, 2018

Normally, bestaudio is Opus. YT does not provide it in your example. That can happen, although it's an exception. best, format 22 in your example, is a single file, you can't get the audio stream directly.
If necessary, download the file and extract the steam for yourself manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.