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

Request feature of merging video and audio separately served at YouTube #2765

Closed
m13253 opened this issue Apr 17, 2014 · 8 comments
Closed

Request feature of merging video and audio separately served at YouTube #2765

m13253 opened this issue Apr 17, 2014 · 8 comments

Comments

@m13253
Copy link

@m13253 m13253 commented Apr 17, 2014

Screenshot at 2014-04-18 00:40:05.png

From the screenshot we can know YouTube now serves video and audio separately.

I think it will be great if youtube-dl can automatically merge them.

I give three ways. Either of them can be implemented into youtube-dl:

ffmpeg -i video.webm -i audio.m4a -c copy output.mkv

mkvmerge -o output.mkv video.webm audio.m4a

MP4Box -add video.mp4 -add audio.m4a output.new.mp4 && mv output.new.mp4 output.mp4

Thank you.

BTW: The worst/best decision is not accurate now, since the 'dash' version is not always the worst and the 'non-dash' version serves only up to 720p.

@m13253 m13253 changed the title Request support of merging video and audio separately served at YouTube Request feature of merging video and audio separately served at YouTube Apr 17, 2014
@AGSPhoenix
Copy link
Contributor

@AGSPhoenix AGSPhoenix commented Apr 18, 2014

We already have support for this, though it's undocumented until we work out a few problems. Just specify two format codes with a + between them. For example, -f 137+140, which will get you a 1080p MP4 file. You can also combine this with specifying multiple formats by preference; for example -f 137+140/136+140/22 would try to get 1080p DASH, then 720p DASH, and finally normal 720p.

This feature isn't enabled by default, because it requires either ffmpeg or avconv to be available and in the $PATH to mux the video, and we need to be able to automatically detect their availability, and change what format is considered the 'best' if they are available. It's certainly something that could be done, but no one has taken the time to do so.

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented May 1, 2014

As @AGSPhoenix said, this is already implemented, but it needs some improvements. If you just want the best quality you may prefer to use -f bestvideo+bestaudio.

@jaimeMF jaimeMF closed this May 1, 2014
@PacoH
Copy link

@PacoH PacoH commented Dec 11, 2014

@AGSPhoenix: Why isn't this in the man page?

BTW didn't work. After downloading webm video and m4a audio:

user$ youtube-dl -f 272+141 https://www.youtube.com/watch?v=rkby8QrWMhs
[youtube] Confirming age
[youtube] rkby8QrWMhs: Downloading webpage
[youtube] rkby8QrWMhs: Downloading video info webpage
[youtube] rkby8QrWMhs: Extracting video information
[youtube] rkby8QrWMhs: Downloading DASH manifest
[download] Destination: 4K-Italy-Long-rkby8QrWMhs.f272.webm
[download] 100% of 4.09GiB in 12:43
[download] Destination: 4K-Italy-Long-rkby8QrWMhs.f141.m4a
[download] 100% of 40.12MiB in 00:05
[ffmpeg] Merging formats into "4K-Italy-Long-rkby8QrWMhs.webm"
ERROR: Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

Yet I can merge the original downloaded files no problem using:

user$ ffmpeg -i 4K-Italy-Long-rkby8QrWMhs.webm -i 4K-Italy-Long-rkby8QrWMhs.m4a -vcodec libvpx -acodec libvorbis 4K-Italy-Long-rkby8QrWMhs-aduio-added.webm

This is a 4k video.

@phihag
Copy link
Contributor

@phihag phihag commented Dec 11, 2014

@PacoH It is documented now. We're still waiting for someone to contribute code that automatically detects whether merging is possible so that we could even default to this.

The webm container does not support m4a content, and that's why youtube-dl fails (If you think it should detect this situation and maybe choose a better container, please file a bug saying that you'd be interested.

In your command-line, you are converting the audio to vorbis, whereas youtube-dl tries to do it losslessly. By the way, why are you recoding the video? That will lead to a loss of quality.

@PacoH
Copy link

@PacoH PacoH commented Dec 12, 2014

I tried -c:v copy and it failed before. This time I tried -c:v copy again and it worked.

 user$ fmpeg -i 4K-Italy-Long-rkby8QrWMhs.webm -i 4K-Italy-Long-rkby8QrWMhs.m4a -c:v copy -acodec libvorbis 4K-Italy-Long-rkby8QrWMhs-aduio-added.webm
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (aac (native) -> vorbis (libvorbis))
@m13253
Copy link
Author

@m13253 m13253 commented Dec 12, 2014

The webm container does not support m4a content, and that's why youtube-dl fails (If you think it should detect this situation and maybe choose a better container, please file a bug saying that you'd be interested.

My suggestion is that, according to the codecs that YouTube are currently using, most of them can be fitted into an MP4 container or a WebM one. General MKV can be used as the last resort:

Use MP4 for H.264/FLV1/H.263/MPEG4 + AAC/MP3/AMR (coming from .mp4 .flv .3gp(only 144p) .m4a .mp3)

Use WebM for VP9/VP8 + Opus/Vorbis (coming from .webm)

Use MKV for the remaining combinations.=

@PacoH
Copy link

@PacoH PacoH commented Dec 12, 2014

OK, it works perfectly if you don't mix formats. I successfully downloaded both wbem-video+webm-audio and mp4-video+m4a-audio formats and they were properly muxed into webm and mp4 containers respectively. Both were 4k video quality but the webm is ~1.5x the size of the mp4 and ~1.5x the bitrate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
@AGSPhoenix @phihag @jaimeMF @m13253 @PacoH and others
You can’t perform that action at this time.