我尝试了这个库来附加视频-mp4parser ..它适用于附加相同模式的视频..但我想附加不同的模式视频-延时和正常模式视频..我应该如何继续?我尝试了下面的代码如果所有视频都处于相同模式,则合并Vid
目录中的视频可以正常工作,但如果视频处于不同模式,则无法附加。
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;
}