Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Videos shot from android phones get ruined after editing with AVFoundation iOS

I am working on an app that requires editing videos(setting overlays).Now,while the videos shot from iPhones are edited fine,the ones shot from android phones are getting blank after editing.

I can't imagine what the problem could be.I would appreciate an immediate help.

This is one of the methods(Trim functionality).

- (IBAction)cutButtonTapped:(id)sender {

    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = @"Encoding...";

    [self.playButton setBackgroundImage:[UIImage imageNamed:@"video_pause.png"] forState:UIControlStateNormal];



    NSString *uniqueString = [[NSProcessInfo processInfo]globallyUniqueString];

//do this to export video
    NSURL *videoFileUrl = [NSURL fileURLWithPath:[AppHelper userDefaultsForKey:@"videoURL"]];

    AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoFileUrl options:nil];
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];

    if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality]) {

        self.exportSession_ = [[AVAssetExportSession alloc]
                           initWithAsset:anAsset presetName:AVAssetExportPresetPassthrough];
    // Implementation continues.

   //        NSURL *furl = [self newURLWithName:[uniqueString stringByAppendingString:@".mov"]];
          NSURL *furl = [self newURLWithName:[uniqueString stringByAppendingString:[NSString stringWithFormat:@".%@",[videoFileUrl pathExtension]]]];

    self.exportSession_.outputURL = furl;
    self.exportSession_.outputFileType = AVFileTypeMPEG4;

    CMTime start = CMTimeMakeWithSeconds(self.startTime, anAsset.duration.timescale);
    CMTime duration = CMTimeMakeWithSeconds(self.stopTime-self.startTime, anAsset.duration.timescale);
    CMTimeRange range = CMTimeRangeMake(start, duration);
    CMTimeShow( self.exportSession_.timeRange.duration);
    self.exportSession_.timeRange = range;
    CMTimeShow( self.exportSession_.timeRange.duration);

    [self.exportSession_ exportAsynchronouslyWithCompletionHandler:^{

        switch ([self.exportSession_ status]) {
            case AVAssetExportSessionStatusFailed:
                NSLog(@"Export failed: %@", [[self.exportSession_ error] localizedDescription]);
                break;
            case AVAssetExportSessionStatusCancelled:
                NSLog(@"Export canceled");
                break;
            default:
                NSLog(@"NONE");
                dispatch_async(dispatch_get_main_queue(), ^{

//                            [self playDocumentDirectoryVideoWithURLString:[uniqueString stringByAppendingString:@".mov"]];
                        [self playDocumentDirectoryVideoWithURLString:[uniqueString stringByAppendingString:[NSString stringWithFormat:@".%@",[videoFileUrl pathExtension]]]];

                });
        }
    }];
}

}

Could anyone please help me with this?

like image 602
Reckoner Avatar asked Jul 08 '16 05:07

Reckoner


People also ask

How can I send a video from my iPhone to my Samsung without losing quality?

Step 1: Open Google Drive official website > log in with your Google account on your iPhone. Step 2: Enter "Drive" > choose "My Drive" > opt for "Upload files" or "Upload folder" to upload iPhone videos to Google Drive. Step 3: Select video files you wanna send to Android under My Drive after the uploading is over.

Why do Android pictures look bad when sent to iPhone?

It has to do with compression. Apple handles the iPhone-to-iPhone delivery of texted videos, so no matter the size, videos are sent and received in their original quality. However, that's not the case when not using Apple's system from start to finish—your carrier gets in the way, and that's when things break down.

How do I watch iPhone videos on my Android?

As we know, iPhone videos' default format is MOV, which cannot be supported by Android. If you want to play iPhone videos on Android without extra apps or codecs installed, you need to convert MOV to common formats such as MP4, AVI, MKV, etc. with an iPhone to Android video converter.


1 Answers

First of all, I recommend you to check duration & range values. It seems like an issue with CMTime and decoding. And second, try to initialise your AVURLAsset with an option to force duration extraction:

AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoFileUrl options:@{AVURLAssetPreferPreciseDurationAndTimingKey: @(YES)}];
like image 179
dive Avatar answered Nov 08 '22 15:11

dive