简体   繁体   中英

MP4Parser creates corrupt mp4

I'm using mp4parser to add two videos together in an android app, but the output is a file I can't play with my phone or my computer (Windows Media Player and VLC). This is the function i use

public void MergeVideos(String[] pathsToVideos, String pathToOutput) throws IOException, InterruptedException
{
    List<Track> tracks = new LinkedList<Track>();
    Movie outputVideo = new Movie();

    for (int i = 0; i < pathsToVideos.length; i++)
    {
        Movie video = MovieCreator.build(pathsToVideos[i]);
        List<Track> trackss = video.getTracks();   
        for (Track track : trackss) 
        {
            if (track.getHandler().equals("vide"))
            {
                tracks.add(track);
            }
        }
    }

    outputVideo.addTrack(new AppendTrack(tracks.toArray(new Track[tracks.size()])));
    Container out = new DefaultMp4Builder().build(outputVideo);

    File outputFile = new File(pathToOutput);

    if(!outputFile.exists())
    {
        outputFile.createNewFile();
    }

    //write mp4 file
    FileChannel fc = new RandomAccessFile(String.format(pathToOutput), "rw").getChannel();
    out.writeContainer(fc);
    fc.close();

    //Add to the android media gallery so i can see it on my computer
    addToGallery(new File(pathToOutput));
}

Since the problem was coming from MP4Parser itself, I stepped over to FFMpeg, from which I can successfully combine videos.

I'm used the demuxer and for later reference; this is the command I used:

"ffmpeg -y -f concat -i temp.txt -c copy output.mp4"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM