Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "-y -i input.mp4 -ss 00:00:01.00 -t 00:00:15.000 -c copy output.mp4"
- "-y -i input.mp4 -ss 00:00:01.000 -t 00:00:15.000 -async 1 output.mp4"
- String[] cmd = new String[]{"-y","-i",input,"-ss","00:00:05.000","-vcodec","copy",
- "-acodec","copy","-t","00:00:15.00","-strict","-2",output };
- final FFmpeg ffmpeg = FFmpeg.getInstance(this);
- try {
- ffmpeg.execute(cmd, new FFmpegExecuteResponseHandler() {
- @Override
- public void onSuccess(String message) {
- Log.i("VideoEditActivity", "Success " + message);
- is_video_generated_ = true;
- }
- @Override
- public void onProgress(String message) {
- Log.i("VideoEditActivity", "Progress updated " + message);
- }
- @Override
- public void onFailure(String message) {
- Log.e("VideoEditActivity", "ERROR! " + message);
- }
- @Override
- public void onStart() {
- progress_dialog_.setMessage(getString(R.string.str_video_generating));
- progress_dialog_.show();
- }
- @Override
- public void onFinish() {
- Log.i("VideoEditActivity", "Finished");
- progress_dialog_.hide();
- Intent intent = new Intent(getApplicationContext(), VideoPlayActivity.class);
- intent.putExtra("media", edited_video_path_);
- startActivity(intent);
- }
- });
- } catch (FFmpegCommandAlreadyRunningException e) {
- e.printStackTrace();
- }
- /**
- * Command for cutting video
- */
- private void executeCutVideoCommand(long startMs, long endMs) {
- String destPath = "/storage/emulated/0/DCIM/test/";//Replace ypur dest Path
- File externalStoragePublicDirectory = new File(destPath);
- if (!externalStoragePublicDirectory.exists() ? externalStoragePublicDirectory.mkdir() : true) {
- String yourRealPath = "YOUR INPUT PATH";//getPath(MainActivity.this, selectedVideoUri);
- String filePrefix = yourRealPath.substring(yourRealPath.lastIndexOf("."));
- String destFileName = "cut_video";
- boolean isFastMode = false;
- File dest = (filePrefix.equals(".webm") || filePrefix.equals(".mkv")) ? new File(externalStoragePublicDirectory, destFileName + ".mp4") : new File(externalStoragePublicDirectory, destFileName + filePrefix);
- int fileNo = 0;
- while (dest.exists()) {
- fileNo++;
- dest = (filePrefix.equals(".webm") || filePrefix.equals(".mkv")) ? new File(externalStoragePublicDirectory, destFileName + fileNo + ".mp4") : new File(externalStoragePublicDirectory, destFileName + fileNo + filePrefix);
- }
- Log.d(TAG, "startTrim: src: " + yourRealPath);
- Log.d(TAG, "startTrim: dest: " + dest.getAbsolutePath());
- Log.d(TAG, "startTrim: startMs: " + startMs);
- Log.d(TAG, "startTrim: endMs: " + endMs);
- filePath = dest.getAbsolutePath();
- final String[] complexCommand = isFastMode ?
- (filePrefix.equals(".webm") || filePrefix.equals(".mkv") || filePrefix.equals(".m4v") || filePrefix.equals(".mov")) ?
- new String[]{"-ss", "" + (startMs / 1000), "-y", "-i", yourRealPath, "-preset", "ultrafast", "-t", "" + ((endMs - startMs) / 1000), "-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", "-strict", "-2", filePath}
- : new String[]{"-y", "-i", yourRealPath, "-preset", "ultrafast", "-ss", "" + (startMs / 1000), "-t", "" + ((endMs - startMs) / 1000), "-c", "copy", filePath}
- : (filePrefix.equals(".webm") || filePrefix.equals(".mkv") || filePrefix.equals(".m4v") || filePrefix.equals(".mov")) ?
- new String[]{"-ss", "" + (startMs / 1000), "-y", "-i", yourRealPath, "-t", "" + ((endMs - startMs) / 1000), "-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", "-strict", "-2", filePath} :
- new String[]{"-y", "-i", yourRealPath, "-ss", "" + (startMs / 1000), "-t", "" + ((endMs - startMs) / 1000), "-c", "copy", filePath};
- execFFmpegBinary(complexCommand);
- }
- }
- private void execFFmpegBinary(final String[] command) {
- try {
- ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
- @Override
- public void onFailure(String s) {
- Log.d(TAG, "FAILED with output : " + s);
- }
- @Override
- public void onSuccess(String s) {
- Log.d(TAG, "SUCCESS with output : " + s);
- }
- @Override
- public void onProgress(String s) {
- Log.d(TAG, "Started command : ffmpeg " + command);
- }
- @Override
- public void onStart() {
- Log.d(TAG, "Started command : ffmpeg " + command);
- }
- @Override
- public void onFinish() {
- Log.d(TAG, "Finished command : ffmpeg " + command);
- }
- });
- } catch (FFmpegCommandAlreadyRunningException e) {
- // do nothing for now
- }
- }
- -ss 00:00:00.00 -t 00:00:00.00 -noaccurate_seek -i input.mp4 -codec copy -avoid_negative_ts 1 output.mp4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement