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

1

9

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?

Orose answered 8/7, 2016 at 5:1 Comment(10)
There's something I don't understand : do you have a problem with your iOS app or do your have a problem with your Android app ? I mean, what I understand is that you have a problem with videos that have been shot by an Android phone when you want to edit these videos on an iPhone. But I think your problem is : your iOS app works well, your Android app doesn't.Jitter
In android app there is no such issue.FFMPEG library has been used there for the entire video editing process.But in iOS app,I have used AVFoundation to do all the video editing task(cut,speed,overlay,merging).It works well for videos taken from iPhone,but not for the videos taken from android.Orose
Could you show us your code ?Jitter
ya sure.just a minuteOrose
Your code looks fine at first glance. You say it works well with videos shot from an iPhone but not that well with videos shot from Android ? How do you get these videos ? What do they look like when you play them on an iPhone ? Can you give us every details you have about these videos ? ( resolution, device used to shoot them ... )Jitter
well its a social networking app and when a video gets posted(from android),I play that video post on my iPhone.It plays fine but supports none of the video editing functionalities.Some videos get blank and some others are not exported by AVExportSession.Orose
Let us continue this discussion in chat.Orose
Can anyone please answer this question?I still haven't found any solutionOrose
Can we see the types of startTime and stopTime? Probably not the problem, but it would be nice if you used case AVAssetExportSessionStatusCompleted: instead of default:.Saguache
@RhythmicFistman Ya that would be nice, but unfortunately that's not the problem here.I am bamboozled as to why only android videos are screwing up.What's the difference in iPhone videos and Android videos?What is that AVFoundation is not picking up?Orose
A
1

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)}];
Asiatic answered 22/11, 2016 at 21:23 Comment(5)
Still the same issue.Orose
Any chance, you can attach the video before processing and after?Asiatic
Yes I will attach that later today.But I guess I have found the problem.The problem is that when I try to adjust the instructionLayer to adjust the video orientation,I encounter this problem.But the question is:why only on android videos?Orose
Sorry for the delay.I was stuck in another problem.Will update within a couple of hours.Orose
Sorry I can't upload the image, but it gets black and the audio is still there.Orose

© 2022 - 2024 — McMap. All rights reserved.