MP4Parser创建损坏的mp4

时间:2015-05-20 14:19:45

标签: java android video mp4 mp4parser

我使用mp4parser在Android应用中添加两个视频,但输出的是我无法使用手机或计算机播放的文件(Windows Media Player和VLC)。这是我使用的功能

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

1 个答案:

答案 0 :(得分:0)

由于问题来自MP4Parser本身,我走到FFMpeg,我可以成功地合并视频。

我使用了分路器并供以后参考;这是我使用的命令:

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