react-native-video-processing 1.6.0 → 1.7.2

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.
Files changed (57) hide show
  1. package/.travis.yml +1 -1
  2. package/CODE_OF_CONDUCT.md +46 -0
  3. package/ISSUE_TEMPLATE.md +21 -0
  4. package/README.md +97 -41
  5. package/_config.yml +1 -0
  6. package/android/build.gradle +26 -10
  7. package/android/react-native-video-processing.iml +8 -17
  8. package/android/src/main/java/com/shahenlibrary/Events/Events.java +2 -0
  9. package/android/src/main/java/com/shahenlibrary/RNVideoProcessingPackage.java +1 -2
  10. package/android/src/main/java/com/shahenlibrary/Trimmer/Trimmer.java +705 -112
  11. package/android/src/main/java/com/shahenlibrary/Trimmer/TrimmerManager.java +50 -7
  12. package/android/src/main/java/com/shahenlibrary/VideoPlayer/VideoPlayerView.java +80 -6
  13. package/android/src/main/java/com/shahenlibrary/VideoPlayer/VideoPlayerViewManager.java +35 -12
  14. package/android/src/main/java/com/shahenlibrary/interfaces/OnCompressVideoListener.java +8 -0
  15. package/android/src/main/java/com/shahenlibrary/utils/VideoEdit.java +34 -7
  16. package/android/src/main/jniLibs/arm64-v8a/libffmpeg.so +0 -0
  17. package/android/src/main/jniLibs/armeabi-v7a/libffmpeg.so +0 -0
  18. package/android/src/main/jniLibs/x86/libffmpeg.so +0 -0
  19. package/android/src/main/jniLibs/x86_64/libffmpeg.so +0 -0
  20. package/ios/RNVideoProcessing/RCTSwiftBridgeModule.h +29 -0
  21. package/ios/RNVideoProcessing/RNTrimmerView/ICGVideoTrimmer/ICGVideoTrimmerView.h +5 -0
  22. package/ios/RNVideoProcessing/RNTrimmerView/ICGVideoTrimmer/ICGVideoTrimmerView.m +48 -13
  23. package/ios/RNVideoProcessing/RNTrimmerView/RNTrimmerView.h +1 -0
  24. package/ios/RNVideoProcessing/RNTrimmerView/RNTrimmerView.swift +107 -36
  25. package/ios/RNVideoProcessing/RNTrimmerView/RNTrimmerViewBridge.m +4 -1
  26. package/ios/RNVideoProcessing/RNTrimmerView/RNTrimmerViewManager.swift +4 -1
  27. package/ios/RNVideoProcessing/RNVideoPlayer.swift +372 -291
  28. package/ios/RNVideoProcessing/RNVideoProcessingBridge.m +4 -1
  29. package/ios/RNVideoProcessing/RNVideoProcessingManager.swift +18 -4
  30. package/ios/RNVideoProcessing/RNVideoTrimmer/AVUtilities.swift +81 -0
  31. package/ios/RNVideoProcessing/RNVideoTrimmer/RNVideoTrimmer.swift +630 -207
  32. package/ios/RNVideoProcessing/RNVideoTrimmer/RNVideoTrimmerBridge.m +8 -3
  33. package/ios/RNVideoProcessing/RNVideoTrimmer/SDAVAssetExportSession.m +32 -32
  34. package/ios/RNVideoProcessing/VideoProcessingGPUFilters.swift +0 -1
  35. package/ios/RNVideoProcessing.xcodeproj/project.pbxproj +10 -3
  36. package/lib/ProcessingManager/ProcessingManager.android.js +81 -17
  37. package/lib/ProcessingManager/ProcessingManager.ios.js +72 -10
  38. package/lib/ProcessingManager/index.js +1 -1
  39. package/lib/ProcessingManager/test/ProcessingManager.test.js +24 -0
  40. package/lib/ProcessingManager/types.android.js +26 -0
  41. package/lib/ProcessingManager/types.ios.js +21 -3
  42. package/lib/Trimmer/Trimmer.android.js +4 -6
  43. package/lib/Trimmer/Trimmer.ios.js +15 -3
  44. package/lib/Trimmer/test/Trimmer.test.js +6 -3
  45. package/lib/Trimmer/test/__snapshots__/Trimmer.test.js.snap +4 -1
  46. package/lib/VideoPlayer/VideoPlayer.android.js +76 -8
  47. package/lib/VideoPlayer/VideoPlayer.ios.js +193 -171
  48. package/lib/VideoPlayer/test/__snapshots__/VideoPlayer.test.js.snap +4 -1
  49. package/lib/utils/index.js +1 -1
  50. package/lib/utils/test/trimmer.test.js +55 -0
  51. package/lib/utils/test/utils.test.js +1 -1
  52. package/lib/utils/trimmer.js +12 -0
  53. package/package.json +37 -26
  54. package/.npmignore +0 -60
  55. package/init/index.js +0 -7
  56. package/ios/GPUImage/.npmignore +0 -25
  57. package/yarn.lock +0 -6183
@@ -6,12 +6,17 @@
6
6
  #import <Foundation/Foundation.h>
7
7
 
8
8
  #import "React/RCTBridgeModule.h"
9
+ #import "RCTSwiftBridgeModule.h"
9
10
 
10
- @interface RCT_EXTERN_MODULE(RNVideoTrimmer, NSObject)
11
+ @interface RCT_EXTERN_SWIFT_MODULE(RNVideoTrimmer, NSObject)
11
12
 
13
+ RCT_EXTERN_METHOD(getAssetInfo:(NSString *)source callback:(RCTResponseSenderBlock)callback);
12
14
  RCT_EXTERN_METHOD(trim:(NSString *)source options:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback);
15
+ RCT_EXTERN_METHOD(reverse:(NSString *)source options:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback);
16
+ RCT_EXTERN_METHOD(boomerang:(NSString *)source options:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback);
13
17
  RCT_EXTERN_METHOD(compress:(NSString *)source options:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback);
14
- RCT_EXTERN_METHOD(getPreviewImageAtPosition:(NSString *)source atTime:(float *)atTime maximumSize:(NSDictionary *)maximumSize callback:(RCTResponseSenderBlock)callback);
15
- RCT_EXTERN_METHOD(getAssetInfo:(NSString *)source callback:(RCTResponseSenderBlock)callback);
18
+ RCT_EXTERN_METHOD(getPreviewImageAtPosition:(NSString *)source atTime:(float *)atTime maximumSize:(NSDictionary *)maximumSize format:(NSString *)format callback:(RCTResponseSenderBlock)callback);
19
+ RCT_EXTERN_METHOD(getTrimmerPreviewImages:(NSString *)source startTime:(float *)startTime endTime:(float *) endTime step:(int *)step maximumSize:(NSDictionary *)maximumSize format:(NSString *)format callback:(RCTResponseSenderBlock)callback);
20
+ RCT_EXTERN_METHOD(crop:(NSString *)source options:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback);
16
21
 
17
22
  @end
@@ -48,7 +48,7 @@
48
48
  _asset = asset;
49
49
  _timeRange = CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity);
50
50
  }
51
-
51
+
52
52
  return self;
53
53
  }
54
54
 
@@ -57,7 +57,7 @@
57
57
  NSParameterAssert(handler != nil);
58
58
  [self cancelExport];
59
59
  self.completionHandler = handler;
60
-
60
+
61
61
  if (!self.outputURL)
62
62
  {
63
63
  _error = [NSError errorWithDomain:AVFoundationErrorDomain code:AVErrorExportFailed userInfo:@
@@ -67,7 +67,7 @@
67
67
  handler();
68
68
  return;
69
69
  }
70
-
70
+
71
71
  NSError *readerError;
72
72
  self.reader = [AVAssetReader.alloc initWithAsset:self.asset error:&readerError];
73
73
  if (readerError)
@@ -76,7 +76,7 @@
76
76
  handler();
77
77
  return;
78
78
  }
79
-
79
+
80
80
  NSError *writerError;
81
81
  self.writer = [AVAssetWriter assetWriterWithURL:self.outputURL fileType:self.outputFileType error:&writerError];
82
82
  if (writerError)
@@ -85,14 +85,14 @@
85
85
  handler();
86
86
  return;
87
87
  }
88
-
88
+
89
89
  self.reader.timeRange = self.timeRange;
90
90
  self.writer.shouldOptimizeForNetworkUse = self.shouldOptimizeForNetworkUse;
91
91
  self.writer.metadata = self.metadata;
92
-
92
+
93
93
  NSArray *videoTracks = [self.asset tracksWithMediaType:AVMediaTypeVideo];
94
-
95
-
94
+
95
+
96
96
  if (CMTIME_IS_VALID(self.timeRange.duration) && !CMTIME_IS_POSITIVE_INFINITY(self.timeRange.duration))
97
97
  {
98
98
  duration = CMTimeGetSeconds(self.timeRange.duration);
@@ -119,7 +119,7 @@
119
119
  {
120
120
  [self.reader addOutput:self.videoOutput];
121
121
  }
122
-
122
+
123
123
  //
124
124
  // Video input
125
125
  //
@@ -144,12 +144,12 @@
144
144
  };
145
145
  self.videoPixelBufferAdaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:self.videoInput sourcePixelBufferAttributes:pixelBufferAttributes];
146
146
  }
147
-
147
+
148
148
  //
149
149
  //Audio output
150
150
  //
151
151
  NSArray *audioTracks = [self.asset tracksWithMediaType:AVMediaTypeAudio];
152
- if (audioTracks.count > 0) {
152
+ if (self.audioSettings && audioTracks.count > 0) {
153
153
  self.audioOutput = [AVAssetReaderAudioMixOutput assetReaderAudioMixOutputWithAudioTracks:audioTracks audioSettings:nil];
154
154
  self.audioOutput.alwaysCopiesSampleData = NO;
155
155
  self.audioOutput.audioMix = self.audioMix;
@@ -161,7 +161,7 @@
161
161
  // Just in case this gets reused
162
162
  self.audioOutput = nil;
163
163
  }
164
-
164
+
165
165
  //
166
166
  // Audio input
167
167
  //
@@ -173,11 +173,11 @@
173
173
  [self.writer addInput:self.audioInput];
174
174
  }
175
175
  }
176
-
176
+
177
177
  [self.writer startWriting];
178
178
  [self.reader startReading];
179
179
  [self.writer startSessionAtSourceTime:self.timeRange.start];
180
-
180
+
181
181
  __block BOOL videoCompleted = NO;
182
182
  __block BOOL audioCompleted = NO;
183
183
  __weak typeof(self) wself = self;
@@ -201,7 +201,7 @@
201
201
  else {
202
202
  videoCompleted = YES;
203
203
  }
204
-
204
+
205
205
  if (!self.audioOutput) {
206
206
  audioCompleted = YES;
207
207
  } else {
@@ -231,20 +231,20 @@
231
231
  {
232
232
  BOOL handled = NO;
233
233
  BOOL error = NO;
234
-
234
+
235
235
  if (self.reader.status != AVAssetReaderStatusReading || self.writer.status != AVAssetWriterStatusWriting)
236
236
  {
237
237
  handled = YES;
238
238
  error = YES;
239
239
  }
240
-
240
+
241
241
  if (!handled && self.videoOutput == output)
242
242
  {
243
243
  // update the video progress
244
244
  lastSamplePresentationTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
245
245
  lastSamplePresentationTime = CMTimeSubtract(lastSamplePresentationTime, self.timeRange.start);
246
246
  self.progress = duration == 0 ? 1 : CMTimeGetSeconds(lastSamplePresentationTime) / duration;
247
-
247
+
248
248
  if ([self.delegate respondsToSelector:@selector(exportSession:renderFrame:withPresentationTime:toBuffer:)])
249
249
  {
250
250
  CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
@@ -264,7 +264,7 @@
264
264
  error = YES;
265
265
  }
266
266
  CFRelease(sampleBuffer);
267
-
267
+
268
268
  if (error)
269
269
  {
270
270
  return NO;
@@ -276,7 +276,7 @@
276
276
  return NO;
277
277
  }
278
278
  }
279
-
279
+
280
280
  return YES;
281
281
  }
282
282
 
@@ -284,7 +284,7 @@
284
284
  {
285
285
  AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
286
286
  AVAssetTrack *videoTrack = [[self.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
287
-
287
+
288
288
  // get the frame rate from videoSettings, if not set then try to get it from the video track,
289
289
  // if not set (mainly when asset is AVComposition) then use the default frame rate of 30
290
290
  float trackFrameRate = 0;
@@ -304,26 +304,26 @@
304
304
  {
305
305
  trackFrameRate = [videoTrack nominalFrameRate];
306
306
  }
307
-
307
+
308
308
  if (trackFrameRate == 0)
309
309
  {
310
310
  trackFrameRate = 30;
311
311
  }
312
-
312
+
313
313
  videoComposition.frameDuration = CMTimeMake(1, trackFrameRate);
314
314
  CGSize targetSize = CGSizeMake([self.videoSettings[AVVideoWidthKey] floatValue], [self.videoSettings[AVVideoHeightKey] floatValue]);
315
315
  CGSize naturalSize = [videoTrack naturalSize];
316
-
316
+
317
317
  CGAffineTransform transform = videoTrack.preferredTransform;
318
318
  videoComposition.frameDuration = CMTimeMake(1, trackFrameRate);
319
-
319
+
320
320
  CGFloat videoAngleInDegree = atan2(transform.b, transform.a) * 180 / M_PI;
321
321
  if (videoAngleInDegree == 90 || videoAngleInDegree == -90) {
322
322
  CGFloat width = naturalSize.width;
323
323
  naturalSize.width = naturalSize.height;
324
324
  naturalSize.height = width;
325
325
  }
326
-
326
+
327
327
  if(transform.a == 0 && transform.b == 1.0 && transform.c == -1.0 && transform.d == 0) {
328
328
  // portrait, home button at bottom (upright)
329
329
  if( (transform.tx == 0) && (transform.ty == 0) ) {
@@ -353,14 +353,14 @@
353
353
  videoComposition.renderSize = naturalSize;
354
354
  AVMutableVideoCompositionInstruction *passThroughInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
355
355
  passThroughInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, self.asset.duration);
356
-
356
+
357
357
  AVMutableVideoCompositionLayerInstruction *passThroughLayer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];
358
-
358
+
359
359
  [passThroughLayer setTransform:transform atTime:kCMTimeZero];
360
-
360
+
361
361
  passThroughInstruction.layerInstructions = @[passThroughLayer];
362
362
  videoComposition.instructions = @[passThroughInstruction];
363
-
363
+
364
364
  return videoComposition;
365
365
  }
366
366
 
@@ -371,7 +371,7 @@
371
371
  {
372
372
  return;
373
373
  }
374
-
374
+
375
375
  if (self.writer.status == AVAssetWriterStatusFailed)
376
376
  {
377
377
  [self complete];
@@ -395,7 +395,7 @@
395
395
  {
396
396
  [NSFileManager.defaultManager removeItemAtURL:self.outputURL error:nil];
397
397
  }
398
-
398
+
399
399
  if (self.completionHandler)
400
400
  {
401
401
  self.completionHandler();
@@ -3,7 +3,6 @@
3
3
  // vpTest
4
4
  //
5
5
  // Created by Shahen Hovhannisyan on 11/16/16.
6
- // Copyright © 2016 Facebook. All rights reserved.
7
6
  //
8
7
 
9
8
  import Foundation
@@ -25,6 +25,7 @@
25
25
  24F466DA1DD9F1CB0012172B /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24F4669B1DD9EB9B0012172B /* CoreVideo.framework */; };
26
26
  24F466DB1DD9F1CB0012172B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24F4669E1DD9EBBD0012172B /* QuartzCore.framework */; };
27
27
  24FFDD151DDC799E006040F9 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24FFDD141DDC799E006040F9 /* MobileCoreServices.framework */; };
28
+ B429F6152251F40500062EA7 /* AVUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B429F6142251F40500062EA7 /* AVUtilities.swift */; };
28
29
  /* End PBXBuildFile section */
29
30
 
30
31
  /* Begin PBXCopyFilesBuildPhase section */
@@ -58,7 +59,7 @@
58
59
  246271B31DDEF8AA003781DB /* RNVideoProcessingBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNVideoProcessingBridge.m; sourceTree = "<group>"; };
59
60
  246271B41DDEF8AA003781DB /* RNVideoProcessingManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RNVideoProcessingManager.swift; sourceTree = "<group>"; };
60
61
  246271B61DDEF8AA003781DB /* RNVideoTrimmer-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RNVideoTrimmer-Bridging-Header.h"; sourceTree = "<group>"; };
61
- 246271B71DDEF8AA003781DB /* RNVideoTrimmer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RNVideoTrimmer.swift; sourceTree = "<group>"; };
62
+ 246271B71DDEF8AA003781DB /* RNVideoTrimmer.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = RNVideoTrimmer.swift; sourceTree = "<group>"; tabWidth = 2; };
62
63
  246271B81DDEF8AA003781DB /* RNVideoTrimmerBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNVideoTrimmerBridge.m; sourceTree = "<group>"; };
63
64
  246271B91DDEF8AA003781DB /* VideoProcessingGPUFilters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoProcessingGPUFilters.swift; sourceTree = "<group>"; };
64
65
  246271CD1DDEF8C6003781DB /* RNVideoProcessing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNVideoProcessing.h; sourceTree = "<group>"; };
@@ -70,6 +71,8 @@
70
71
  24F4669E1DD9EBBD0012172B /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
71
72
  24F466A01DD9EBC40012172B /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
72
73
  24FFDD141DDC799E006040F9 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
74
+ B429F6142251F40500062EA7 /* AVUtilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = AVUtilities.swift; sourceTree = "<group>"; tabWidth = 2; };
75
+ B429F7102252496D00062EA7 /* RCTSwiftBridgeModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTSwiftBridgeModule.h; sourceTree = "<group>"; };
73
76
  /* End PBXFileReference section */
74
77
 
75
78
  /* Begin PBXFrameworksBuildPhase section */
@@ -101,6 +104,7 @@
101
104
  children = (
102
105
  246271B21DDEF8AA003781DB /* RNVideoProcessing-Bridging-Header.h */,
103
106
  246271CD1DDEF8C6003781DB /* RNVideoProcessing.h */,
107
+ B429F7102252496D00062EA7 /* RCTSwiftBridgeModule.h */,
104
108
  246271B31DDEF8AA003781DB /* RNVideoProcessingBridge.m */,
105
109
  246271B11DDEF8AA003781DB /* RNVideoPlayer.swift */,
106
110
  246271B41DDEF8AA003781DB /* RNVideoProcessingManager.swift */,
@@ -144,6 +148,7 @@
144
148
  24F055831E2E4A92009E0196 /* SDAVAssetExportSession */,
145
149
  246271B61DDEF8AA003781DB /* RNVideoTrimmer-Bridging-Header.h */,
146
150
  246271B71DDEF8AA003781DB /* RNVideoTrimmer.swift */,
151
+ B429F6142251F40500062EA7 /* AVUtilities.swift */,
147
152
  246271B81DDEF8AA003781DB /* RNVideoTrimmerBridge.m */,
148
153
  );
149
154
  path = RNVideoTrimmer;
@@ -220,6 +225,7 @@
220
225
  developmentRegion = English;
221
226
  hasScannedForEncodings = 0;
222
227
  knownRegions = (
228
+ English,
223
229
  en,
224
230
  );
225
231
  mainGroup = 58B511D21A9E6C8500147676;
@@ -244,6 +250,7 @@
244
250
  246271C01DDEF8AA003781DB /* RNVideoPlayer.swift in Sources */,
245
251
  246271BE1DDEF8AA003781DB /* RNTrimmerViewBridge.m in Sources */,
246
252
  246271BD1DDEF8AA003781DB /* RNTrimmerView.swift in Sources */,
253
+ B429F6152251F40500062EA7 /* AVUtilities.swift in Sources */,
247
254
  246271C11DDEF8AA003781DB /* RNVideoProcessingBridge.m in Sources */,
248
255
  246271C51DDEF8AA003781DB /* VideoProcessingGPUFilters.swift in Sources */,
249
256
  246271C31DDEF8AA003781DB /* RNVideoTrimmer.swift in Sources */,
@@ -347,7 +354,7 @@
347
354
  SKIP_INSTALL = YES;
348
355
  SWIFT_OBJC_BRIDGING_HEADER = "RNVideoProcessing-Bridging-Header.h";
349
356
  SWIFT_OPTIMIZATION_LEVEL = "-Onone";
350
- SWIFT_VERSION = 3.0;
357
+ SWIFT_VERSION = 4.2;
351
358
  };
352
359
  name = Debug;
353
360
  };
@@ -367,7 +374,7 @@
367
374
  PRODUCT_NAME = RNVideoProcessing;
368
375
  SKIP_INSTALL = YES;
369
376
  SWIFT_OBJC_BRIDGING_HEADER = "RNVideoProcessing-Bridging-Header.h";
370
- SWIFT_VERSION = 3.0;
377
+ SWIFT_VERSION = 4.2;
371
378
  };
372
379
  name = Release;
373
380
  };
@@ -3,38 +3,102 @@
3
3
  import { NativeModules } from 'react-native';
4
4
  import type {
5
5
  sourceType,
6
- trimOptions
6
+ arrayType,
7
+ trimOptions,
8
+ previewMaxSize,
9
+ format,
10
+ cropOptions
7
11
  } from './types';
8
12
 
9
- import { getActualSource } from '../utils';
13
+ import { getActualSource, numberToHHMMSS } from '../utils';
10
14
 
11
15
  const { RNTrimmerManager: TrimmerManager } = NativeModules;
12
- class ProcessingManager {
16
+ export class ProcessingManager {
13
17
  static trim(source: sourceType, options: trimOptions): Promise<string> {
18
+ if ( options.startTime != null ) {
19
+ options.startTime = numberToHHMMSS({ number: options.startTime })
20
+ }
21
+ if ( options.endTime != null ) {
22
+ options.endTime = numberToHHMMSS({ number: options.endTime })
23
+ }
24
+
14
25
  const actualSource: string = getActualSource(source);
15
26
  const mData = { source: actualSource, ...options };
16
27
  return TrimmerManager.trim(mData)
17
28
  .then((res) => res.source);
18
29
  }
19
- static compress(source: sourceType, options: any): Promise<*> {
30
+
31
+ static getPreviewForSecond(
32
+ source: sourceType,
33
+ second: number,
34
+ maximumSize: previewMaxSize,
35
+ format: format
36
+ ): Promise<*> {
20
37
  const actualSource: string = getActualSource(source);
21
- const mData = { source: actualSource, ...options };
22
- return TrimmerManager.compress(mData);
38
+ const mData = { source: actualSource, second, format };
39
+ return TrimmerManager.getPreviewImageAtPosition(mData)
40
+ .then((res) => res.image);
41
+ }
42
+
43
+ static getTrimmerPreviewImages(
44
+ source: sourceType,
45
+ startTime: number,
46
+ endTime: number,
47
+ step: number,
48
+ maximumSize: previewMaxSize,
49
+ format: fromat
50
+ ): Promise<*> {
51
+ const actualSource: string = getActualSource(source)
52
+ const mData = {
53
+ source: actualSource,
54
+ startTime,
55
+ endTime,
56
+ step,
57
+ format
58
+ }
59
+
60
+ return TrimmerManager.getTrimmerPreviewImages(mData).then((res)=> res.images)
23
61
  }
62
+
63
+
64
+
24
65
  static getVideoInfo(source: sourceType): Promise<*> {
25
66
  const actualSource: string = getActualSource(source);
26
- return TrimmerManager.getVideoInfo(actualSource)
27
- .then(({ duration, size }) => ({
28
- duration: duration / 1000,
29
- size
30
- }));
67
+ return TrimmerManager.getVideoInfo(actualSource);
31
68
  }
32
- static getPreviewForSecond(source: sourceType, second: number): Promise<*> {
69
+
70
+ static compress(source: sourceType, options: any): Promise<*> {
33
71
  const actualSource: string = getActualSource(source);
34
- const mData = { source: actualSource, second };
35
- return TrimmerManager.getPreviewImageAtPosition(mData)
36
- .then((res) => res.image);
72
+ return TrimmerManager.compress(actualSource, options);
37
73
  }
38
- }
39
74
 
40
- export default ProcessingManager;
75
+ static boomerang(source: sourceType): Promise<*> {
76
+ const actualSource: string = getActualSource(source);
77
+ return TrimmerManager.boomerang(actualSource)
78
+ .then((res) => res.source);
79
+ }
80
+
81
+ static reverse(source: sourceType): Promise<*> {
82
+ const actualSource: string = getActualSource(source);
83
+ return TrimmerManager.reverse(actualSource)
84
+ .then((res) => res.source);
85
+ }
86
+
87
+ static crop(source: sourceType, options: cropOptions): Promise<string> {
88
+ if ( options.startTime != null ) {
89
+ options.startTime = numberToHHMMSS({ number: options.startTime })
90
+ }
91
+ if ( options.endTime != null ) {
92
+ options.endTime = numberToHHMMSS({ number: options.endTime })
93
+ }
94
+
95
+ const actualSource: string = getActualSource(source);
96
+ return TrimmerManager.crop(actualSource, options)
97
+ .then((res) => res.source);
98
+ }
99
+
100
+ static merge(readableFiles: arrayType, cmd: string): Promise<string> {
101
+ return TrimmerManager.merge(readableFiles, cmd).then((res) => res.source);
102
+ }
103
+
104
+ }
@@ -1,14 +1,15 @@
1
1
  // @flow
2
2
 
3
-
4
3
  import { NativeModules } from 'react-native';
5
4
  import { getActualSource } from '../utils';
6
5
  const { RNVideoTrimmer } = NativeModules;
7
6
  import type {
8
- compressOptions,
9
- previewMaxSize,
10
7
  sourceType,
11
8
  trimOptions,
9
+ previewMaxSize,
10
+ format,
11
+ compressOptions,
12
+ cropOptions
12
13
  } from './types';
13
14
 
14
15
  export class ProcessingManager {
@@ -22,23 +23,72 @@ export class ProcessingManager {
22
23
  return resolve(output);
23
24
  });
24
25
  });
25
- };
26
+ }
27
+
28
+ static reverse(source: sourceType, options: trimOptions = {}): Promise<string> {
29
+ const actualSource: string = getActualSource(source);
30
+ return new Promise((resolve, reject) => {
31
+ RNVideoTrimmer.reverse(actualSource, options, (err: Object<*>, output: string) => {
32
+ if (err) {
33
+ return reject(err);
34
+ }
35
+ return resolve(output);
36
+ });
37
+ });
38
+ }
39
+
40
+ static boomerang(source: sourceType, options: trimOptions = {}): Promise<string> {
41
+ const actualSource: string = getActualSource(source);
42
+ return new Promise((resolve, reject) => {
43
+ RNVideoTrimmer.boomerang(actualSource, options, (err: Object<*>, output: string) => {
44
+ if (err) {
45
+ return reject(err);
46
+ }
47
+ return resolve(output);
48
+ });
49
+ });
50
+ }
51
+
26
52
  static getPreviewForSecond(
27
53
  source: sourceType,
28
54
  forSecond: ?number = 0,
29
- maximumSize: previewMaxSize
55
+ maximumSize: previewMaxSize,
56
+ format: format
30
57
  ): Promise<string> {
31
58
  const actualSource: string = getActualSource(source);
32
59
  return new Promise((resolve, reject) => {
33
- RNVideoTrimmer.getPreviewImageAtPosition(actualSource, forSecond, maximumSize,
34
- (err: Object<*>, base64: string) => {
60
+ RNVideoTrimmer.getPreviewImageAtPosition(actualSource, forSecond, maximumSize, format,
61
+ (err: Object<*>, res: any) => {
35
62
  if (err) {
36
63
  return reject(err);
37
64
  }
38
- return resolve(base64);
65
+ return resolve(res);
39
66
  });
40
67
  });
41
68
  }
69
+
70
+
71
+ static getTrimmerPreviewImages(
72
+ source: sourceType,
73
+ startTime: number,
74
+ endTime: number,
75
+ step: number,
76
+ maximumSize: previewMaxSize,
77
+ format: fromat
78
+ ): Promise<*> {
79
+ const actualSource: string = getActualSource(source)
80
+ return new Promise((resolve, reject) => {
81
+ RNVideoTrimmer.getTrimmerPreviewImages(actualSource, startTime, endTime, step, maximumSize, format,
82
+ (err: Object<x>, res: any) => {
83
+ if (err) {
84
+ return reject(err);
85
+ }
86
+ return resolve(res)
87
+ })
88
+ })
89
+ }
90
+
91
+
42
92
  static getVideoInfo(source: sourceType): Promise<*> {
43
93
  const actualSource: string = getActualSource(source);
44
94
  return new Promise((resolve, reject) => {
@@ -50,6 +100,7 @@ export class ProcessingManager {
50
100
  });
51
101
  });
52
102
  }
103
+
53
104
  static compress(source: sourceType, _options: compressOptions): Promise<string> {
54
105
  const options = { ..._options };
55
106
  const actualSource = getActualSource(source);
@@ -62,6 +113,17 @@ export class ProcessingManager {
62
113
  });
63
114
  });
64
115
  }
65
- }
66
116
 
67
- export default ProcessingManager;
117
+ static crop(source: sourceType, options: cropOptions = {}): Promise<string> {
118
+ const actualSource: string = getActualSource(source);
119
+ return new Promise((resolve, reject) => {
120
+ RNVideoTrimmer.crop(actualSource, options, (err: Object<*>, output: string) => {
121
+ if (err) {
122
+ return reject(err);
123
+ }
124
+ return resolve(output);
125
+ });
126
+ });
127
+ }
128
+
129
+ }
@@ -1 +1 @@
1
- export ProcessingManager from './ProcessingManager';
1
+ export { ProcessingManager } from './ProcessingManager';
@@ -0,0 +1,24 @@
1
+ jest.mock('../ProcessingManager.ios', () => {
2
+ const ProcessingManager = {
3
+ trim: jest.fn(),
4
+ getPreviewForSecond: jest.fn(),
5
+ compress: jest.fn()
6
+ };
7
+ return ProcessingManager;
8
+ });
9
+
10
+ import ProcessingManager from '../ProcessingManager.ios';
11
+
12
+ describe('[ProcessingManager]', () => {
13
+ it('should be defined', () => {
14
+ expect(ProcessingManager).toBeDefined();
15
+ });
16
+ it('should call trim', () => {
17
+ ProcessingManager.trim();
18
+ expect(ProcessingManager.trim).toHaveBeenCalled();
19
+ });
20
+ it('should call compress', () => {
21
+ ProcessingManager.compress();
22
+ expect(ProcessingManager.compress).toHaveBeenCalled();
23
+ });
24
+ })
@@ -8,10 +8,36 @@ export type trimOptions = {
8
8
  endTime: number
9
9
  };
10
10
 
11
+ // TODO
12
+ export type previewMaxSize = {
13
+ width: number,
14
+ height: number
15
+ };
16
+
17
+ export type format = 'base64' | 'JPEG';
18
+
19
+ export type cropOptions = {
20
+ cropOffsetX: number,
21
+ cropOffsetY: number,
22
+ cropWidth: number,
23
+ cropHeight: number,
24
+
25
+ startTime: ?number,
26
+ endTime: ?number,
27
+
28
+ // TODO: COMPRESS IN CROP
29
+ // quality: ?trimQuality
30
+ };
31
+
32
+ export type arrayType = Array<string>;
33
+
11
34
  declare class RNTrimmerManager {
12
35
  static trim(source: string, options: trimOptions): Promise<{ source: string }>;
13
36
  static compress(source: string, options: any): Promise<*>;
14
37
  static getVideoInfo(source: string): Promise<*>;
15
38
  static getPreviewImages(source: string): Promise<*>;
16
39
  static getPreviewImageAtPosition(source: string, second: number): Promise<{ image: string }>;
40
+ static getTrimmerPreviewImages(source: string, startTime: number, endTime: number, step: number): Promise<Array<{ image: string }>>;
41
+ static crop(source: string, options: cropOptions): Promise<{ source: string }>;
42
+ static merge(source: arrayType, cmd: string): Promise<{ source: string }>;
17
43
  }
@@ -14,7 +14,8 @@ export type trimQuality = 'low'
14
14
  export type trimOptions = {
15
15
  startTime: ?number,
16
16
  endTime: ?number,
17
- quality: ?trimQuality
17
+ quality: ?trimQuality,
18
+ cameraType: ?string || 'back' //'back' or 'front'
18
19
  };
19
20
 
20
21
  export type sourceType = string
@@ -32,11 +33,28 @@ export type compressOptions = {
32
33
  minimumBitrate: number
33
34
  };
34
35
 
36
+ export type format = 'base64' | 'JPEG';
37
+
38
+ export type cropOptions = {
39
+ cropOffsetX: number,
40
+ cropOffsetY: number,
41
+ cropWidth: number,
42
+ cropHeight: number,
43
+
44
+ // TODO: TRIM IN CROP
45
+ // startTime: ?String,
46
+ // endTime: ?String,
47
+
48
+ quality: ?trimQuality
49
+ };
50
+
35
51
  type processingCallback = Function;
36
52
 
37
53
  declare class RNVideoTrimmer {
38
54
  static trim(source: string, options: trimOptions, callback: processingCallback): void;
39
- static getPreviewImageAtPosition(source: string, forSecond: number, maximumSize: previewMaxSize, callback: processingCallback): void;
40
- static getAssetInfo(source: string, callback: processingCallback): void;
41
55
  static compress(source: string, options: compressOptions, callback: processingCallback): void;
56
+ static getAssetInfo(source: string, callback: processingCallback): void;
57
+ static getPreviewImageAtPosition(source: string, forSecond: number, maximumSize: previewMaxSize, callback: processingCallback): void;
58
+ static getTrimmerPreviewImages(source: string, startTime: number, endTime: number, step: number, maximumSize: previewMaxSize): Promise<*>;
59
+ static crop(source: string, options: cropOptions): Promise<{ source: string }>;
42
60
  }