Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. "-y -i input.mp4 -ss 00:00:01.00 -t 00:00:15.000 -c copy output.mp4"
  2.  
  3. "-y -i input.mp4 -ss 00:00:01.000 -t 00:00:15.000 -async 1 output.mp4"
  4.  
  5. String[] cmd = new String[]{"-y","-i",input,"-ss","00:00:05.000","-vcodec","copy",
  6. "-acodec","copy","-t","00:00:15.00","-strict","-2",output };
  7.  
  8. final FFmpeg ffmpeg = FFmpeg.getInstance(this);
  9. try {
  10. ffmpeg.execute(cmd, new FFmpegExecuteResponseHandler() {
  11. @Override
  12. public void onSuccess(String message) {
  13. Log.i("VideoEditActivity", "Success " + message);
  14. is_video_generated_ = true;
  15. }
  16.  
  17. @Override
  18. public void onProgress(String message) {
  19. Log.i("VideoEditActivity", "Progress updated " + message);
  20. }
  21.  
  22. @Override
  23. public void onFailure(String message) {
  24. Log.e("VideoEditActivity", "ERROR! " + message);
  25. }
  26.  
  27. @Override
  28. public void onStart() {
  29. progress_dialog_.setMessage(getString(R.string.str_video_generating));
  30. progress_dialog_.show();
  31. }
  32.  
  33. @Override
  34. public void onFinish() {
  35. Log.i("VideoEditActivity", "Finished");
  36. progress_dialog_.hide();
  37.  
  38. Intent intent = new Intent(getApplicationContext(), VideoPlayActivity.class);
  39. intent.putExtra("media", edited_video_path_);
  40. startActivity(intent);
  41. }
  42. });
  43. } catch (FFmpegCommandAlreadyRunningException e) {
  44. e.printStackTrace();
  45. }
  46.  
  47. /**
  48. * Command for cutting video
  49. */
  50. private void executeCutVideoCommand(long startMs, long endMs) {
  51.  
  52. String destPath = "/storage/emulated/0/DCIM/test/";//Replace ypur dest Path
  53. File externalStoragePublicDirectory = new File(destPath);
  54. if (!externalStoragePublicDirectory.exists() ? externalStoragePublicDirectory.mkdir() : true) {
  55. String yourRealPath = "YOUR INPUT PATH";//getPath(MainActivity.this, selectedVideoUri);
  56. String filePrefix = yourRealPath.substring(yourRealPath.lastIndexOf("."));
  57. String destFileName = "cut_video";
  58. boolean isFastMode = false;
  59. File dest = (filePrefix.equals(".webm") || filePrefix.equals(".mkv")) ? new File(externalStoragePublicDirectory, destFileName + ".mp4") : new File(externalStoragePublicDirectory, destFileName + filePrefix);
  60. int fileNo = 0;
  61. while (dest.exists()) {
  62. fileNo++;
  63. dest = (filePrefix.equals(".webm") || filePrefix.equals(".mkv")) ? new File(externalStoragePublicDirectory, destFileName + fileNo + ".mp4") : new File(externalStoragePublicDirectory, destFileName + fileNo + filePrefix);
  64. }
  65. Log.d(TAG, "startTrim: src: " + yourRealPath);
  66. Log.d(TAG, "startTrim: dest: " + dest.getAbsolutePath());
  67. Log.d(TAG, "startTrim: startMs: " + startMs);
  68. Log.d(TAG, "startTrim: endMs: " + endMs);
  69. filePath = dest.getAbsolutePath();
  70. final String[] complexCommand = isFastMode ?
  71. (filePrefix.equals(".webm") || filePrefix.equals(".mkv") || filePrefix.equals(".m4v") || filePrefix.equals(".mov")) ?
  72. 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}
  73. : new String[]{"-y", "-i", yourRealPath, "-preset", "ultrafast", "-ss", "" + (startMs / 1000), "-t", "" + ((endMs - startMs) / 1000), "-c", "copy", filePath}
  74. : (filePrefix.equals(".webm") || filePrefix.equals(".mkv") || filePrefix.equals(".m4v") || filePrefix.equals(".mov")) ?
  75. 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} :
  76. new String[]{"-y", "-i", yourRealPath, "-ss", "" + (startMs / 1000), "-t", "" + ((endMs - startMs) / 1000), "-c", "copy", filePath};
  77. execFFmpegBinary(complexCommand);
  78. }
  79. }
  80.  
  81. private void execFFmpegBinary(final String[] command) {
  82. try {
  83. ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
  84. @Override
  85. public void onFailure(String s) {
  86. Log.d(TAG, "FAILED with output : " + s);
  87. }
  88.  
  89. @Override
  90. public void onSuccess(String s) {
  91. Log.d(TAG, "SUCCESS with output : " + s);
  92.  
  93. }
  94.  
  95. @Override
  96. public void onProgress(String s) {
  97. Log.d(TAG, "Started command : ffmpeg " + command);
  98.  
  99. }
  100.  
  101. @Override
  102. public void onStart() {
  103. Log.d(TAG, "Started command : ffmpeg " + command);
  104.  
  105. }
  106.  
  107. @Override
  108. public void onFinish() {
  109. Log.d(TAG, "Finished command : ffmpeg " + command);
  110.  
  111.  
  112. }
  113. });
  114. } catch (FFmpegCommandAlreadyRunningException e) {
  115. // do nothing for now
  116. }
  117. }
  118.  
  119. -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