I'm attempting to append a simple, 3 second outro video to an existing video using MP4Parser, but for some reason I cannot play the video after the merge happens. I'm getting the infamous "Sorry, this video cannot be played" error when trying to play the video from my gallery. Anyone have similar experience doing this? I'm testing on an HTC One running 4.4 KitKat
Here's my method to merge to .mp4 clips into a single one, taken from the AppendExample from MP4Parser itself.
private void createFinalOutputVideo() {
CameraHelper helper = new CameraHelper(this);
File outFile = helper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO);
try {
Movie[] movies = new Movie[2];
movies[0] = MovieCreator.build(mVideoPath);
movies[1] = MovieCreator.build(mOutroPath);
Log.d("ShareActivity", "Video 1 path " + mVideoPath);
Log.d("ShareActivity", "Video 2 path " + mOutroPath);
List<Track> videoTracks = new LinkedList<Track>();
List<Track> audioTracks = new LinkedList<Track>();
for (Movie m : movies) {
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()])));
}
Container out = new DefaultMp4Builder().build(result);
FileChannel fc = new RandomAccessFile(String.format(outFile.getPath()), "rw").getChannel();
out.writeContainer(fc);
fc.close();
Toast.makeText(this, "Merge successful! Output path is " + outFile.getAbsolutePath(), Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Error merging videos!", Toast.LENGTH_SHORT).show();
}
}
Has anyone ever had this issue with MP4Parser? Would be great if Sebastian could chime in here.
I have been using https://github.com/hoolrory/AndroidVideoSamples for resizing Videos which uses mp4parser internally. The samples have a way to resize the video but it will not have the sound. So I added a mix to add tracks into the video. But then the video will error out with "Can't play this video" message at the end.
Hope that helps in someways.
来源:https://stackoverflow.com/questions/26708247/android-mp4parser-cannot-play-video