Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed on select Video - IOS 14 #1415

Closed
RZulfikri opened this issue Sep 26, 2020 · 38 comments
Closed

Failed on select Video - IOS 14 #1415

RZulfikri opened this issue Sep 26, 2020 · 38 comments

Comments

@RZulfikri
Copy link

RZulfikri commented Sep 26, 2020

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.35.0
  • react-native v0.63.2

Platform

Tell us to which platform this issue is related

  • iOS 14

Expected behaviour

Return video

Actual behaviour

Return error

Steps to reproduce

  1. Open picker

  2. Select video

  3. Return error

code:E_CANNOT_PROCESS_VIDEO
message:Cannot process video data
domain:RCTErrorDomain
userInfo:null

Attachments

When I'm trying to debug in xcode, exportSession always return status = 4 (AVAssetExportSessionStatusFailed), and the error look like this.

Video Export Failed: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x2826f6730 {Error Domain=NSOSStatusErrorDomain Code=-16979 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-16979), NSURL=file:///var/mobile/Media/PhotoData/Metadata/DCIM/102APPLE/IMG_2272.medium.MP4, NSLocalizedDescription=The operation could not be completed}

[Update]
I'm trying to select few files:

  1. file:///var/mobile/Media/PhotoData/Metadata/DCIM/102APPLE/IMG_2272.medium.MP4 (ERROR) // from whatsapp
  2. file:///var/mobile/Media/DCIM/100APPLE/IMG_0454.MOV (CORRECT) // save from instagram
  3. file:///var/mobile/Media/DCIM/102APPLE/IMG_2429.MOV (CORRECT) // save from camera
  4. file:///var/mobile/Media/PhotoData/Metadata/DCIM/102APPLE/IMG_2075.medium.MP4 (ERROR) // from whatsapp

Video with .MOV extension return success, but video with .MP4 return error.

Any idea why this issue exist and how to solve??

Love react-native-image-crop-picker? Please consider supporting our collective:
👉 https://opencollective.com/react-native-image-crop-picker/donate

@vrgimael
Copy link

Same here, iOS 14 is causing a lot of trouble

@chr-sk
Copy link

chr-sk commented Sep 27, 2020

Also experiencing the same issue with iOS 14 and iOS 14.2 beta.

@TONYYYYYYYYYYY
Copy link

It's related to downloading images from iCloud.

iOS devices can choose to store a compressed version of the video/images locally but have a full version in the iCloud. When you choose to upload a video, it first gets the full version from iCloud and then tries the upload it.

When I try to upload a video that was recently viewed on my phone (which means the full version is already downloaded), there’s no problem. The problem occurs when it needs to download from iCloud

@eliw00d
Copy link

eliw00d commented Oct 1, 2020

We are also experiencing this as of iOS 14.

@ZachMayry
Copy link

It does seem related to iCloud. I didn't realize I had Optimize Photos on until now

@jamesshaw49
Copy link

jamesshaw49 commented Oct 7, 2020

Also experiencing this issue on iOS14, but only on a physical device. On simulator iOS14, there are no issues. However, I am guessing that this is because on the simulator, the files are not stored in iCloud.

@snamstorm
Copy link

Anyone find a solution for this yet?

Also having this issue but for me it doesn't work on the simulator but does work on physical device

@jamesshaw49
Copy link

Anyone find a solution for this yet?

Also having this issue but for me it doesn't work on the simulator but does work on physical device

Doesn't seem so. They released another version, but it does not include a fix. @ivpusic do you guys have an update on this, it is fairly critical that we are able to select an older video which may be stored on iCloud.

@estevg
Copy link

estevg commented Nov 3, 2020

I tried with a video that was sent to me by whatsapp and I passed it to diaspositive and it doesn't work so I don't think it's a problem of iCloud

@midoalone
Copy link

I tried with a video that was sent to me by whatsapp and I passed it to diaspositive and it doesn't work so I don't think it's a problem of iCloud

I tried with a fresh captured video and it has been selected without issues, the problem is related to iCloud videos only, I am sure now

@banchichen
Copy link

The following code is work, for your reference:

- (void)requestVideoOutputPathWithAsset:(PHAsset *)asset presetName:(NSString *)presetName success:(void (^)(NSString *outputPath))success failure:(void (^)(NSString *errorMessage, NSError *error))failure {
    if (!presetName) {
        presetName = AVAssetExportPresetMediumQuality;
    }
    [[PHImageManager defaultManager] requestExportSessionForVideo:asset options:[self getVideoRequestOptions] exportPreset:presetName resultHandler:^(AVAssetExportSession *_Nullable exportSession, NSDictionary *_Nullable info) {
        NSString *outputPath = [self getVideoOutputPath];
        exportSession.outputURL = [NSURL fileURLWithPath:outputPath];
        exportSession.shouldOptimizeForNetworkUse = NO;
        exportSession.outputFileType = AVFileTypeMPEG4;
        [exportSession exportAsynchronouslyWithCompletionHandler:^{
            [self handleVideoExportResult:exportSession outputPath:outputPath success:success failure:failure];
        }];
    }];
}

- (void)handleVideoExportResult:(AVAssetExportSession *)session outputPath:(NSString *)outputPath success:(void (^)(NSString *outputPath))success failure:(void (^)(NSString *errorMessage, NSError *error))failure {
    dispatch_async(dispatch_get_main_queue(), ^{
        switch (session.status) {
            case AVAssetExportSessionStatusCompleted: {
                if (success) {
                    success(outputPath);
                }
            }  break;
            case AVAssetExportSessionStatusFailed: {
                if (failure) {
                    failure(@"AVAssetExportSessionStatusFailed", session.error);
                }
            }  break;
            case AVAssetExportSessionStatusCancelled: {
                if (failure) {
                    failure(@"AVAssetExportSessionStatusCancelled", nil);
                }
            }  break;
            default: break;
        }
    });
}

- (PHVideoRequestOptions *)getVideoRequestOptions {
    PHVideoRequestOptions* options = [[PHVideoRequestOptions alloc] init];
    options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
    options.networkAccessAllowed = YES;
    return options;
}

- (NSString *)getVideoOutputPath {
    NSDateFormatter *formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss-SSS"];
    NSString *outputPath = [NSHomeDirectory() stringByAppendingFormat:@"/tmp/video-%@-%d.mp4", [formater stringFromDate:[NSDate date]], arc4random_uniform(10000000)];
    return outputPath;
}

@luco
Copy link
Contributor

luco commented Dec 9, 2020

@banchichen Can you make a PR?

@luco
Copy link
Contributor

luco commented Dec 19, 2020

@banchichen Tried your code. Doesn't work either. I managed to find the error on the native side:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-17507), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x2801f2280 {Error Domain=NSOSStatusErrorDomain Code=-17507 "(null)"}}

@banchichen
Copy link

banchichen commented Dec 19, 2020

@vladpanov
Copy link

Has anyone been successful in trying @banchichen code suggestion? #1415 (comment)

@luco
Copy link
Contributor

luco commented Dec 28, 2020

@vladpanov Yes. Didn't work.

@reyanshmishra
Copy link

Not working for me as well, any help so far?

@anhkieet
Copy link

Same here, any ideas?

@anhkieet
Copy link

anhkieet commented Jan 12, 2021

I found the solution. Add this line to the getVideoAsset function

Screen Shot 2021-01-12 at 16 47 32

https://github.com/ivpusic/react-native-image-crop-picker/blob/master/ios/src/ImageCropPicker.m#L467

@superandrew213
Copy link
Contributor

@anhkieet can you create a PR? @luco have you tried @anhkieet solution?

@luco
Copy link
Contributor

luco commented Jan 19, 2021

@superandrew213 I'll give it a shot and let you know.

@luco
Copy link
Contributor

luco commented Jan 20, 2021

@superandrew213 It works! @anhkieet Thanks a lot!

I've opened a PR #1515.

@ivpusic Can you merge?

@ibilalnawaz
Copy link

I found the solution :
Just change "deliveryMode" to this.
options.deliveryMode = .highQualityFormat

@ivpusic
Copy link
Owner

ivpusic commented Jan 21, 2021

fix available in https://github.com/ivpusic/react-native-image-crop-picker/releases/tag/v0.35.3

@ivpusic ivpusic closed this as completed Jan 21, 2021
@eliw00d
Copy link

eliw00d commented Jan 21, 2021

Awesome! When can we expect this to hit npm?

@nmhoan76
Copy link

nmhoan76 commented Feb 9, 2021

Still issue for iCloud video. I use iOS 14.4 and version 0.35.3

@dandre-hound
Copy link

How come this was solved for video and not photo? I have the same issue with iCloud photos -- anyone else? I tried adding a similar fix as suggested above but I still have the same error:

- (void)qb_imagePickerController:
(QBImagePickerController *)imagePickerController
          didFinishPickingAssets:(NSArray *)assets {
    
    PHImageManager *manager = [PHImageManager defaultManager];
    PHImageRequestOptions* options = [[PHImageRequestOptions alloc] init];
    options.synchronous = NO;
    options.networkAccessAllowed = YES;
    options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; <-- ADDED

@cenaHara
Copy link

cenaHara commented Mar 2, 2021

Still issue for iCloud video. I use iOS 14.3 and version 0.36.0
hi @nmhoan76 any solution ?

@tufanlodos
Copy link
Contributor

macOS : You can make this node_modules change with sed -ie "s/options.networkAccessAllowed = YES;/options.networkAccessAllowed = YES; options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;/" node_modules/react-native-image-crop-picker/ios/src/ImageCropPicker.m;

@Great-hijack
Copy link

Still same issues for iCloud photos with version 0.36.0.
@tufanlodos any thought?

@guy-shahine
Copy link

guy-shahine commented Jul 1, 2021

@tufanlodos your suggestion creates a duplicate entry and adds the wrong deliveryMode in the video section (I ran the command once). Even after I fixed the duplicate part, the same issue happens with iCloud photos. The library freezes then crashes the app

@tufanlodos
Copy link
Contributor

@guy-shahine you need to run this sed command only once.
@Great-hijack my react-native version 0.62.0 and image-crop-picker version is 0.35.0

@guy-shahine
Copy link

@tufanlodos save an original copy of the file. run your command once, then use a file diff to view the changes, you'll notice that the deliveryMode=... will be added twice for getVideoAsset and for the imagePickerController because options.networkAccessAllowed = YES; is found at line 467 and line 530

@tufanlodos
Copy link
Contributor

@guy-shahine try remove node_modules folder and after clean install with npm or yarn, run sed command

@guy-shahine
Copy link

guy-shahine commented Aug 2, 2021

@tufanlodos I've tried many approaches. imageData is always nil for iCloud images and I see an error in the console [PhotoKit] Error: Missing cpl resource required for CPL download . I tried to search for a solution without any luck.

@russelRajitha
Copy link

Still have issue with apple m1. react native latest version.

rtt Error: Cannot process video data
    at Object.promiseMethodWrapper [as openPicker] (NativeModules.js:104)
    at openImageLibrary (uploader-menu.js:112)
    at onPress (uploader-menu.js:577)
    at Pressability._performTransitionSideEffects (Pressability.js:697)
    at Pressability._receiveSignal (Pressability.js:634)
    at onResponderRelease (Pressability.js:528)
    at Object.invokeGuardedCallbackProd (ReactNativeRenderer-dev.js:93)
    at invokeGuardedCallback (ReactNativeRenderer-dev.js:318)
    at invokeGuardedCallbackAndCatchFirstError (ReactNativeRenderer-dev.js:342)
    at executeDispatch (ReactNativeRenderer-dev.js:439)

Video request delivery mode is only applicable for current version requests

@TheWhiteUnicorn
Copy link

react-native version 0.63.4, image-crop-picker version 0.36.3
I've also had this issue with some videos on simulator. But on a real device it works fine.

@timok06
Copy link

timok06 commented Sep 16, 2022

I resolved this issue for videos with the following solution:
#1518 (comment)

Hope this helps someone.

@russelRajitha You can change options.version to PHVideoRequestOptionsVersionCurrent; in function - (void) getVideoAsset in ImageCropPicker.m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests