Learn how to add a muted audio track to a video without audio using FFMpeg.

In some cases, when working with videos, you will end up with video files that don't have an audio track included. This can become troublesome if you don't understand the concept of a video that doesn't have an audio track or a video that has an audio track, but it's empty (silenced, muted). When you work with FFMpeg, in most cases, you will need a video with both tracks, the video, and the audio. If the video file that will be manipulated by FFMpeg doesn't contain an audio track, you will need to add it. Usually, a padded silenced audio track will do the trick as specified in the following diagram:

FFMpeg Video with Silenced Audio Track

In this article, I will explain to you how to easily create a silenced audio track and merge it with a video without audio tracks using FFmpeg.

1. Create an empty audio file

You need to create an empty audio file that will be merged with the video that doesn't have an audio track already. The following command should generate a muted track in opus format using a mono audio channel:

ffmpeg -f lavfi -t 1 -i anullsrc=cl=mono ./dummy.opus

You just need to replace the path wherever you need the audio file and keep it in mind as you will need it to join it to the video. In our case, the generated audio track will be dummy.opus.

2. Add silenced audio track

The following command would have 2 custom inputs, where the first input argument is the path to the video that doesn't have an audio track (video-without-audio.webm), then as the second input argument the path to the muted audio generated with the command explained in the first step (dummy.opus) and finally as positional argument the path to the output file, in this case, the generated video with the new muted audio track will be output-video.webm:

ffmpeg -i ./video-without-audio.webm -i ./dummy.opus -af apad -shortest ./output-video.webm

The -af argument creates the provided apad filtergraph, which pads the end of an audio stream with silence, which together with -shortest to extend audio streams to the same length as the video stream.

Happy coding ❤️!


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors