react-native-video-trim 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -33
- package/android/src/main/AndroidManifest.xml +13 -0
- package/android/src/main/java/com/videotrim/VideoTrimModule.java +282 -75
- package/android/src/main/java/com/videotrim/enums/ErrorCode.java +10 -0
- package/android/src/main/java/com/videotrim/interfaces/VideoTrimListener.java +4 -1
- package/android/src/main/java/com/videotrim/utils/MediaMetadataUtil.java +75 -0
- package/android/src/main/java/com/videotrim/utils/StorageUtil.java +2 -2
- package/android/src/main/java/com/videotrim/utils/VideoTrimmerUtil.java +26 -16
- package/android/src/main/java/com/videotrim/widgets/VideoTrimmerView.java +310 -81
- package/android/src/main/res/drawable/airpodsmax.xml +19 -0
- package/android/src/main/res/drawable/exclamationmark_triangle_fill.xml +15 -0
- package/android/src/main/res/drawable/thumb_container_bg.xml +8 -0
- package/android/src/main/res/layout/video_trimmer_view.xml +71 -4
- package/android/src/main/res/xml/file_paths.xml +5 -0
- package/ios/AssetLoader.swift +99 -0
- package/ios/ErrorCode.swift +16 -0
- package/ios/ProgressAlertController.swift +100 -0
- package/ios/VideoTrim.mm +4 -2
- package/ios/VideoTrim.swift +472 -177
- package/ios/VideoTrimmer.swift +16 -10
- package/ios/VideoTrimmerViewController.swift +191 -22
- package/lib/commonjs/index.js +25 -55
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +24 -55
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +215 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +229 -66
- package/android/src/main/java/iknow/android/utils/BuildConfig.java +0 -18
- package/android/src/main/java/iknow/android/utils/DateUtil.java +0 -64
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
package com.videotrim.utils;
|
|
2
2
|
|
|
3
|
-
import android.
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
4
|
import android.graphics.Bitmap;
|
|
5
5
|
import android.media.MediaMetadataRetriever;
|
|
6
|
-
import android.net.Uri;
|
|
7
6
|
import com.arthenica.ffmpegkit.FFmpegKit;
|
|
7
|
+
import com.arthenica.ffmpegkit.FFmpegSession;
|
|
8
8
|
import com.arthenica.ffmpegkit.ReturnCode;
|
|
9
9
|
import com.arthenica.ffmpegkit.SessionState;
|
|
10
10
|
import com.facebook.react.bridge.Arguments;
|
|
11
11
|
import com.facebook.react.bridge.WritableMap;
|
|
12
|
+
import com.videotrim.enums.ErrorCode;
|
|
12
13
|
import com.videotrim.interfaces.VideoTrimListener;
|
|
13
14
|
|
|
14
15
|
import java.text.SimpleDateFormat;
|
|
@@ -31,18 +32,19 @@ public class VideoTrimmerUtil {
|
|
|
31
32
|
public static int MAX_COUNT_RANGE = 10; // how many images in the highlight range of seek bar
|
|
32
33
|
public static int SCREEN_WIDTH_FULL = DeviceUtil.getDeviceWidth();
|
|
33
34
|
public static final int RECYCLER_VIEW_PADDING = UnitConverter.dpToPx(35);
|
|
35
|
+
public static String DEFAULT_AUDIO_EXTENSION = ".wav";
|
|
34
36
|
public static int VIDEO_FRAMES_WIDTH = SCREEN_WIDTH_FULL - RECYCLER_VIEW_PADDING * 2;
|
|
35
37
|
// public static final int THUMB_WIDTH = (SCREEN_WIDTH_FULL - RECYCLER_VIEW_PADDING * 2) / VIDEO_MAX_TIME;
|
|
36
38
|
public static int mThumbWidth = 0; // make it automatic
|
|
37
39
|
public static final int THUMB_HEIGHT = UnitConverter.dpToPx(50); // x2 for better resolution
|
|
38
40
|
private static final int THUMB_RESOLUTION_RES = 2; // double thumb resolution for better quality
|
|
39
41
|
|
|
40
|
-
public static
|
|
42
|
+
public static FFmpegSession trim(String inputFile, String outputFile, int videoDuration, long startMs, long endMs, final VideoTrimListener callback) {
|
|
41
43
|
// Get the current date and time
|
|
42
44
|
Date currentDate = new Date();
|
|
43
45
|
|
|
44
46
|
// Create a SimpleDateFormat object with the desired format
|
|
45
|
-
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
|
47
|
+
@SuppressLint("SimpleDateFormat") SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
|
46
48
|
|
|
47
49
|
// Set the timezone to UTC
|
|
48
50
|
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
@@ -65,19 +67,21 @@ public class VideoTrimmerUtil {
|
|
|
65
67
|
"creation_time=" + formattedDateTime,
|
|
66
68
|
outputFile
|
|
67
69
|
};
|
|
70
|
+
System.out.println("Command: " + String.join(",", cmds));
|
|
68
71
|
|
|
69
|
-
FFmpegKit.executeWithArgumentsAsync(cmds, session -> {
|
|
72
|
+
return FFmpegKit.executeWithArgumentsAsync(cmds, session -> {
|
|
70
73
|
SessionState state = session.getState();
|
|
71
74
|
ReturnCode returnCode = session.getReturnCode();
|
|
72
|
-
|
|
73
|
-
if (ReturnCode.isSuccess(returnCode)) {
|
|
75
|
+
if (ReturnCode.isSuccess(session.getReturnCode())) {
|
|
74
76
|
// SUCCESS
|
|
75
77
|
callback.onFinishTrim(outputFile, startMs, endMs, videoDuration);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
} else if (ReturnCode.isCancel(session.getReturnCode())) {
|
|
79
|
+
// CANCEL
|
|
80
|
+
callback.onCancelTrim();
|
|
81
|
+
} else {
|
|
82
|
+
// FAILURE
|
|
79
83
|
String errorMessage = String.format("Command failed with state %s and rc %s.%s", state, returnCode, session.getFailStackTrace());
|
|
80
|
-
callback.onError(errorMessage);
|
|
84
|
+
callback.onError(errorMessage, ErrorCode.TRIMMING_FAILED);
|
|
81
85
|
}
|
|
82
86
|
}, log -> {
|
|
83
87
|
System.out.println("FFmpeg process started with log " + log.getMessage());
|
|
@@ -110,18 +114,25 @@ public class VideoTrimmerUtil {
|
|
|
110
114
|
});
|
|
111
115
|
}
|
|
112
116
|
|
|
113
|
-
public static void shootVideoThumbInBackground(final
|
|
117
|
+
public static void shootVideoThumbInBackground(final MediaMetadataRetriever mediaMetadataRetriever, final int totalThumbsCount, final long startPosition,
|
|
114
118
|
final long endPosition, final SingleCallback<Bitmap, Integer> callback) {
|
|
115
119
|
BackgroundExecutor.execute(new BackgroundExecutor.Task("", 0L, "") {
|
|
116
120
|
@Override public void execute() {
|
|
117
121
|
try {
|
|
118
|
-
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
|
|
119
|
-
mediaMetadataRetriever.setDataSource(context, videoUri);
|
|
120
122
|
// Retrieve media data use microsecond
|
|
121
123
|
long interval = (endPosition - startPosition) / (totalThumbsCount - 1);
|
|
122
124
|
for (long i = 0; i < totalThumbsCount; ++i) {
|
|
123
125
|
long frameTime = startPosition + interval * i;
|
|
124
|
-
|
|
126
|
+
|
|
127
|
+
Bitmap bitmap;
|
|
128
|
+
try {
|
|
129
|
+
bitmap = mediaMetadataRetriever.getFrameAtTime(frameTime * 1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
|
|
130
|
+
} catch (final Throwable t) {
|
|
131
|
+
// this can happen while thumbnails are being generated in background and we press Cancel
|
|
132
|
+
t.printStackTrace();
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
|
|
125
136
|
if(bitmap == null) continue;
|
|
126
137
|
try {
|
|
127
138
|
bitmap = Bitmap.createScaledBitmap(bitmap, mThumbWidth * THUMB_RESOLUTION_RES, THUMB_HEIGHT * THUMB_RESOLUTION_RES, false);
|
|
@@ -130,7 +141,6 @@ public class VideoTrimmerUtil {
|
|
|
130
141
|
}
|
|
131
142
|
callback.onSingleCallback(bitmap, (int) interval);
|
|
132
143
|
}
|
|
133
|
-
mediaMetadataRetriever.release();
|
|
134
144
|
} catch (final Throwable e) {
|
|
135
145
|
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
|
|
136
146
|
}
|