White video when opening AVMutableComposition in Instagram
Asked Answered
L

1

6

After I export an AVMutableComposition I use PHPhotoLibrary to save the video to the camera roll. In the creationRequestForAssetFromVideoAtFileURL: completion handler, I then open the saved video in Instagram, like so:

__block PHObjectPlaceholder *videoAssetPlaceholder;

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    PHAssetChangeRequest *req = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:localVideoURL];
    videoAssetPlaceholder = req.placeholderForCreatedAsset;
} completionHandler:^(BOOL success, NSError *error) {
    if (success) {
        completion(YES);
        NSString *localID = videoAssetPlaceholder.localIdentifier;
        NSRange rangeOfSlash = [localID rangeOfString:@"/"];
        if (rangeOfSlash.location != NSNotFound) {
            NSString *assetID = [localID substringToIndex:rangeOfSlash.location];
            NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@", assetID]];
            if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
                [[UIApplication sharedApplication] openURL:instagramURL];
            }
        }
    }
}];

About 50% of the times Instagram opens and the video plays like expected. The other 50% of the times, however, both the video and the preview is white, and all I get is the sound. This usually gets fixed by selecting another video and then going back to my video. The video plays perfectly in the camera roll, it's only Instagram that causes problems. Is this an issue that Instagram has or could I be exporting my videos the wrong way?

These are my AVAssetExportSession settings:

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition
                                                                  presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL = url;
exporter.outputFileType = AVFileTypeMPEG4;
exporter.shouldOptimizeForNetworkUse = YES;
exporter.videoComposition = mainCompositionInst;
[exporter exportAsynchronouslyWithCompletionHandler:^{
    dispatch_async(dispatch_get_main_queue(), ^{
        handler(exporter.outputURL);
    });
}];
Lanfri answered 2/9, 2016 at 21:3 Comment(7)
Daniel, I think we're hunting the same whale. My QuestionPesach
Do you have a solution? I thought the AVAssetExportSession had to be active while I started playback but it even seems to happen after it has finished. Thought if you cancel it right away after it starts the problem does not seem to happen.Pesach
@AndresCanella I have not found a solution for this yet. Since I have only seen the problem when exporting to Instagram, I'm might reach out to them to see if this is a known bug or not. But yes, it definitely seems as though our questions are of the same origin.Lanfri
Appreciate it Daniel. Did this start with iOS10 for you as well?Pesach
I've evaded the iOS bug from my end by not using AVAssetExportSession after capturing, this might not be an option for you since you're using an API, unless perhaps you provide the exact format instagram wants?... I'm using AVCaptureSession with AVAssetWriter to do the image adjustments inline while capturing...Pesach
Thanks for the input. Yeah I need to use AVAssetExportSession since I'm using it to create a composition different from the original video.Lanfri
@DanielLarsson have you found a solution? I can't figure out a workaround that works perfectly.Leprosy
P
2

Just heard from Apple DTS. They also agree this points to an Apple iOS bug and asked me to log it.

I cut out usage of AVAssetExportSession like mentioned above and it solved my problem as a work around. So the issue seems to be around that method which is probably contained in the Instagram method you are using.

So until Apple fixes this or Instagram builds a work around, there does not seem to be a solution for this problem... Bummer

Pesach answered 21/9, 2016 at 0:28 Comment(1)
I see. Thanks for letting me know what DTS told you, hope that this will get resolved soon.Lanfri

© 2022 - 2024 — McMap. All rights reserved.