Filmora
Filmora - AI Video Editor
Edit Faster, Smarter and Easier!
OPEN
Filmora Video Editor
Effortlessly create video with AI.
  • Various AI editing tools to increase your video creation efficiency.
  • Offer popular templates and royalty-free creative resources.
  • Cross-platform functionality for editing everywhere.

How to Merge Audio and Video Using FFmpeg

Caroline Laurent
Caroline Laurent Originally published Feb 16, 23, updated Dec 10, 24

Welcome to the world of video production! Whether you're a beginner or an experienced video creator, one of the most important skills to master is merging audio and video seamlessly. In this article, we'll focus on FFmpeg, a powerful command-line tool that can help you easily merge audio and video.

FFmpeg is open-source software that allows you to convert, edit, and stream multimedia files. It's widely used by professionals and enthusiasts and has many capabilities, including merging audio and video files. This guide will walk you through merging audio and video using FFmpeg. So, whether you're creating a YouTube video, a podcast, or a movie, you'll have the skills to make it sound and look great.

merge audio and video with ffmpeg
In this article
  1. Preparation
  2. It May Interest You - Merge Audio and Video Files With Filmora
  3. People Also Ask

Preparation

Are you ready to master the art of merging audio and video? Then let's dive into the world of FFmpeg, a powerful and versatile tool that can help you achieve professional results.

With FFmpeg, you can record, convert, and stream audio and video files in any format, making it a complete and cross-platform solution. It's also a great tool for decoding, encoding, transcoding, muxing, demuxing, streaming, filtering, and playing any media type.

But before we start merging video files using FFmpeg, it's important to understand the basics of container formats and video codecs. These are the building blocks of your videos, and the specific types you're working with will determine the method you'll use to merge them. So, buckle up, and let's get started!

How To Combine Video With Two Audio Using FFmpeg

Are you looking to add multiple audio tracks to your video? With FFmpeg, you can easily combine video with two audio streams. Whether creating a foreign-language version of your video or adding an alternate audio track, this method will help you achieve professional results. This section will guide you through combining video with two audio streams using FFmpeg's command-line interface. So, let's get started!

Mixing Two Audios Into a Video

Combining multiple audio tracks into one video can be done easily with FFmpeg's command-line interface. In this example, we will combine two audio tracks into one video so that the voiceover will play over the background music. Here's the step-by-step process:

Step1 Open your command prompt or terminal and navigate to the directory where your video and audio files are located.

Step2 Replace "video1.mp4" and "audio1.mp3" with the names of your actual video and audio files.

ffmpeg \

-i video1.mp4 -i audio1.mp3 \

Step3 The -c:v copy flag tells FFmpeg to copy the video stream from the source file without re-encoding it. This helps to speed up the process and avoid quality loss.

-c:v copy \

-filter_complex " \

Step4 The command "amix=inputs=2:duration=longest" tells amix to accept 2 inputs (0:a and 1:a) and combine them into an output stream called audio_out, with the duration of the longest input.

[0:a][1:a] amix=inputs=2:duration=longest [audio_out] \

Step5 Map the video stream (0:v) and the mixed audio stream (audio_out) into the final output video.

-map 0:v -map "[audio_out]" \

Step6 The -y flag tells FFmpeg to overwrite the output file if it already exists.

-y output.mp4

Once complete, you'll find the newly created video file with the mixed audio in the specified output location.

Mixing Two Audios Into a Video Adjusting Volume

We will be taking a step further and show you how to merge two audio tracks into a video while adjusting the volume of one of the audio tracks. This can be useful when you want to emphasize one audio track over the other, for example, to make the voiceover more prominent in a video.

And here's the step-by-step process:

Step1 Start the command by specifying the input files.

ffmpeg \

-i video1.mp4 -i audio1.mp3 \

Step2 Use the filter_complex option to specify a filter graph.

-filter_complex " \

[0:a] volume=0.5 [music];

Step3 Use the amix filter to take the "music" stream and audio1.mp3 and mix them.

[music][1:a] amix=inputs=2:duration=longest [audio_out] \

" \

Step4 Use the map option to specify which streams from the input files should be included in the output file.

-map 0:v -map "[audio_out]" \

Step5 Specify the output file name as "output.mp4" and the -y flag to overwrite the output file without asking for confirmation if it already exists.

-y output.mp4

Mixing Two Audios Into a Video With Delay

When creating videos, sometimes the audio needs to be synced with the video, or you want to add a delay to the audio track. Here's how to add delay to an audio track using FFmpeg.

Step1 Use the adelay filter to add delay to the audio track.

[1:a] adelay=2100|2100 [voice];

Step2 Mix the delayed audio track with the original audio track

[0:a][voice] amix=inputs=2:duration=longest [audio_out]

Step3 Map the video and audio tracks to the output file

-map 0:v -map "[audio_out]"

Step4 Use the -y flag to overwrite the output file

-y output.mp4

The final command would look like this:

ffmpeg \

-i video1.mp4 -i audio1.mp3 \

-filter_complex " \

[1:a] adelay=2100|2100 [voice]; \

[0:a][voice] amix=inputs=2:duration=longest [audio_out] \

" \

-map 0:v -map "[audio_out]" \

-y output.mp4

This command will delay the audio track by 2100 milliseconds and then mix it with the original audio track, resulting in a new video file with the delayed audio.

It May Interest You - Merge Audio and Video Files With Filmora

While FFmpeg is a powerful tool for merging audio and video files, its learning curve can be steep for some users. If you're looking for an easier option, you may consider using video editing software like Filmora.

What Is Filmora?

Wondershare Filmora is a video editing software that allows users to create professional-looking videos easily. It offers a user-friendly interface, making it an excellent option for those needing a more extensive video editing experience.

Free Download
Free Download

This software offers an intuitive interface and a wide range of features that make it easy to merge audio and video files, even for beginners. In addition, Filmora provides various options for editing and enhancing the audio and video files, giving you more control over the final output. Filmora is a great alternative to FFmpeg for those who want to merge audio and video files quickly and easily.

How To Combine Audio and Video Files Using Filmora

Filmora is a user-friendly video editing software that allows you to easily combine audio and video files to create a polished and professional final product. So here's the step-by-step process of combining audio and video files using Filmora.

Step1 Import audio and video files into Filmora using drag-and-drop or the "Import Media" button.

filmora import media

Step2 Place the media files in the timeline and align the video with the audio.

filmora align media

Step3 Replace the original audio by right-clicking the video, selecting "Detach Audio," deleting the original audio, and replacing it with new audio.

filmora detach audio

Step4 Export the final video by selecting a format and clicking "Export," or publish directly to YouTube or burn to DVD.

filmora export video

People Also Ask

Here are some frequently asked questions regarding the merging function of FFmpeg and other related topics:

Q1. How To Merge Image and Video in FFmpeg?

To merge an image and a video using FFmpeg, first, use the -loop option on the image to loop it for the duration of the video, then use the overlay filter to overlay the image on the video. The command would look like this:

ffmpeg -i video.mp4 -i image.jpg -filter_complex "[0:v][1:v] overlay=0:0" -pix_fmt yuv420p -c:a copy output.mp4

This command takes the input video and image, applies the overlay filter to overlay the image on the video starting at the top left corner (0:0), and outputs the result to output.mp4. The -pix_fmt yuv420p and -c:a copy options ensure compatibility with most devices.

Q2. Can I Merge 2 MP4 Files Into 1?

Yes, you can merge two MP4 files into one using Filmora. To do this, follow these steps:

Step1 Open Filmora and import the video files

Step2 Drag the videos to the timeline

Step3 Align the second video with the first without leaving any gaps

Step4 Click "Export" and select desired settings

Step5 Click "Export" again to save the combined video on your computer.

Q3. How Can I Merge the Video and Subtitle?

To merge video and subtitle in Filmora, follow these steps:

Step1 Open Filmora and import your SRT subtitle file.

Step2 Place the SRT file on the timeline and right-click on it. Select "Advanced Edit" from the options.

Step3 Adjust the subtitle's time code, text, color, font, and other settings. When finished, choose "Export Subtitle file" to save the changes.

Still want to learn more tricks about adding subtitles to your video? Check out the video below:

Conclusion

Using FFmpeg and Filmora, you can easily combine video with audio, merge multiple video files, and add subtitles to your videos. Both tools offer different features and learning curves, so it's important to understand what you need before choosing one. Filmora is a great option for beginners and those who want a user-friendly interface, while FFmpeg is a powerful command-line tool for advanced users.

Caroline Laurent
Caroline Laurent Dec 10, 24
Share article: