How to merge two audio files on android using ffmpeg.

4,020 views
Skip to first unread message

gull

unread,
Jul 11, 2012, 2:56:42 PM7/11/12
to jav...@googlegroups.com
Hi,
I want to combine two audio files on android. I did lot of search on google about this topic but  did not get desire result.
 Somebody told me that we can use ffmpeg library for this purpose. Can you help me or guide me that how i can
 combine two audio files on android using ffmpeg. I want to know about the APIS of  ffmpeg?. It is better if  you can give me any example.

Regards
Gull

 

Samuel Audet

unread,
Jul 13, 2012, 11:23:12 PM7/13/12
to jav...@googlegroups.com
The latest revisions of FFmpegFrameGrabber and FFmpegFrameRecorder can
be used to do that, e.g.:

FrameGrabber grabber = new FFmpegFrameGrabber("input.mp3");
grabber.start();
FrameRecorder recorder = new FFmpegFrameRecorder("output.mp3",
grabber.getAudioChannels());
recorder.setSampleFormat(grabber.getSampleFormat());
recorder.setSampleRate(grabber.getSampleRate());
recorder.start();
Frame frame;
while ((frame = grabber.grabFrame()) != null) {
recorder.record(frame);
}
recorder.stop();
grabber.stop();

But you'll have to build JavaCV or wait for the next release if you're
not inclined to recompile JavaCV yourself

Samuel

Ahmad Gull Liaqat

unread,
Jul 14, 2012, 3:18:50 AM7/14/12
to jav...@googlegroups.com

Thanks for your reply. I just want to clear two things.
1. Is it possible to mix the two audio files, i means not cocatination or merging the one audio file at the end of other file.  e.g i want to mix my voice with background music.

2. Can we mix two different format of audio files like .wav and .mp3.

if the above two steps  are possible in the new version of javacv then i am going to compile javacv for android.

Thanks,
gull

Samuel Audet

unread,
Jul 14, 2012, 3:25:04 AM7/14/12
to jav...@googlegroups.com
JavaCV won't help you much I'm afraid. Java Sound has that kind of
feature, e.g.:
http://javasolution.blogspot.jp/2007/05/mixing-two-audio-files-using-java-sound.html
But unfortunately, it doesn't seem like Java Sound is available for Android:
http://code.google.com/p/android/issues/detail?id=60

Samuel

Samuel Audet

unread,
Jul 14, 2012, 3:28:49 AM7/14/12
to jav...@googlegroups.com
Then again, it looks like avfilter has that kind of capabilities:
http://ffmpeg.org/libavfilter.html#amix
I don't know how to use its API, but I'm sure there are samples out there...

Samuel

Ahmad Gull Liaqat

unread,
Jul 14, 2012, 3:34:48 AM7/14/12
to jav...@googlegroups.com

Thanks Samuel.

Ophir Levinson

unread,
May 19, 2013, 10:30:40 AM5/19/13
to jav...@googlegroups.com

Hello gul ,
were you able to mix the audio's , can you please post some sample code ?
thanks
בתאריך יום שבת, 14 ביולי 2012 10:34:48 UTC+3, מאת gull:

Vinod Morya

unread,
Nov 1, 2013, 2:19:40 AM11/1/13
to jav...@googlegroups.com
Hi gull and samuel,
                                I am also working on a project like this, so if you have found any way to mix two audio files on android system them please share that. I will appreciate the support.

Thanks
vinod 

Ahmad Gull Liaqat

unread,
Nov 1, 2013, 6:39:00 AM11/1/13
to jav...@googlegroups.com
Hi,
I   changed my idea little bit and mixed the audio while playing both files at the same time. It can easily achieved by using android APIs.


--
 
---
You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Best Regards,
Ahmad Gull Liaqat

Samuel Audet

unread,
Nov 3, 2013, 8:35:58 AM11/3/13
to jav...@googlegroups.com
Hi,

On 11/01/2013 03:19 PM, Vinod Morya wrote:
> I am also working on a project like
> this, so if you have found any way to mix two audio files on android
> system them please share that. I will appreciate the support.

Could you please define what you mean by "mix"?

Samuel

Vinod Morya

unread,
Nov 3, 2013, 11:31:55 AM11/3/13
to jav...@googlegroups.com
"Mix" means ..playing both the files at the same time...

Regards
Vinod Morya




--

--- You received this message because you are subscribed to a topic in the Google Groups "javacv" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/javacv/KsyqJTYarYE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to javacv+unsubscribe@googlegroups.com.

Samuel Audet

unread,
Nov 17, 2013, 6:52:15 AM11/17/13
to jav...@googlegroups.com
On 11/04/2013 01:31 AM, Vinod Morya wrote:
> "Mix" means ..playing both the files at the same time...

It looks like libavfilter supports that, but it's not exposed by a
high-level API like FFmpegFrameRecorder. You could open an new issue here:
http://code.google.com/p/javacv/issues/
To see how many people are interested such a feature, have a discussion
about how it should be implemented, etc...

Samuel

Reply all
Reply to author
Forward
0 new messages