I want to extract some portion of video when user is playing that video via my application. While playing a video user can give start and end duration to cut the video. so are there any way to cut the video based on duration and save to sd card ?
-
you can use the camera recorder to record the stream – Vipin Sahu Jul 18 '12 at 11:27
-
@vipin: Can you please provide more info on that – Ravi Bhojani Jul 18 '12 at 12:14
-
have ever worked with surface view ......... – Vipin Sahu Jul 19 '12 at 08:47
-
Do you want to cut a prerecorded video? I really don't understand what are trying to achieve. – Sebastian Annies Jul 20 '12 at 23:21
-
1Yes exactly, i want to cut prerecorded video – Ravi Bhojani Jul 21 '12 at 08:57
-
@SebastianAnnies I am using your MP4 library and using ShortenExample . But it's giving me outofmemory error :( – Ravi Bhojani Jul 21 '12 at 13:44
-
This is not the correct place to discuss that. Please write to the mp4parser discussion [mailing list](http://groups.google.com/group/mp4parser-discussion). (Hint try to open the IsoFile with a FileChannel object since with them I can do memorymapping tricks) – Sebastian Annies Jul 21 '12 at 23:18
-
This lib is perfect to cut videos http://stackoverflow.com/questions/11205299/android-sdk-cut-trim-video-file/11551682#11551682 – Ravi Bhojani Jun 27 '13 at 12:37
-
Check out [this](http://stackoverflow.com/a/42897025/3753273) for cutting videos using ffmpeg in android – Android Developer Mar 26 '17 at 08:59
5 Answers
You may try to compile and integrate ffmpeg into your project. I used ffmpeg to cut video and audio, is very fast, no recording needed. I've NO experience on doing it on android, but It should work. Here you have the official wiki page about ffmpeg on android:
https://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20compile%20FFmpeg%20for%20Android

- 2,762
- 1
- 28
- 22
I think that can be done using MP4Parser its purely written in java and can be used with android and also here is an example of doing video shorten in java By Sebastian-annies

- 1,617
- 1
- 19
- 35
-
Heyy Vivek can you please change the second [link](https://mp4parser.googlecode.com/svn/trunk/examples/src/main/java/com/googlecode/mp4parser/ShortenExample.java) to [this](https://github.com/sannies/mp4parser/blob/master/examples/src/main/java/com/googlecode/mp4parser/ShortenExample.java) because it has been chaged – MashukKhan Oct 10 '17 at 06:53
Android uses Mp4Parser/isoParser for Trimming Videos here is the example to trim the video https://android.googlesource.com/platform/packages/apps/Gallery2/+/android-4.4.2_r2/src/com/android/gallery3d/app/TrimVideo.java and as mentioned he usees isoParser which u can get it from "git clone https://android.googlesource.com/platform/external/mp4parser"

- 607
- 5
- 18
@Ravi --- video can be played in videoview or surfaceview android inbuilt class. In surfaceview you can start a thread to record you video from the position you select to position you want using MediaRecorder
MediaRecorder recorder = new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setOutputFile("/sdcard/recordvideooutput.3gpp");
recorder.setPreviewDisplay(mHolder.getSurface());
recorder.prepare();
YOUR mholder is the SurfaceHolder holder for attaching surface view
calling these two method will start and stop recording and the file will be written to /sdcard/recordvideooutput.3gpp
recorder.start();
recorder.stop();
use the developer guide http://developer.android.com/reference/android/media/MediaRecorder.html

- 1,441
- 1
- 18
- 29