-1

I have two stereo file: 1.mp3, 2.mp3

I want to merge this two audio files in the special way

I mean I want 3.mp3 to be a stereo file that has 1.mp3 in it's left channel and 2.mp3 in it's right channel

j.doe
  • 662
  • 4
  • 19
  • 3
    You will need to decode the mp3 data, mix it, then encode it again, you can't just mix compressed data. – Retired Ninja Dec 19 '18 at 05:11
  • 1
    Yes, it's possible, but it's harder than just sticking the two files together with duct tape and baling wire. – user253751 Dec 19 '18 at 05:22
  • The answer to [this question](https://stackoverflow.com/questions/62618/what-is-the-best-way-to-merge-mp3-files?rq=1) suggests a tool called mp3wrap. – user253751 Dec 19 '18 at 05:23
  • If you don't mind a slight loss of quality you can also convert them both to raw files, join the raw files and convert back to mp3. – user253751 Dec 19 '18 at 05:26
  • @immibis how to mix raw files? – j.doe Dec 19 '18 at 05:47
  • @RetiredNinja How to do that? – j.doe Dec 19 '18 at 05:48
  • Use appropriate libraries. (Do not ask which, that would be off-topic here. Search and pick one yourself. Ideally one with a tutorial, asking about one would also be off-topic.) – Yunnosch Dec 19 '18 at 07:03
  • @Yunnosch to mix this two mp3 or to mix raw files? – j.doe Dec 19 '18 at 07:06
  • Yes, one of the two. Or better, yes, whatever is your goal. However, I only have heard of libs for mixing non-compressed files - and for uncompressing them. – Yunnosch Dec 19 '18 at 07:16
  • It seems like you don't really understand how computer audio works. I suggest learning about that first, if you can't find an existing tool that does what you want – user253751 Dec 21 '18 at 06:39

2 Answers2

0

You can achieve that by following these steps:

  1. Decode 1.mp3 and 2.mp3 files

  2. Save decoded raw data (in different WAVE formatted files or in memory)

  3. Replace of 1.mp3 decoded raw data's first or second channel values with 2.mp3 decoded raw data's first or second channel values one by one (note that this causes quality loss of audio)

  4. Construct WAVE(raw audio data format) header based on the merged audio data features

  5. Create WAVE formated 3.wav file using constructed WAVE header and merged audio data

  6. Convert 3.wav file to 3.mp3 file format

Doing these steps requires you to know:

  • How to decode mp3 files to get raw data

  • How to manipulate on data bytes in buffer

  • WAVE soundfile format

  • How to convert wav to mp3

For decoding and encoding audio files in different formats you can use some appropriate sound library(for example BASS) - this helps you to do 1 and 6 steps. For constructing WAVE formated audio data you should be familiar with WAVE File Format and how audio data channels is aligned in buffer - this helps you to do 3, 4 and 5 steps

Gio
  • 316
  • 2
  • 3
  • 11
0

mp3 is compressed audio data. you can not directly mix them using file operations. one thing you can do is use ffmpeg library to convert the mp3 to raw PCM, mix the channels and then converting it back to mp3.

thomachan
  • 378
  • 3
  • 14