我正在通过 Android MediaRecorder 创建视频..
这是我添加视频的代码,
音频总是比视频长....
视频在最后停留 3 - 5 秒,而音频继续播放。
private void doAppend(String _firstVideox, String _secondVideox,
String _newName) {
try {
FileInputStream fis1 = new FileInputStream(_firstVideox);
FileInputStream fis2 = new FileInputStream(_secondVideox);
Movie[] inMovies = new Movie[] {
MovieCreator.build(fis1.getChannel()),
MovieCreator.build(fis2.getChannel()) };
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()])));
}
IsoFile out = new DefaultMp4Builder().build(result);
String filename = _newName;
lastAppendOut = filename;
FileOutputStream fos = new FileOutputStream(filename);
FileChannel fco = fos.getChannel();
fco.position(0);
out.getBox(fco);
fco.close();
fos.close();
fis1.close();
fis2.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
请检查一下并帮助我,我该怎么办。