react-native-video-trim 7.1.1 → 8.1.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/src/index.tsx CHANGED
@@ -2,8 +2,21 @@ import VideoTrimNewArch from './NativeVideoTrim';
2
2
  import VideoTrimOldArch from './OldArch';
3
3
  import type {
4
4
  BaseOptions,
5
+ CompressOptions,
6
+ CompressResult,
5
7
  EditorConfig,
8
+ ExtractAudioOptions,
9
+ ExtractAudioResult,
6
10
  FileValidationResult,
11
+ FrameExtractionOptions,
12
+ FrameResult,
13
+ GifOptions,
14
+ GifResult,
15
+ MergeOptions,
16
+ MergeResult,
17
+ SaveToDocumentsResult,
18
+ SaveToPhotoResult,
19
+ ShareResult,
7
20
  TrimOptions,
8
21
  TrimResult,
9
22
  } from './NativeVideoTrim';
@@ -21,6 +34,64 @@ function createBaseOptions(overrides: Partial<BaseOptions> = {}): BaseOptions {
21
34
  removeAfterSavedToPhoto: false,
22
35
  removeAfterFailedToSavePhoto: false,
23
36
  enablePreciseTrimming: false,
37
+ removeAudio: false,
38
+ speed: 1.0,
39
+ ...overrides,
40
+ };
41
+ }
42
+
43
+ function createCompressOptions(
44
+ overrides: Partial<CompressOptions> = {}
45
+ ): CompressOptions {
46
+ return {
47
+ quality: 'medium',
48
+ bitrate: -1,
49
+ width: -1,
50
+ height: -1,
51
+ frameRate: -1,
52
+ outputExt: 'mp4',
53
+ removeAudio: false,
54
+ ...overrides,
55
+ };
56
+ }
57
+
58
+ function createFrameExtractionOptions(
59
+ overrides: Partial<FrameExtractionOptions> = {}
60
+ ): FrameExtractionOptions {
61
+ return {
62
+ time: 0,
63
+ format: 'jpeg',
64
+ quality: 80,
65
+ maxWidth: -1,
66
+ maxHeight: -1,
67
+ ...overrides,
68
+ };
69
+ }
70
+
71
+ function createExtractAudioOptions(
72
+ overrides: Partial<ExtractAudioOptions> = {}
73
+ ): ExtractAudioOptions {
74
+ return {
75
+ outputExt: 'm4a',
76
+ ...overrides,
77
+ };
78
+ }
79
+
80
+ function createGifOptions(overrides: Partial<GifOptions> = {}): GifOptions {
81
+ return {
82
+ startTime: 0,
83
+ endTime: -1,
84
+ fps: 10,
85
+ width: -1,
86
+ ...overrides,
87
+ };
88
+ }
89
+
90
+ function createMergeOptions(
91
+ overrides: Partial<MergeOptions> = {}
92
+ ): MergeOptions {
93
+ return {
94
+ outputExt: 'mp4',
24
95
  ...overrides,
25
96
  };
26
97
  }
@@ -78,6 +149,7 @@ function createEditorConfig(
78
149
  waveformBarWidth: 3,
79
150
  waveformBarGap: 2,
80
151
  waveformBarCornerRadius: 1.5,
152
+ durationFormat: 'mm:ss.SSS',
81
153
  ...createBaseOptions(overrides),
82
154
  ...overrides,
83
155
  };
@@ -214,5 +286,119 @@ export function trim(
214
286
  return VideoTrim.trim(url, createTrimOptions(options));
215
287
  }
216
288
 
289
+ /**
290
+ * Extract a single frame from a video at a given timestamp
291
+ *
292
+ * @param {string} url: absolute non-empty file path
293
+ * @param {Partial<FrameExtractionOptions>} options: extraction options
294
+ * @returns {Promise<FrameResult>} A **Promise** which resolves to the FrameResult
295
+ */
296
+ export function getFrameAt(
297
+ url: string,
298
+ options: Partial<FrameExtractionOptions> = {}
299
+ ): Promise<FrameResult> {
300
+ return VideoTrim.getFrameAt(url, createFrameExtractionOptions(options));
301
+ }
302
+
303
+ /**
304
+ * Extract the audio track from a video file
305
+ *
306
+ * @param {string} url: absolute non-empty file path
307
+ * @param {Partial<ExtractAudioOptions>} options: extraction options
308
+ * @returns {Promise<ExtractAudioResult>} A **Promise** which resolves to the result
309
+ */
310
+ export function extractAudio(
311
+ url: string,
312
+ options: Partial<ExtractAudioOptions> = {}
313
+ ): Promise<ExtractAudioResult> {
314
+ return VideoTrim.extractAudio(url, createExtractAudioOptions(options));
315
+ }
316
+
317
+ /**
318
+ * Compress a video file to reduce its size
319
+ *
320
+ * @param {string} url: absolute non-empty file path
321
+ * @param {Partial<CompressOptions>} options: compression options
322
+ * @returns {Promise<CompressResult>} A **Promise** which resolves to the result
323
+ */
324
+ export function compress(
325
+ url: string,
326
+ options: Partial<CompressOptions> = {}
327
+ ): Promise<CompressResult> {
328
+ return VideoTrim.compress(url, createCompressOptions(options));
329
+ }
330
+
331
+ /**
332
+ * Convert a video segment to an animated GIF
333
+ *
334
+ * @param {string} url: absolute non-empty file path
335
+ * @param {Partial<GifOptions>} options: GIF conversion options
336
+ * @returns {Promise<GifResult>} A **Promise** which resolves to the result
337
+ */
338
+ export function toGif(
339
+ url: string,
340
+ options: Partial<GifOptions> = {}
341
+ ): Promise<GifResult> {
342
+ return VideoTrim.toGif(url, createGifOptions(options));
343
+ }
344
+
345
+ /**
346
+ * Merge multiple media files into a single file (headless, no UI)
347
+ *
348
+ * @param {string[]} urls: array of file paths to merge in order
349
+ * @param {Partial<MergeOptions>} options: merge options
350
+ * @returns {Promise<MergeResult>} A **Promise** which resolves to the result
351
+ */
352
+ export function merge(
353
+ urls: string[],
354
+ options: Partial<MergeOptions> = {}
355
+ ): Promise<MergeResult> {
356
+ if (!urls?.length) {
357
+ throw new Error('URLs array cannot be empty!');
358
+ }
359
+ return VideoTrim.merge(urls, createMergeOptions(options));
360
+ }
361
+
362
+ /**
363
+ * Save a file to the device's photo library
364
+ *
365
+ * @param {string} filePath: absolute path to the file
366
+ * @returns {Promise<SaveToPhotoResult>} A **Promise** which resolves to the result
367
+ */
368
+ export function saveToPhoto(filePath: string): Promise<SaveToPhotoResult> {
369
+ if (!filePath?.trim().length) {
370
+ throw new Error('File path cannot be empty!');
371
+ }
372
+ return VideoTrim.saveToPhoto(filePath);
373
+ }
374
+
375
+ /**
376
+ * Present the system document picker to save a file
377
+ *
378
+ * @param {string} filePath: absolute path to the file
379
+ * @returns {Promise<SaveToDocumentsResult>} A **Promise** which resolves to the result
380
+ */
381
+ export function saveToDocuments(
382
+ filePath: string
383
+ ): Promise<SaveToDocumentsResult> {
384
+ if (!filePath?.trim().length) {
385
+ throw new Error('File path cannot be empty!');
386
+ }
387
+ return VideoTrim.saveToDocuments(filePath);
388
+ }
389
+
390
+ /**
391
+ * Open the system share sheet for a file
392
+ *
393
+ * @param {string} filePath: absolute path to the file
394
+ * @returns {Promise<ShareResult>} A **Promise** which resolves to the result
395
+ */
396
+ export function share(filePath: string): Promise<ShareResult> {
397
+ if (!filePath?.trim().length) {
398
+ throw new Error('File path cannot be empty!');
399
+ }
400
+ return VideoTrim.share(filePath);
401
+ }
402
+
217
403
  export * from './NativeVideoTrim';
218
404
  export default VideoTrim;