You can do this very easily with ffmpeg (download a static build) like so:
ffmpeg -i input.mp4 -i input.avi -c copy -map 0:v:0 -map 1:a output.mp4
This will map the following streams to the output file:
- the first video channel of the first input (
0:v:0
)
- the audio channels of the second input (
1:a
) – if you only want the first one, use 1:a:0
, etc.
The video and audio streams are copied, so this process is fast.
Incompatible audio
In case that the AVI file uses MP3 for audio streams, they cannot be mapped to an MP4 file. In this case, use:
ffmpeg -i input.mp4 -i input.avi -c:v copy -c:a aac -b:a 192k -map 0:v:0 -map 1:a output.mp4
This would re-encode the audio streams using AAC at 192 kBit/s, which should be high enough quality for you not to notice any artifacts from re-encoding.
Or, you can use MKV as an output container, which supports virtually any codec:
ffmpeg -i input.mp4 -i input.avi -c copy -map 0:v:0 -map 1:a output.mkv
How to run in batch
You can use this command in a loop, obvisouly, to run it on all files, e.g. under Linux with Bash, assuming that the MP4 and AVI files have the same base name, and that you only run it once (otherwise it'll try to convert its output files as well):
for f in *.mp4; do
aviFile="${f%%.mp4}.avi" # replace the extension
outputFile="${f%%.mp4}-output.mp4" # create output filename
ffmpeg -i "$f" -i "$aviFile" -c copy -map 0:v:0 -map 1:a "$outputFile"
done
You will find a lot of examples online on how to run a command in a Windows Batch file loop.
Possible duplicate of How to replace an audio stream in a video file with multiple audio streams?
– Vlastimil Ovčáčík – 2018-08-22T14:32:58.490