问题
I have a audio recording in multiple files. I am creating one continues audio file using com.googlecode.mp4parser:isoparser:1.0.2
library.
Below is my code :
String mediaKey = isAudio ? "soun" : "vide";
List<Movie> listMovies = new ArrayList<>();
for (String filename : sourceFiles) {
listMovies.add(MovieCreator.build(filename));
}
List<Track> listTracks = new LinkedList<>();
for (Movie movie : listMovies) {
for (Track track : movie.getTracks()) {
if (track.getHandler().equals(mediaKey)) {
listTracks.add(track);
}
}
}
Movie outputMovie = new Movie();
if (!listTracks.isEmpty()) {
outputMovie.addTrack(new AppendTrack(listTracks.toArray(new Track[listTracks.size()])));
}
Container container = new DefaultMp4Builder().build(outputMovie);
FileChannel fileChannel = new RandomAccessFile(String.format(targetFile), "rw").getChannel();
container.writeContainer(fileChannel);
fileChannel.close();
Above code runs on Android phone. As its mobile environment there are memory limitations per application.
Problem with above code is when I load Movie from file and create a track list for small files its working fine. But as file size grows the operation starts to become non-responsive. It takes lot of memory. How can I make it memory efficient. Is their any way of doing this operations in small streams as we do in case of file copy operations in Java ?
Update :
For recording audio in files, I am using android MediaRecorder
for this operations with Output format as MPEG_4
and Audio encoder as AAC
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
来源:https://stackoverflow.com/questions/47009530/creating-movie-from-files-by-adding-track-using-com-googlecode-mp4parser-with-wi