How to mix sound files of different format using FFMPEG?

天涯浪子 提交于 2020-01-23 12:06:05

问题


I need to mix audio files of different types into a single output file through code in my iPad app. For example, I need to merge a .m4a file with .mp3 or .wav or any other format file. The resulting output file should be of .m4a type.

I have compiled FFMPEG for iOS with the link: http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2009-October/076618.html

Now, I am not able to understand in which direction to proceed?


回答1:


This is more of a suggestion than an answer. I don't have any experience with obj-c, though I have worked with audio formats in other languages. Unless you find some library that does this specific task, you may need to decode the files and convert their data to some common numerical representation.

The sample data of a .wav file is stored as signed integers between the range of -32768 to 32767, while mp3 sample data is stored as floating points between the range of -1 to +1. Either representation could be converted to the other through some simple calculation.

mp3ToWavSample = mp3Sample * 32767

Once the data is converted "merging" becomes very easy. You can simply add the sample values together.

mergedSample = convertedSample1 + convertedSample2

You would need to apply this to every sample in the mp3. Depending on the size of your files, this could be a significant processing task.

As for adding reverb to your track, I'd suggest that you ask for help on that in a another question.



来源:https://stackoverflow.com/questions/5714719/how-to-mix-sound-files-of-different-format-using-ffmpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!