Merging multiple mp3 files “overlayered” not seque

2019-02-15 06:13发布

问题:

My recent update with my latest discussion over this problem is displayed in bottom

Alright so i'm trying to build a platform where my silverlight app is going to merge different instrument audios into a single file and output a music audio.

What i'm trying to do now is merging multiple mp3 files into a single mp3 file. But that final mp3 file shouldn't play the first mp3 then the second and ... to the end. it should play them all like mp3 channels. The user is going to put a guitar channel, drum channel etc.. and the merger is going to merge them all into one mp3 file as an output.

I've found that i can do that with some code via ffmpeg and some other utilites but i couldn't find a way to make it layered in a channel structure.

I've found an easier implementation of merging mp3's via Mp3Wrap which i would prefer to use, but i couldn't find any helper code about it on google, and from what i've read the structure i've been trying to do is harder to find..

Oh btw.. Last time question, i'm not into GPL knowledge guy so if i use Mp3Wrapper.exe in my project can i be able to use it as a commercial project? can i be able to gain money? or gather donations?


Edit: I've also found something called NAudio I'm not really sure it can make the job done but at least it seems familiar since its written with c#. But i can't use it in my silverlight project cause its not a silverlight assembly and i'm not sure it will work.

Also i'v been wasting my hours searching deep google and documentations of 3 options, couldn't find anything useful, well i don't really understand these stuff but, i'm ready to commit a hack, not really sure if its any use or feasible but i'm also ok with merging mp3 files as audio channels (which i saw that i'm able to select audio channels in ffmpeg but not really sure how to). And add multiple media elements into my project and play them at the same time, hope for them to be synced and mp3 file size to be low.

Any suggestion how can i achieve my goal either with hack or with a good solution.


Another update:

I've decided to use streams to merge my mp3 files since i can directly play with them over .net and it seems faster after some tries. I'm using the following code but i still couldn't found a way to merge the files in a "channeled" or "layered" system and i don't understand a bit about streams, bits, buffers, anything related to IO. Hope this update helps you to give me some insight.

    string path = AppDomain.CurrentDomain.BaseDirectory;
        using (var fs = File.OpenWrite(Path.Combine(path, "cOut.mp3")))
        {
            var buffer = File.ReadAllBytes(Path.Combine(path, "c1.mp3"));
            fs.Write(buffer, 0, buffer.Length);
            buffer = File.ReadAllBytes(Path.Combine(path, "c3.mp3"));
            fs.Write(buffer, 0, buffer.Length);
            fs.Flush();
        }

I'm also kind of changing my mind into embedding the mp3 files as audio channels. The other one seems extremely hard. I'm totally open to the suggestions about audio channel manipulation also, you can write any solution you can come up with i'm open to anything.

Thanks in advance..


Finally i was able to achieve manipulating audio streams of a wmv, but the size was huge! so i changed my focus to my original point merging mp3's and i was able to achive what i want via ffmpeg! This simple code merges multiple mp3 files! But now i have a problem with the speed of the audio. I guess the ffmpeg gets the duration calculated as both mp3 files (a1.mp3 + a2.mp3) and then stretches the audio to fit. Thus my audio plays as in half speed... I've tried;

  • -shortest (Finish encoding when the shortest input stream ends)
  • -async 1 (Sync audio to the timestamps, used with the -copyts)
  • -copyts (get the timestamps from input stream)
  • -speed 2 (manipulate speed)

but couldn't find a way out.. When it processes the audio it executes up to right duration but it produces a double duration timed audio as a result because of a -newaudio stream. I'm able to listen the music as i want when i speed it up by 2x in media player. here is the code;

   ffmpeg -i a1.mp3 -i a2.mp3 -map 0:0 -map 1:0 -acodec wmav2 -ar 44100 -ab 128k -y aout.wav -acodec wmav2 -ar 44100 -ab 128k -newaudio

btw:two input streams are the same mp3's for debug process, so no problem on the input. Thanks.

P.S: i don't want to use SOX if i can, but if there is no other choice please direct me to a fully working binary.