问题
I tried this library for appending videos-mp4parser ..it works fine for appending same mode videos..but i want to append different mode videos-time lapse and normal mode video..How should i proceed in tht?I tried below code for merging videos in Vid
directory which works fine if all videos are in same mode but fails to append if videos are of different mode.
public class MergedVideo extends AsyncTask<Void, Integer, String> {
@Override
protected void onPreExecute() {
}
;
@Override
protected String doInBackground(Void... voids) {
try {
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "Vid");
File f = new File(mediaStorageDir.getPath());
File file[] = f.listFiles();
String paths[] = new String[file.length];
Movie[] inMovies = new Movie[file.length];
for (int i = 0; i < file.length; i++) {
paths[i] = file[i].getPath();
inMovies[i] = MovieCreator.build(paths[i]);
}
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()])));
}
BasicContainer out = (BasicContainer) new DefaultMp4Builder()
.build(result);
@SuppressWarnings("resource")
FileChannel fc = new RandomAccessFile(String.format(Environment
.getExternalStorageDirectory() + "/mergedvideo.mp4"),
"rw").getChannel();
out.writeContainer(fc);
fc.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("Bhu", e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("Bhu", e.toString());
}
String mFileName = Environment.getExternalStorageDirectory()
.getAbsolutePath();
mFileName += "/mergedvideo.mp4";
return mFileName;
}
来源:https://stackoverflow.com/questions/33213959/mp4parser-appending-different-mode-videos