
Replace audio in files with another audio stream using FFmpeg map 1:a:0, similarly, means select from the second file (index number 1) the first audio stream (index number 0) to include in the output file. The first number (0) is the index of the first input file, the latter is the index number of the video stream. map 0:v:0 means that select the first input file (INPUT_FILE.mp4), then select the first (0) video stream.

ffmpeg -i INPUT_FILE.mp4 -i AUDIO.aac -c:v copy -c:a copy -map 0:v:0 -map 1:a:0 OUTPUT_FILE.mp4 The example will replace the audio in video.mp4 with audio.aac and output OUTPUT_FILE.mp4. Let’s suppose we have a video file with audio named video.mp4 and an audio file named audio.aac encoded with the AAC codec. The -map option can also be used to exclude specific streams with negative mapping. The -map option is used to choose which streams from the input/inputs to be included in the output/outputs. If your video file already contains one or more audio stream and you want to replace the default audio with another (external) audio file, you need to use FFmpeg’s -map option. In case you don’t want any audio conversion, just drop the aac part in the command and replace it with copy, so it would look like this ffmpeg -i INPUT_FILE.mp4 -i AUDIO.aac -c:v copy -c:a copy OUTPUT_FILE.mp4 Extract video from file and combine with another audio file using FFmpeg c:a aac means select all the audio stream from source files, then encode it with AAC encoder. c:v copy is a short form of -codec:v copy which means copy the video stream from the source files to the destination file. Similarly, -i AUDIO.wav tells FFmpeg to take AUDIO.wav as an input source. i INPUT_FILE.mp4 specify INPUT_FILE.mp4 as an input source If you want to combine them AND re-encode the audio to AAC format, you can use this command : ffmpeg -i INPUT_FILE.mp4 -i AUDIO.wav -c:v copy -c:a aac OUTPUT_FILE.mp4 Let’s suppose our video file name is INPUT_FILE.mp4 and the audio file name is AUDIO.wav.

To ensure compatibility, we recommend using MP4 or MKV as the container. Please do note that the container (file extension) must accept the video and audio codec. If you have separate audio and video file, and the video file contains no audio, you can use this command to combine them into one video file.

6 Conclusion Combine separate video and audio using FFmpeg
