Youtube-DL is a powerful tool that serves almost all your needs when you want to download a video from the internet. It cannot only perform the crawling, parsing, and finding real video URLs, youtube-dl can also be used in conjunction with other open-source programs such as FFmpeg. This article will show you how to manually merge separate video and audio files into one single file.
To follow this tutorial, you obviously need youtube-dl installed on your Windows/Linux/macOS machine. In addition to that, FFMPEG also needs to be present in the system path.
An alternative to FFMPEG supported by youtube-dl is avconv, which is just another fork of FFMPEG with a different set of features. In this article, we will only use FFMPEG as it is more feature completed and widely supported among the open-source community.
Step 1: Install FFMPEG
On FFMPEG homepage, there are official packages for major distros such as Debian/Ubuntu or Fedora/RHEL/CentOS.
Install FFMPEG in Fedora/RHEL/CentOS
If you are running Fedora/RHEL/CentOS, you can install FFMPEG directly from the RPM Fusion repository.
The RPM Fusion repository depends on the EPEL software repository. Please ensure EPEL is enabled by typing:
Code language: Bash (bash)sudo yum install epel-release
Then you need to install the RPM packages to enable RPM Fusion
Code language: Bash (bash)sudo yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
After that, install FFMPEG from RPM Fusion using this command :
Code language: Bash (bash)sudo yum install ffmpeg ffmpeg-devel
Install FFMPEG in Debian/Ubuntu
If you are running Ubuntu/Debian, you can simply install it using apt as follows :
Code language: Bash (bash)sudo apt-get install ffmpeg -y
You can also get FFMPEG from snap, but I personally do not recommend this method. There have been numerous problems reportedly caused by snap’s heavy limitations of accessing system resources such as the infamous “permission denied”. But if you still want easy installation, here’s the command to install FFMPEG from snap :
Code language: Bash (bash)sudo snap install ffmpeg
Install FFMPEG in Windows.
Windows users will have to get community builds from gyan.dev or BtbN to install FFMPEG.
After downloading and extracting the build, you have to browse to bin
folder, then copy them to one of the system paths. If you are unsure about system paths, the easiest way is to copy ffmpeg.exe
,ffplay.exe
and ffprobe.exe
into C:WindowsSystem32
.
Install FFMPEG in macOS
MacOS users can easily install FFMPEG using Homebrew.
Once you have Homebrew installed, perform the installation of FFMPEG from the Terminal with the following command :
Code language: Bash (bash)brew install ffmpeg
Step 2 : Merge audio and video using youtube-dl
youtube-dl can automatically detect whether ffmpeg is installed in the system and use it as part of the script to join/merge the separate video and audio files.
This functionality is often used when you download from Youtube. New videos from Youtube are streamed to the user in HD as separate files.
Let’s look at this example where we automatically merge audio and video of two formats into a single file :
Code language: Bash (bash)youtube-dl -f bestvideo+bestaudio https://www.youtube.com/watch?v=qugduxazBBg
The important part of the command is the argument for joining files : -f bestvideo+bestaudio
.
The output should look something like this :

As you can see from the image, downloaded audio and video in the best available formats have been automatically downloaded and merged into one single MKV file named Duterte's Drug War (full film) _ FRONTLINE-qugduxazBBg.mkv
.
Youtube-dl by default outputs merged files in Matroska (MKV) container. If you want to output into a different format, pass a --merge-output-format
following by a supported file extension like this :
Code language: Bash (bash)youtube-dl -f bestvideo+bestaudio --merge-output-format mp4 https://www.youtube.com/watch?v=qugduxazBBg
Supported formats are mkv, mp4, ogg, webm, flv.