Reputation: 41
The goal is to combine 2 .mp4 videos like one playing after the other. There are countless references to ffmpeg, which is not a very good option since it involves NDK making the project really heavy for some not so significant function.
I came to know that mediacodec has been improved a lot. I need a guide to help me through it. I couldn't find any.
Also I am looking for combining .mp3 and a photo (single) and making a .mp4
Please help.
I tried using javacv library for 2nd query, it was a dead end. The code is as follows:
{FFmpegFrameGrabber videoFrames = FFmpegFrameGrabber.createDefault(videoSource);
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFile, 200, 200);
recorder.setFrameRate(10);
recorder.start();
Frame frame = videoFrames.grab();
for (int i = 0; i < (numSeconds * 10); i++) {
recorder.record(frame);
}
}
It takes 12 seconds just to make a 5 frame video. fps is 25.
Upvotes: 2
Views: 3701
Reputation: 497
If you want to merge two video files the easy way is mp4parser (it has everything you need). The other way is to try to extract the audio and video channels with MediaExtractor
, than use the MediaMuxer
to merge the two files into one. Also, make sure the files are identical in terms of resolution, framerate and bitrate, otherwise the merge may not be perfect. In such case, you may need to re-encode the files. You can do that with FFMPEG
, or you might want to consider sophisticated Android tools such as the MediaCodec
.
UPDATE:
Creating an audio .mp4
with a single frame should be the easiest in FFMPEG
. If you need a lighter solution, you have to encode your image with MediaCodec
, and extract the audio from the .mp3
first. After that, you have to mux the given video and audio samples into a video file. You can find brilliant MediaCodec
examples in Grafika and BigFlake
Upvotes: 4