There are two possible things that you could mean by merging audio files in two different ways: ffmpeg:
Insert two separate audio tracks into the same file
Like a DVD, where there is a normal soundtrack, and another soundtrack, such as commentary or dubbed language. To do this, use ffmpeg and two m4a files to use the ffmpeg -i in-1.m4a -acodec copy out.m4a -i in-2.m4a -acodec copy -newaudio . The order of options is important, so do not confuse with it.
Combining two audio files
Create a second file immediately after the first. The easiest way to do this is to use a program designed to manipulate audio, such as SoX . It looks like there is a recent but unstable Android SoX port .
If you want to do concatenation strictly in ffmpeg, you can do the following:
ffmpeg -i in-1.m4a -f s16le in-1.raw
This outputs the audio file to raw PCM. You need to pay attention to the sampling rate and the number of channels, because this information will not be stored in a raw PCM file, and you will need it later. ffmpeg will show you audio stream information as it is transcoded. It will look something like Audio: aac, 44100 Hz, stereo, s16, 63 kb/s , which means that your sampling rate is 44100 and the number of channels is 2 (stereo). Most often you will be dealing with a sampling rate of 22050, 44100 or 48000; and 1 (βmonoβ), 2 (βstereoβ) or 6 (β5.1β) channels.
ffmpeg -i in-2.m4a -f s16le in-1.raw
Now decode the second file in raw PCM.
ffmpeg -f s16le -ar 44100 -ac 2 -i 'concat:in-1.raw|in-2.raw' -acodec libfaac out.m4a
Again, the order of options is very important. Change the selection parameters ( -ar ) and channels ( -ac ) to suit your input.
source share