Вопрос

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.

Это было полезно?

Решение

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

Другие советы

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();
    }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top