Merge two .m4a files or convert the WAV file to m4a

I was looking for a way to write to mpeg-4 with the option of pausing and resuming, but it seemed like it wasn’t. So I decided to record in raw wave format and convert to .m4a . Is there any way to convert the .wav file to .m4a in android. I looked at the mencoder port for android, but did not find any, there was a message about porting ffmpeg to android on linux , but it is not entirely clear how I can use it in android to merge two .m4a files or convert a .wav file to .m4a .

+4
source share
2 answers

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.

+4
source

Assuming you create ffmpeg with the appropriate formats and codecs, converting wav to m4a is as simple as:

 ffmpeg -i in.wav out.m4a 

If you work with audio, you might be lucky with SoX .

+1
source

Source: https://habr.com/ru/post/1379960/


All Articles