I am storing video files on a web server that are taken with the stock iOS video recorder within UIImagePickerController. Before sending the video to the server I convert it from MOV to MP4 with the following code:
AVAsset *avAsset = [AVAsset assetWithURL:info[UIImagePickerControllerMediaURL]];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
exporter.outputFileType = AVFileTypeMPEG4;
exporter.shouldOptimizeForNetworkUse = YES;
exporter.outputURL = [NSURL fileURLWithPath:[self getVideoPath]];
[exporter exportAsynchronouslyWithCompletionHandler:^{
switch (exporter.status)
{
case AVAssetExportSessionStatusFailed:
NSLog(@"Video conversion Failed: %@",exporter.error);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"video conversion canceled");
break;
case AVAssetExportSessionStatusExporting:
NSLog(@"video conversion exporting");
break;
case AVAssetExportSessionStatusWaiting:
NSLog(@"video conversion is waiting");
break;
case AVAssetExportSessionStatusUnknown:
NSLog(@"video converstion status unknown");
break;
case AVAssetExportSessionStatusCompleted:
self.outputFileURL = exporter.outputURL;
break;
}
}];
I have verified with the switch statement above that the conversion is hitting the AVAssetExportSessionStatusCompleted
state. However, when I look at the video on the server side it is flipped upside down. This occurs regardless of iPad/iPhone or whether the video was taken in landscape or portrait modes. When I download the file from the web server into the app, it does play correctly and with the correct orientation so this only happens outside of iOS. Of note, if I don't covert the file but instead leave it as a MOV file, it maintains the correct orientation outside the app but of course it has to use Quicktime to view it.
Why is this conversion process causing the video to be rendered upside down and how can I fix this?