1

我正在使用 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));
}
4

1 回答 1

0

由于问题出在 MP4Parser 本身,我转而使用 FFMpeg,我可以从中成功组合视频。

我使用了解复用器,供以后参考;这是我使用的命令:

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

于 2015-05-22T11:37:52.873 回答