Append multiple videos but result not opening

32 Views Asked by At

I am using MP4 Parser to concatenate multiple videos into one video (MP4).

When I concatenate 2 videos ,the output is that it opens and plays as it should, but when I concatenate multiple videos (3 or more), the result is that it does not play.

This is my code:

@NonNull
    public static void appendTwoVideos(@NonNull List<String> videos, String outputPath) throws IOException {
        List<Movie> inputMovies = new ArrayList<>();
        for (String input : videos) {
            inputMovies.add(MovieCreator.build(input));
        }

        List<Track> videoTracks = new LinkedList<>();
        List<Track> audioTracks = new LinkedList<>();

        for (Movie m : inputMovies) {
            for (Track t : m.getTracks()) {
                if (PREFIX_AUDIO_HANDLER.equals(t.getHandler())) {
                    audioTracks.add(t);
                }
                if (PREFIX_VIDEO_HANDLER.equals(t.getHandler())) {
                    videoTracks.add(t);
                }
            }
        }

        Movie outputMovie = new Movie();
        if (audioTracks.size() > 0) {
            outputMovie.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
        }
        if (videoTracks.size() > 0) {
            outputMovie.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
        }

        Container out = new DefaultMp4Builder().build(outputMovie);

        FileChannel fc = new RandomAccessFile(outputPath, "rw").getChannel();
        out.writeContainer(fc);
        fc.close();
    }

What am I doing wrong ?

0

There are 0 best solutions below