react-native-video-trim 7.1.1 → 8.0.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/ios/VideoTrim.mm CHANGED
@@ -73,8 +73,10 @@ RCT_EXPORT_MODULE()
73
73
  dict[@"startTime"] = @(options.startTime());
74
74
  dict[@"endTime"] = @(options.endTime());
75
75
  dict[@"enablePreciseTrimming"] = @(options.enablePreciseTrimming());
76
+ dict[@"removeAudio"] = @(options.removeAudio());
77
+ dict[@"speed"] = @(options.speed());
76
78
 
77
- [self->videoTrim trim:url url:dict config:^(NSDictionary<NSString *,id> * _Nonnull result) {
79
+ [self->videoTrim trimWithInputFile:url config:dict completion:^(NSDictionary<NSString *,id> * _Nonnull result) {
78
80
  BOOL success = [result[@"success"] boolValue];
79
81
  if (success) {
80
82
  resolve(result);
@@ -143,6 +145,8 @@ RCT_EXPORT_MODULE()
143
145
  dict[@"alertOnFailMessage"] = config.alertOnFailMessage();
144
146
  dict[@"alertOnFailCloseText"] = config.alertOnFailCloseText();
145
147
  dict[@"enablePreciseTrimming"] = @(config.enablePreciseTrimming());
148
+ dict[@"removeAudio"] = @(config.removeAudio());
149
+ dict[@"speed"] = @(config.speed());
146
150
 
147
151
  // Handle optional color values
148
152
  auto trimmerColorOpt = config.trimmerColor();
@@ -193,6 +197,135 @@ RCT_EXPORT_MODULE()
193
197
  [self->videoTrim showEditor:filePath withConfig:dict];
194
198
  }
195
199
 
200
+ - (void)getFrameAt:(nonnull NSString *)url
201
+ options:(JS::NativeVideoTrim::FrameExtractionOptions &)options
202
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
203
+ reject:(nonnull RCTPromiseRejectBlock)reject {
204
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
205
+ dict[@"time"] = @(options.time());
206
+ dict[@"format"] = options.format();
207
+ dict[@"quality"] = @(options.quality());
208
+ dict[@"maxWidth"] = @(options.maxWidth());
209
+ dict[@"maxHeight"] = @(options.maxHeight());
210
+
211
+ [VideoTrimSwift getFrameAt:url options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
212
+ if (result[@"error"]) {
213
+ reject(@"ERR_FRAME_EXTRACTION", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
214
+ } else {
215
+ resolve(result);
216
+ }
217
+ }];
218
+ }
219
+
220
+ - (void)extractAudio:(nonnull NSString *)url
221
+ options:(JS::NativeVideoTrim::ExtractAudioOptions &)options
222
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
223
+ reject:(nonnull RCTPromiseRejectBlock)reject {
224
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
225
+ dict[@"outputExt"] = options.outputExt();
226
+
227
+ [VideoTrimSwift extractAudio:url options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
228
+ if (result[@"error"]) {
229
+ reject(@"ERR_EXTRACT_AUDIO", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
230
+ } else {
231
+ resolve(result);
232
+ }
233
+ }];
234
+ }
235
+
236
+ - (void)compress:(nonnull NSString *)url
237
+ options:(JS::NativeVideoTrim::CompressOptions &)options
238
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
239
+ reject:(nonnull RCTPromiseRejectBlock)reject {
240
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
241
+ dict[@"quality"] = options.quality();
242
+ dict[@"bitrate"] = @(options.bitrate());
243
+ dict[@"width"] = @(options.width());
244
+ dict[@"height"] = @(options.height());
245
+ dict[@"frameRate"] = @(options.frameRate());
246
+ dict[@"outputExt"] = options.outputExt();
247
+ dict[@"removeAudio"] = @(options.removeAudio());
248
+
249
+ [VideoTrimSwift compress:url options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
250
+ if (result[@"error"]) {
251
+ reject(@"ERR_COMPRESS", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
252
+ } else {
253
+ resolve(result);
254
+ }
255
+ }];
256
+ }
257
+
258
+ - (void)toGif:(nonnull NSString *)url
259
+ options:(JS::NativeVideoTrim::GifOptions &)options
260
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
261
+ reject:(nonnull RCTPromiseRejectBlock)reject {
262
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
263
+ dict[@"startTime"] = @(options.startTime());
264
+ dict[@"endTime"] = @(options.endTime());
265
+ dict[@"fps"] = @(options.fps());
266
+ dict[@"width"] = @(options.width());
267
+
268
+ [VideoTrimSwift toGif:url options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
269
+ if (result[@"error"]) {
270
+ reject(@"ERR_GIF", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
271
+ } else {
272
+ resolve(result);
273
+ }
274
+ }];
275
+ }
276
+
277
+ - (void)merge:(nonnull NSArray<NSString *> *)urls
278
+ options:(JS::NativeVideoTrim::MergeOptions &)options
279
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
280
+ reject:(nonnull RCTPromiseRejectBlock)reject {
281
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
282
+ dict[@"outputExt"] = options.outputExt();
283
+
284
+ [VideoTrimSwift merge:urls options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
285
+ if (result[@"error"]) {
286
+ reject(@"ERR_MERGE", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
287
+ } else {
288
+ resolve(result);
289
+ }
290
+ }];
291
+ }
292
+
293
+ - (void)saveToPhoto:(nonnull NSString *)filePath
294
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
295
+ reject:(nonnull RCTPromiseRejectBlock)reject {
296
+ [VideoTrimSwift saveToPhoto:filePath completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
297
+ if (result[@"error"]) {
298
+ reject(@"ERR_SAVE_TO_PHOTO", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
299
+ } else {
300
+ resolve(result);
301
+ }
302
+ }];
303
+ }
304
+
305
+ - (void)saveToDocuments:(nonnull NSString *)filePath
306
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
307
+ reject:(nonnull RCTPromiseRejectBlock)reject {
308
+ [VideoTrimSwift saveToDocuments:filePath completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
309
+ if (result[@"error"]) {
310
+ reject(@"ERR_SAVE_TO_DOCUMENTS", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
311
+ } else {
312
+ resolve(result);
313
+ }
314
+ }];
315
+ }
316
+
317
+ - (void)share:(nonnull NSString *)filePath
318
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
319
+ reject:(nonnull RCTPromiseRejectBlock)reject {
320
+ [VideoTrimSwift share:filePath completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
321
+ if (result[@"error"]) {
322
+ reject(@"ERR_SHARE", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
323
+ } else {
324
+ resolve(result);
325
+ }
326
+ }];
327
+ }
328
+
196
329
  - (void)closeEditor {
197
330
  if (self->videoTrim) {
198
331
  [self->videoTrim closeEditor:0];
@@ -253,6 +386,27 @@ RCT_EXTERN_METHOD(isValidFile:(NSString*)uri withResolver:(RCTPromiseResolveBloc
253
386
  RCT_EXTERN_METHOD(trim:(NSString*)uri withConfig:(NSDictionary *)config
254
387
  withResolver:(RCTPromiseResolveBlock)resolve
255
388
  withRejecter:(RCTPromiseRejectBlock)reject)
389
+ RCT_EXTERN_METHOD(getFrameAt:(NSString*)url withOptions:(NSDictionary *)options
390
+ withResolver:(RCTPromiseResolveBlock)resolve
391
+ withRejecter:(RCTPromiseRejectBlock)reject)
392
+ RCT_EXTERN_METHOD(extractAudio:(NSString*)url withOptions:(NSDictionary *)options
393
+ withResolver:(RCTPromiseResolveBlock)resolve
394
+ withRejecter:(RCTPromiseRejectBlock)reject)
395
+ RCT_EXTERN_METHOD(compress:(NSString*)url withOptions:(NSDictionary *)options
396
+ withResolver:(RCTPromiseResolveBlock)resolve
397
+ withRejecter:(RCTPromiseRejectBlock)reject)
398
+ RCT_EXTERN_METHOD(toGif:(NSString*)url withOptions:(NSDictionary *)options
399
+ withResolver:(RCTPromiseResolveBlock)resolve
400
+ withRejecter:(RCTPromiseRejectBlock)reject)
401
+ RCT_EXTERN_METHOD(merge:(NSArray *)urls withOptions:(NSDictionary *)options
402
+ withResolver:(RCTPromiseResolveBlock)resolve
403
+ withRejecter:(RCTPromiseRejectBlock)reject)
404
+ RCT_EXTERN_METHOD(saveToPhoto:(NSString*)filePath withResolver:(RCTPromiseResolveBlock)resolve
405
+ withRejecter:(RCTPromiseRejectBlock)reject)
406
+ RCT_EXTERN_METHOD(saveToDocuments:(NSString*)filePath withResolver:(RCTPromiseResolveBlock)resolve
407
+ withRejecter:(RCTPromiseRejectBlock)reject)
408
+ RCT_EXTERN_METHOD(share:(NSString*)filePath withResolver:(RCTPromiseResolveBlock)resolve
409
+ withRejecter:(RCTPromiseRejectBlock)reject)
256
410
  @end
257
411
 
258
412
  #endif