First of all hello,
When I add another mp4 file at the end of an mp4 file, the video looks completely black screen but I can get the video sounds.
If I add a copy of a video to the end of it, I saw that there was no problem, but this is not a scenario I want.
I am getting the "text relocations" error when merging with the FFmpeg library. (This problem is fixed when I change this library version, but I have other problems. Therefore, mp4parser is an alternative I see.)
The piece of code that allows the videos to be merged is as follows. Thank you from now.
private void appendTwoVideos(String firstVideoPath, String secondVideoPath) {
try {
Movie[] inMovies = new Movie[2];
inMovies[0] = MovieCreator.build(firstVideoPath);
inMovies[1] = MovieCreator.build(secondVideoPath);
List<Track> videoTracks = new LinkedList<>();
List<Track> audioTracks = new LinkedList<>();
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()])));
}
BasicContainer out = (BasicContainer) new DefaultMp4Builder().build(result);
@SuppressWarnings("resource")
FileChannel fc = new RandomAccessFile(DIRECTORY_PATH + "output.mp4", "rw").getChannel();
out.writeContainer(fc);
fc.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}