mp4parser icon indicating copy to clipboard operation
mp4parser copied to clipboard

Unable to merge mp4 files

Open dummy-amit opened this issue 5 years ago • 1 comments

I am trying to merge these 2 mp4 files attached.

Only first video ends up in final video with size of that equalling addition of both files.

This is the code which I am using to merge

Any help is highly highly appreciated.

`fun combine(){
        val inMovies = arrayOf<Movie>(MovieCreator.build(getVideoFile(1))
                 , MovieCreator.build(getVideoFile(2))/*
                , MovieCreator.build(getVideoFile(3))
                , MovieCreator.build(getVideoFile(4))
                , MovieCreator.build(getVideoFile(5))
                , MovieCreator.build(getVideoFile(6))*/)

        val videoTracks = LinkedList<Track>()
        val audioTracks = LinkedList<Track>()
        for (m in inMovies) {
            for (t in m.tracks) {
                if (t.handler == "soun") {
                    audioTracks.add(t)
                }
                if (t.handler == "vide") {
                    videoTracks.add(t)
                }
            }
        }
        val result = Movie()
        audioTracks.forEach {
            result.addTrack(it)
        }

        videoTracks.forEach {
            result.addTrack(it)
        }

        val out = DefaultMp4Builder().build(result) as BasicContainer
        val fc = RandomAccessFile(
                String.format(getOutputPath()), "rw").channel
        out.writeContainer(fc)
        fc.close()
    }`

video.zip

dummy-amit avatar Jun 06 '19 13:06 dummy-amit

@sannies

dummy-amit avatar Jun 06 '19 16:06 dummy-amit