open-sourcecontainersmp4muxer

open source mp4 muxer in java


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.


Solution

  • 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();