0

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?

C6Silver
  • 3,127
  • 2
  • 21
  • 49

1 Answers1

0

The exporter just isn't respecting the transform. Rotate it.

how to export video asset via AVAssetExportSession in portrait mode

This may also help.

http://www.padamthapa.com/video-rotation-issue-merge/

Community
  • 1
  • 1
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
  • Thanks for the links. One thing that is confusing me is with the final file. Are you supposed to export the video twice, once before the transform and then again after? I can apply the transform to the video but if I use export to get to a file the same problem happens. It seems you apply the tranform after using the export session but then how do you get those changes saved back to video without using the exporter? – C6Silver Apr 15 '15 at 18:45