Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open source mp4 muxer in java [closed]

Is there any Open Source MP4 muxer/writer java project(source written in java, no native code) available?

I have H.264 & AAC raw/elementary streams stored seperate files. I want to mux them and get the .mp4 video file containing both Audio & Video.

Thanks in advance for your valuable suggestions.

like image 880
mrsatish Avatar asked Feb 08 '26 05:02

mrsatish


2 Answers

Use the isoparser library it is as far as I know the only pure Java tool that can mux AAC and H264. It also provides an example for precisely the use case you are describing.

Full disclosure: I am the creator of the library.

 AACTrackImpl audio= new AACTrackImpl(new FileInputStream("sample.aac").getChannel());
 H264TrackImpl video = new H264TrackImpl(new FileInputStream("sample.h264"));
 Movie m = new Movie();
 m.addTrack(video);
 m.addTrack(audio);

 IsoFile out = new DefaultMp4Builder().build(m);
 FileOutputStream fos = new FileOutputStream(new File("output.mp4"));
 out.getBox(fos.getChannel());
 fos.close();
like image 57
Sebastian Annies Avatar answered Feb 12 '26 04:02

Sebastian Annies


Previous sample from isoparser cannot be compiled with latest sources. I`m using folliwing code to mux row h264(from android MediaCodec) into .mp4 container

    H264TrackImpl video;
    try {
        video = new H264TrackImpl(new FileDataSourceImpl("/home/aod/tmp/rec_1392309584754.h264"), "eng", 9, 1);
        Movie m = new Movie();
        m.addTrack(video);

        BasicContainer out = (BasicContainer) new DefaultMp4Builder().build(m);
        FileOutputStream fos = new FileOutputStream(new File("/home/aod/tmp/output.mp4"));
        out.writeContainer(fos.getChannel());
        fos.flush();                        
        fos.close();
    } catch ( IOException e) {
        e.printStackTrace();
    }
like image 23
Tolik Odukha Avatar answered Feb 12 '26 03:02

Tolik Odukha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!