I am creating videos through Android MediaRecorder..
This is the code where i am appending the videos,
Audio is always longer then video....
Video stays stuck at the end for 3 - 5 seconds while audio keeps on playing.
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();
}
}
please check this out and help me, what should i do.
It was not the problem of JavaCpp
i suppose,
When we make video using MediaRecorder
in android device, the audio and video are not exactly the same...
Audio is bit larger i.e. 0.1s to 0.25s
So when we append the videos using JavaCpp
which at the end bring together the audio video stream, first appending them seperately gives a huge difference.
In my case i appended 30 to 40 videos and sometimes video audio difference went to 14 seconds, which was very distrubing...
So another approach i used was to trim every video from the end (approx 0.5s), that makes audio video stream equal.
Here you can find what i did.
I hope i helped you people.