Combining downloaded YouTube video formats with ffmpeg for full HD videos

youtube-dl makes downloading YouTube videos very easy. From a command prompt, simply run youtube-dl <video-url>

However, by default, this will download the best video file with video and audio; which is 720p. While youtube-dl itself has a ton of options, recombining a video and audio file is a great introduction to the powerful ffmpeg.

youtube-dl lists the available formats with the -F option

youtube-dl -F <video-url>

You can then download the best / desired video and audio files with

youtube-dl -f <format-ID> <video-url>

After you downloaded both files, ffmpeg can copy the encoded video and audio channels into a new container. The process of putting video and audio into a container format (like mp4, webm, ogg etc) is called muxing.

ffmpeg has great introduction documentation. If you want to take the fast route though, here’s the command and explanation:

ffmpeg -vn -i "<file1>" -an -i "<file2>" -c copy -map 0:a:0 -map 1:v:0 video-muxed.webm

The top command structure in this case is:

<input file 1 options> <input file 1 filename> <input file 2 options> <input file 2 filename> <output options> <output filename>

The -vn parameter says that this input file has no video, so file1 is the audio file. The -an parameter respectively declares that the second input file has no audio. The -c copy parameter defines to copy all channels (video and audio) rather than re-encoding them. And most importantly, the -map parameter maps channels; 0:a:0 maps the audio channel from the first input file to the audio primary audio stream of the output file, and 1:v:0 maps the video channel of the second input file to the primary video channel of the output file.

This command should be blazingly fast, as ffmpeg simply copies the encoded data, and puts them into a new container. Compared to (re-)encoding a video (and audio), this is magnitudes faster, and compared to re-encoding you also lose no quality.