Question

I'm writing an Android project where I'm recording several audio files. Therefore, I'm setting the following parameters. The recording works fine.

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

My problem is that each time I record, the output is written in a separate file. Now, I need to combine these files to one file. Does anyone have an idea how to combine several MPEG 4 files in an Android project?

Thanks for your help....

Was it helpful?

Solution

In android there is no any inbuilt functionality for combining two audio files, If you are done it through any file operation then this also down to work because its not working as the headers of audio files are different.

I recommended to use a external library FFMPEG for your android application.

OTHER TIPS

I would suggest using my mp4parser library then you don't have to deal with native libs. Have a look at the AppendExample. It does exactly what you want to do. Look out for the latest version. See below for AppendExample to get an idea how it works.

    Movie[] inMovies = new Movie[]{MovieCreator.build(Channels.newChannel(AppendExample.class.getResourceAsStream("/count-deutsch-audio.mp4"))),
            MovieCreator.build(Channels.newChannel(AppendExample.class.getResourceAsStream("/count-english-audio.mp4")))};

    List<Track> videoTracks = new LinkedList<Track>();
    List<Track> audioTracks = new LinkedList<Track>();

    for (Movie m : inMovies) {
        for (Track t : m.getTracks()) {
            if (t.getHandler().equals("soun")) {
                audioTracks.add(t);
            }
            if (t.getHandler().equals("vide")) {
                videoTracks.add(t);
            }
        }
    }

    Movie result = new Movie();

    if (audioTracks.size() > 0) {
        result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
    }
    if (videoTracks.size() > 0) {
        result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
    }

    IsoFile out = new DefaultMp4Builder().build(result);

    FileChannel fc = new RandomAccessFile(String.format("output.mp4"), "rw").getChannel();
    fc.position(0);
    out.getBox(fc);
    fc.close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top