mp4parser
mp4parser copied to clipboard
OutOfMemory at android platform
Movie result = new Movie();
result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
FileChannel fc = new RandomAccessFile(mOutputFile, "rw").getChannel();
Container out = new DefaultMp4Builder().build(result);
// this code take 200+MB memory
out.writeContainer(fc);
fc.close();
The final video duration is 5 minutes, this code take 200+MB memory Please fix this problem @sannies #139
Can you please confirm that the latest commit fixed this issue? - https://github.com/sannies/mp4parser/pull/288
👍 , I will inform you as soon as I confirm it
@liungkejin Thank you, so far I have not gotten any OutOfMemory
exceptions in crashlytics. Please let me know when you have tested.
Sorry for late reply ! I tested the release version 1.1.22 and the newest master branch.
Here is the test: Append 12 videos, each video size: 720x960, duration: 10s (sum: 2min), bitrate: 10Mb/s
here is the test code
public static void test() {
ArrayList<String> files = new ArrayList<>();
files.add("/sdcard/test1.mp4");
files.add("/sdcard/test2.mp4");
files.add("/sdcard/test3.mp4");
files.add("/sdcard/test4.mp4");
files.add("/sdcard/test5.mp4");
files.add("/sdcard/test6.mp4");
files.add("/sdcard/test7.mp4");
files.add("/sdcard/test8.mp4");
files.add("/sdcard/test9.mp4");
files.add("/sdcard/test10.mp4");
files.add("/sdcard/test11.mp4");
files.add("/sdcard/test12.mp4");
try {
appendVideo(files, new File("/sdcard/test_out.mp4"));
} catch (Exception e) {
e.printStackTrace();
}
}
private static boolean appendVideo(ArrayList<String> files, File outputFile) throws Exception {
if (files.isEmpty()) {
return false;
}
if (files.size() < 2) {
File file = new File(files.get(0));
return file.renameTo(outputFile);
}
LinkedList<Track> videoTracks = new LinkedList<>();
LinkedList<Track> audioTracks = new LinkedList<>();
for (String path : files) {
Movie movie = MovieCreator.build(path);
Track vTrack = null;
Track aTrack = null;
for (Track t : movie.getTracks()) {
String hand = t.getHandler();
if (hand.equals("soun")) {
aTrack = t;
} else if (hand.equals("vide")) {
vTrack = t;
}
}
if (vTrack != null && aTrack != null) {
videoTracks.add(vTrack);
audioTracks.add(aTrack);
}
}
if (audioTracks.isEmpty()) {
throw new Exception("Video invalid");
}
Movie result = new Movie();
result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
FileChannel fc = new RandomAccessFile(outputFile, "rw").getChannel();
Log.i("Mp4Parser", "Append video: tracks: " + videoTracks.size());
Container out = new DefaultMp4Builder().build(result);
out.writeContainer(fc);
fc.close();
System.gc();
return outputFile.exists();
}
Test devices: XiaoMi 8, Android 8.1.0, RAM: 6GB
release version: com.googlecode.mp4parser:isoparser:1.1.22
result:
newest master branch : result:
Test devices: HUAWEI P9, Android 6.0, RAM 3GB
release version: com.googlecode.mp4parser:isoparser:1.1.22
result:
after force GC:
newest master branch : result:
on this device, the memory take 100MB, and more stable than release version, but after force GC, the memory no change!
@liungkejin did you ever resolve this issue? I still getting outofmemory crashes.
@liungkejin did you ever resolve this issue? I still getting outofmemory crashes.
Sorry, I didn't resolve this issue, and I'm use MP4v2 library to splice mp4 files now :-)
@liungkejin Did you compile MP4v2 or is there a library I don't know of?
@liungkejin Did you compile MP4v2 or is there a library I don't know of?
Yes, I compiled MP4v2。 Bento4 is another library, and i think it is better than MP4v2. But Bento4 is available under two different licenses! so I'm using MP4v2 in my application!