Q:

How to trim the video with start & end time in android programmatically?

I want to trim the local video based on start and end time in android programmatically ,I tried below attached few links but haven't worked for me.Please let me know any working libraries or sample code to overcome this?
Refereed links:

Android sdk cut/trim video file
How to trim the video using FFMPEG library in android?
https://superuser.com/questions/377343/cut-part-from-video-file-from-start-position-to-end-position-with-ffmpeg

Thanks in advance!

A:

Use FFMPEG library to solve your problem. Thanks for writingminds to make ffmpeg simple for android 
 1. implementation 'com.writingminds:FFmpegAndroid:0.3.2'

initialize ffmpeg 
private void setUpFFmpeg() {
ffmpeg = FFmpeg.getInstance(context);

try {
    ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

        @Override
        public void onStart() {
            Log.d("Event ", "onStart");
        }

        @Override
        public void onFailure() {
            Log.d("Event ", "onFailure");
        }

        @Override
        public void onSuccess() {
            Log.d("Event ", "onSuccess");
        }

        @Override
        public void onFinish() {
            Log.d("Event ", "onFinish");

        }
    });
} catch (FFmpegNotSupportedException e) {
    // Handle if FFmpeg is not supported by device
}
}

use FFMPEG command like @Mahesh Keshvala posted above. Good work @Mahesh
then execFFmpegBinary(complexCommand); will be like this
private void execFFmpegBinary(String[] command){
      try {

    ffmpeg.execute(commands, new ExecuteBinaryResponseHandler() {

        @Override
        public void onStart() {
            Log.d("Event ", "onStart");
        }

        @Override
        public void onProgress(String message) {
            Log.e("Event ", "onProgress - " + message);

        }

        @Override
        public void onFailure(String message) {
            Log.e("Event ", "onFailure - " + message);

        }

        @Override
        public void onSuccess(String message) {
            Log.e("Event ", "onSuccess - " + message);

        }

        @Override
        public void onFinish() {
            Log.e("Event ", "onFinish");

        }
    });
} catch (FFmpegCommandAlreadyRunningException e) {
    // Handle if FFmpeg is already running
 }
}

try command for cut video
String[] complexCommand = {"-ss", "" + startMs / 1000, "-y", "-i", inputFileAbsolutePath, "-t", "" + (endMs - startMs) / 1000, "-s", "320x240", "-r", "15", "-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", outputFileAbsolutePath};

to know more about ffmpeg android refer this link

