Requirement :
I want to develop an app that has Video Recoding with pause and resume feature.
I Have Tried :
I have developed the app upto recoding the video by using surface view.
Already Researched :
I have already searched all the site and also like but till now i can't get the solution and
that i know there is no default option in android for pause and resume video and also know by merging the video we can achieve it.
What i need:
Please share me if there is any external plugin available for it, guide me how to achieve this if you already achieved, and also share me any resouce that related to how to merge video ..i have searched but no proper resource i had seen please share any thing if you find..
Asked
Active
Viewed 6,017 times
10
1 Answers
6
Finally i find the answer :)
i research about ffmpeg it seems more deeply and some more days digging around it but can't get
proper resource for ffmepg and i try to use mp4parser lib and successfully completed my requirement.
Code For Merging Multiple Video
public class MergeVide extends AsyncTask<String, Integer, String> {
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(Video.this,
"Preparing for upload", "Please wait...", true);
// do initialization of required objects objects here
};
@Override
protected String doInBackground(String... params) {
try {
String paths[] = new String[count];
Movie[] inMovies = new Movie[count];
for (int i = 0; i < count; i++) {
paths[i] = path + filename + String.valueOf(i + 1) + ".mp4";
inMovies[i] = MovieCreator.build(new FileInputStream(
paths[i]).getChannel());
}
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() + "/wishbyvideo.mp4"),
"rw").getChannel();
out.writeContainer(fc);
fc.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String mFileName = Environment.getExternalStorageDirectory()
.getAbsolutePath();
mFileName += "/wishbyvideo.mp4";
filename = mFileName;
return mFileName;
}
@Override
protected void onPostExecute(String value) {
super.onPostExecute(value);
progressDialog.dismiss();
Intent i = new Intent(Video.this, VideoUpload.class);
i.putExtra("videopath", value);
i.putExtra("id", id);
i.putExtra("name", name);
i.putExtra("photo", photo);
startActivity(i);
finish();
}
}
the count is nothing but video file count.
the above code for merge more video and send the final code to another activity in that i have decided to preview the video.
before using above code make sure use mp4parser lib.

Arslan Anwar
- 18,746
- 19
- 76
- 105

Karthi
- 756
- 4
- 16
-
Hey Karthi, I tried to use this code. It throws error and recommends me to cast with DataSource, after casting it throws ClassCastException on this line: inMovies[i] = MovieCreator.build((DataSource)new FileInputStream( paths[i]).getChannel()); Then I replaced path without channel and FileInputStream as it is accepting direct string file too, it stitches video too but fails to play and joins incorrectly. Can you tell me the version of the jar that you used I will try to replace with that one. Also, please tell me how not to cast DataSource. Kindly let me know. Thanks. – abhy Jan 28 '14 at 12:50
-
Well I have got an exception "java.io.IOException: Cannot append Mp4TrackImpl{handler='vide'} to Mp4TrackImpl{handler='vide'} since their Sample Description Boxes differ:" while adding this. if (videoTracks.size() > 0) { result.addTrack(new AppendTrack(videoTracks .toArray(new Track[videoTracks.size()]))); } – Ahmad Arslan Feb 06 '14 at 06:15
-
@karthi can u tell us what is BasicContainer ? – duggu May 30 '14 at 06:54
-
@Karthi - Unable to find the class BasicContainer. Can you please let us know where it is? Is it in your code?If yes, please provide me the class. – Kameswari Jun 20 '14 at 10:42
-
You can download both isoparser-1.0-RC-27.jar and aspectj-rt.jar, and include them in your libs folder. http://repo1.maven.org/maven2/org/aspectj/aspectjrt/1.7.3/ http://repo1.maven.org/maven2/com/googlecode/mp4parser/isoparser/ – Chitrang Mar 09 '15 at 11:17
-
@Karthi, it takes way too long to merge the videos together. It takes 2+ mins to merge 2 videos with the total of 5 mins. Are you experiencing the same? Thanks – IYM-14 Jun 01 '15 at 14:12
-
Using this library Can we append two videos with different capture rates?I want to append timelapse video and normal mode video – Android Developer Oct 18 '15 at 18:51