MP4Parser 创建损坏的 mp4
MP4Parser creates corrupt mp4
我正在使用 mp4parser 在 android 应用程序中将两个视频添加到一起,但输出的文件是我无法用我的 phone 或我的计算机播放的文件(Windows 媒体播放器和 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));
}
由于问题出在 MP4Parser 本身,我转向了 FFMpeg,从中我可以成功地合并视频。
我用过分路器,供以后参考;这是我使用的命令:
"ffmpeg -y -f concat -i temp.txt -c copy output.mp4"
我正在使用 mp4parser 在 android 应用程序中将两个视频添加到一起,但输出的文件是我无法用我的 phone 或我的计算机播放的文件(Windows 媒体播放器和 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));
}
由于问题出在 MP4Parser 本身,我转向了 FFMpeg,从中我可以成功地合并视频。
我用过分路器,供以后参考;这是我使用的命令:
"ffmpeg -y -f concat -i temp.txt -c copy output.mp4"