0

I try to concat two mp4 video by mp4parser lib. But I'm getting error. Here is my code

public void appendTwoVideo(String mp4_1,String mp4_2) throws IOException {
    Movie[] inMovies = new Movie[]{MovieCreator.build(mp4_1),
            MovieCreator.build(mp4_2)};

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

In line

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

I'm getting error

Error:(296, 53) error: incompatible types: Container cannot be converted to IsoFile.

Can anyone help me with my error or how can concat two videos any other way?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Butterfly
  • 445
  • 1
  • 9
  • 22

1 Answers1

0

I find the solution

Just don’t use IsoFile. Use Container as type, write the container to disk with

    WritableByteChannel wbc = new FileOutputStream(

            new File(outputDirectory, filename)).getChannel();

    try {

        container.writeContainer(wbc);

    } finally {

        wbc.close();

    }

https://groups.google.com/forum/#!msg/mp4parser-discussion/t3jRVeRsGFs/RTT3bdDN-qQJ

Butterfly
  • 445
  • 1
  • 9
  • 22