Closed ericzutter closed 9 years ago
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!!
youtube-dl -f 137+bestaudio https://www.youtube.com/watch?v=RS5mzvqWM-c
That should do it.
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.
@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.
@chrisaljoudi you don't understand the problem.
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!
@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
@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.
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.
@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:
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).
@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!
@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.
@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'
@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.
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 ?
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)
@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.
I realize this thread is a bit old, but I think the situation has changed somewhat. For my goal:
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.
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
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.
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 reducingmkv
, (apparently) eliminatingwebm
, 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 ismp4
, 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 onbestaudio
, which may then mean a mixed format. It's because thebestvideo+bestaudio
command is too insistent that you get forced out ofmp4
.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 issuingbestvideo
again--(by using the the format selection above) you essentially express a flexible preference formp4
over the other containers; you surely do wantmp4
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 anywebm
at all, because something like 248+140 works ends up asmkv
.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.
Hmm strange that MacOS cannot open such videos via QuickTime but VLC has no problem. Seems this method uses codec that MacOS does not like.
As of March 24, 2020, bestvideo[ext=mp4] seems to include av01 videos sometimes. Example video where this happens for me (although I expect this may be region dependent): https://www.youtube.com/watch?v=jW6gzAa-VUE
Is there a way to specify "best video that uses h264"?
As of March 24, 2020, bestvideo[ext=mp4] seems to include av01 videos sometimes. Example video where this happens for me (although I expect this may be region dependent): https://www.youtube.com/watch?v=jW6gzAa-VUE
Is there a way to specify "best video that uses the h264"?
even now still I think there is no way around this.
my flags:
--prefer-ffmpeg
--format "bestvideo+bestaudio[ext=m4a]/bestvideo+bestaudio/best"
--merge-output-format mp4
will merge the video and audio into a mp4 container but will still at times(around 60% of the time) encode using the vp09 codec(google's Not-Invented-Here codec). Very irritating and frankly I think they did that on purpose to throw a wrench in youtube archivers using youtube-dl.
A workaround is a transcode that is not actually heavyweight(should get about 3x speed on an i5):
vp09-codec-mp4-wrapper to mp4/h264/h265:
ffmpeg -fflags +genpts -i vp09-input.mp4 -r 24 h264-output.mp4
As of March 24, 2020, bestvideo[ext=mp4] seems to include av01 videos sometimes. Example video where this happens for me (although I expect this may be region dependent): https://www.youtube.com/watch?v=jW6gzAa-VUE
Is there a way to specify "best video that uses h264"?
ext=mp4 is not the right format selection for your use case. It selects the container format but you want to select the codec. You can use the vcodec=... selector to specify the video format you want to download.
As of March 24, 2020, bestvideo[ext=mp4] seems to include av01 videos sometimes. Example video where this happens for me (although I expect this may be region dependent): https://www.youtube.com/watch?v=jW6gzAa-VUE Is there a way to specify "best video that uses h264"?
ext=mp4 is not the right format selection for your use case. It selects the container format but you want to select the codec. You can use the vcodec=... selector to specify the video format you want to download.
Thanks for the suggestion. I tried:
--format "bestvideo[vcodec=h264]+bestaudio[ext=m4a]/bestvideo+bestaudio/best"
but it does not seem to fetch h264 codec.
Echoing the above— I've tried:
-f bestvideo[vcodec=h264]+bestaudio
-f bestvideo[vcodec=x264]+bestaudio
-f bestvideo[vcodec=avc1]+bestaudio
All result in "Requested format not available".
Is this a separate bug I should open a new issue for?
As of March 24, 2020, bestvideo[ext=mp4] seems to include av01 videos sometimes. Example video where this happens for me (although I expect this may be region dependent): https://www.youtube.com/watch?v=jW6gzAa-VUE Is there a way to specify "best video that uses h264"?
ext=mp4 is not the right format selection for your use case. It selects the container format but you want to select the codec. You can use the vcodec=... selector to specify the video format you want to download.
Thanks for the suggestion. I tried:
--format "bestvideo[vcodec=h264]+bestaudio[ext=m4a]/bestvideo+bestaudio/best"
but it does not seem to fetch h264 codec.
Echoing the above— I've tried:
-f bestvideo[vcodec=h264]+bestaudio
-f bestvideo[vcodec=x264]+bestaudio
-f bestvideo[vcodec=avc1]+bestaudio
All result in "Requested format not available".
Is this a separate bug I should open a new issue for?
H264 streams in Youtube are called "avc1....." and the =
operator expects an exact match, so you need to use something like vcodec^=avc1
for selecting h264 videos. Format selection operators are explained in the readme file under FORMAT SELECTION section. You can check the available formats and field values of a video using the -F
option.
How to get best video + best audio for mp4 container format ?
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 ?