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