大家好我想尝试使用mp4parser
在Android中附加两个视频,但问题是结果视频的持续时间为00:00
,尽管它占用视频1 +视频2的大小视频都是从同一手机的同一后凸轮捕获,具有完全相同的编码,因此encoding
没有任何问题。我已经看过mp4parser官方网站提到的样本,它的代码几乎相同,但似乎有其他事先谢谢
这是我的代码
private void appendVideos() throws IOException
{
String f1 = Environment.getExternalStorageDirectory() + "/video1.mp4";
String f2 = Environment.getExternalStorageDirectory()+ "/video2.mp4";
Movie[] inMovies;
inMovies = new Movie[]
{
MovieCreator.build(f1),
MovieCreator.build(f2),
};
List<Track> videoTracks = new LinkedList<Track>();
List<Track> audioTracks = new LinkedList<Track>();
for (Movie m : inMovies)
{
for (Track t : m.getTracks())
{
if (t.getHandler().equals("soun"))
{
audioTracks.add(t);
}
if (t.getHandler().equals("vide"))
{
videoTracks.add(t);
}
}
}
Movie result = new Movie();
if (audioTracks.size() > 0)
{
result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
}
if (videoTracks.size() > 0)
{
result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
}
Container out = new DefaultMp4Builder().build(result);
RandomAccessFile ram = new RandomAccessFile(String.format(Environment.getExternalStorageDirectory() + "/output.mp4"), "rw");
FileChannel fc = ram.getChannel();
out.writeContainer(fc);
ram.close();
fc.close();
Toast.makeText(getApplicationContext(), "success", Toast.LENGTH_SHORT).show();
}
答案 0 :(得分:1)
它与我合作。
只需执行此操作即可更改您的代码。
将isoparser-1.0-RC-37.jar替换为lib文件夹中的isoparser-1.0-RC-27.jar。
从下面的链接下载isoparser-1.0-RC-27.jar文件。 http://grepcode.com/snapshot/repo1.maven.org/maven2/com.googlecode.mp4parser/isoparser/1.0-RC-27