Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

White video when opening AVMutableComposition in Instagram

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);
    });
}];
like image 347
Daniel Larsson Avatar asked Sep 02 '16 21:09

Daniel Larsson


1 Answers

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

like image 186
Andres Canella Avatar answered Nov 17 '22 13:11

Andres Canella