How to add an external audio track to a video file using VLC or FFMPEG command line
Categories:
Adding External Audio Tracks to Video with VLC or FFmpeg
Learn how to seamlessly integrate external audio tracks into your video files using the powerful command-line tool FFmpeg or the versatile media player VLC.
Integrating an external audio track into a video file is a common task for video editors, content creators, and anyone looking to enhance their media. Whether you're replacing a video's original audio with a higher-quality soundtrack, adding commentary, or including multiple language options, tools like FFmpeg and VLC offer robust solutions. This article will guide you through the process using both command-line and GUI methods.
Understanding Audio-Video Multiplexing
Multiplexing, often called 'muxing,' is the process of combining multiple elementary streams (like video, audio, and subtitles) into a single stream or container file. When you add an external audio track, you're essentially telling the container format (e.g., MP4, MKV) to include this new audio stream alongside the existing video stream. This doesn't re-encode the video, saving significant time and preserving video quality.
flowchart TD A[Input Video File] --> B{Multiplexer} C[External Audio File] --> B B --> D[Output Video File (with new audio track)] style A fill:#f9f,stroke:#333,stroke-width:2px style C fill:#bbf,stroke:#333,stroke-width:2px style D fill:#ccf,stroke:#333,stroke-width:2px
Conceptual diagram of audio-video multiplexing.
Method 1: Using FFmpeg (Command Line)
FFmpeg is an incredibly powerful and versatile command-line tool for handling multimedia files. It can convert, stream, and manipulate audio and video in almost any format. For adding an external audio track, FFmpeg is often the preferred choice due to its speed and precision.
brew install ffmpeg
on macOS, sudo apt install ffmpeg
on Debian/Ubuntu).Adding an Audio Track (Replacing Original)
To replace the existing audio track in a video with a new one, you'll use the -map
option to select which streams to include. The -c:v copy
and -c:a copy
options ensure that the video and audio streams are copied directly without re-encoding, preserving quality and speeding up the process.
ffmpeg -i input_video.mp4 -i external_audio.mp3 -map 0:v -map 1:a -c:v copy -c:a copy output_video_with_new_audio.mp4
FFmpeg command to replace a video's audio track.
In the command above:
-i input_video.mp4
: Specifies your original video file.-i external_audio.mp3
: Specifies your external audio file.-map 0:v
: Selects the video stream from the first input (input_video.mp4).-map 1:a
: Selects the audio stream from the second input (external_audio.mp3).-c:v copy
: Copies the video stream without re-encoding.-c:a copy
: Copies the audio stream without re-encoding.
Adding an Audio Track (Keeping Original and Adding New)
If you want to keep the original audio track and add a new one (e.g., for multiple language options), you can map both audio streams. The order in which you map them determines their default playback order.
ffmpeg -i input_video.mp4 -i external_audio.mp3 -map 0:v -map 0:a -map 1:a -c:v copy -c:a copy -metadata:s:a:1 language=eng output_video_multi_audio.mkv
FFmpeg command to add an additional audio track while keeping the original.
-metadata:s:a:X language=YYY
where X
is the stream index (0 for the first audio, 1 for the second, etc.) and YYY
is the 3-letter ISO 639-2/B language code (e.g., eng
, spa
, fra
). This helps media players identify the tracks.Synchronizing Audio (If Needed)
Sometimes, the external audio track might not perfectly align with the video. FFmpeg provides the -itsoffset
option to delay or advance an audio stream. A positive value delays the audio, and a negative value advances it.
ffmpeg -i input_video.mp4 -itsoffset 0.5 -i external_audio.mp3 -map 0:v -map 1:a -c:v copy -c:a copy output_synced_audio.mp4
FFmpeg command to delay the external audio by 0.5 seconds.
Method 2: Using VLC Media Player (GUI)
VLC Media Player is renowned for its ability to play almost any media format, but it also offers basic conversion and stream manipulation capabilities through its graphical user interface. While less powerful than FFmpeg for complex tasks, it's a good option for simple audio track additions.
1. Open VLC and Access Convert/Save
Launch VLC Media Player. Go to Media
> Convert / Save...
(or press Ctrl+R
on Windows/Linux, Cmd+Shift+S
on macOS).
2. Add Video and Audio Files
In the Open Media
dialog, click Add...
to select your video file. Then, check the Show more options
box. Below it, check Play another media synchronously (extra audio file, ...)
and click Browse...
to add your external audio file.
3. Configure Conversion Settings
Click Convert / Save
. In the new window, under Settings
, choose a Profile
(e.g., Video - H.264 + MP3 (MP4)
). Click the wrench icon next to the profile to customize. Under the Audio codec
tab, ensure Audio
is checked and select your preferred codec (e.g., MP3, AAC). Under the Video codec
tab, ensure Video
is checked and select Keep original video track
if available, or a suitable codec like H.264.
4. Select Destination and Start
Click Browse
next to Destination file
to choose where to save your new video file and give it a name (e.g., output_video_vlc.mp4
). Finally, click Start
to begin the conversion process.
Conclusion
Adding an external audio track to a video file is a straightforward process with the right tools. FFmpeg offers unparalleled control and efficiency for command-line users, allowing for stream copying and precise synchronization. VLC provides a user-friendly graphical interface for simpler tasks, though with the caveat of re-encoding. Choose the method that best suits your technical comfort level and specific project requirements.