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?
startTime
andstopTime
? Probably not the problem, but it would be nice if you usedcase AVAssetExportSessionStatusCompleted:
instead ofdefault:
. – Saguache