react-native-video-trim 3.0.3 → 3.0.4
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.
|
@@ -89,11 +89,34 @@ public class VideoTrimmerUtil {
|
|
|
89
89
|
long endUs = endMs * 1000; // e.g., 9s = 9000000us
|
|
90
90
|
long trimmedDurationUs = endUs - startUs; // e.g., 4s = 4000000us
|
|
91
91
|
|
|
92
|
+
// Determine max buffer size from video format and resolution
|
|
93
|
+
int maxBufferSize = BUFFER_SIZE; // Default 1MB
|
|
94
|
+
String widthStr = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
|
|
95
|
+
String heightStr = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
|
|
96
|
+
int width = widthStr != null ? Integer.parseInt(widthStr) : 0; // Default to unknown
|
|
97
|
+
int height = heightStr != null ? Integer.parseInt(heightStr) : 0;
|
|
98
|
+
|
|
99
|
+
// Adjust buffer size based on resolution
|
|
100
|
+
if (width > 3840 || height > 2160) { // 8K+
|
|
101
|
+
maxBufferSize = 16 * 1024 * 1024; // 16MB for 8K
|
|
102
|
+
} else if (width > 1920 || height > 1080) { // 4K
|
|
103
|
+
maxBufferSize = 8 * 1024 * 1024; // 8MB for 4K
|
|
104
|
+
} else if (width > 1280 || height > 720) { // 1080p
|
|
105
|
+
maxBufferSize = 4 * 1024 * 1024; // 4MB for 1080p
|
|
106
|
+
} // 720p or lower (or unknown resolution) sticks with BUFFER_SIZE (1MB)
|
|
107
|
+
|
|
92
108
|
// Add tracks with corrected duration
|
|
93
109
|
for (int i = 0; i < trackCount; i++) {
|
|
94
110
|
MediaFormat format = extractor.getTrackFormat(i);
|
|
111
|
+
|
|
112
|
+
// Override with KEY_MAX_INPUT_SIZE if available
|
|
113
|
+
if (format.containsKey(MediaFormat.KEY_MAX_INPUT_SIZE)) {
|
|
114
|
+
int maxInputSize = format.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE);
|
|
115
|
+
maxBufferSize = Math.max(maxBufferSize, maxInputSize);
|
|
116
|
+
}
|
|
117
|
+
|
|
95
118
|
String mime = format.getString(MediaFormat.KEY_MIME);
|
|
96
|
-
if (mime.startsWith("video/")) {
|
|
119
|
+
if (mime != null && mime.startsWith("video/")) {
|
|
97
120
|
videoTrackIndex = i;
|
|
98
121
|
}
|
|
99
122
|
// Set the duration for each track to the trimmed duration
|
|
@@ -109,7 +132,7 @@ public class VideoTrimmerUtil {
|
|
|
109
132
|
// Seek to start time
|
|
110
133
|
extractor.seekTo(startUs, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
|
|
111
134
|
|
|
112
|
-
ByteBuffer buffer = ByteBuffer.allocate(
|
|
135
|
+
ByteBuffer buffer = ByteBuffer.allocate(maxBufferSize);
|
|
113
136
|
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
|
114
137
|
long lastProgressTime = System.currentTimeMillis();
|
|
115
138
|
boolean videoSampleWritten = false;
|