Export Video from Application's Document to cameraRoll

158 views Asked by At

I Just want to export .mp4 file to CameraRoll

Here is my code.

self.videoPath=@"/var/mobile/Applications/AE75E729-7F10-478B-9DAF-E730EB4231D1/Documents/Videos/aa.mp4"; 
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:self.videoPath] options:nil];
        NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];

        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
        //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        exportSession.outputURL = [NSURL fileURLWithPath:self.videoPath];
        NSLog(@"videopath of your mp4 file = %@",self.videoPath);  // PATH OF YOUR .mp4 FILE
        exportSession.outputFileType = AVFileTypeMPEG4;

        //  CMTime start = CMTimeMakeWithSeconds(1.0, 600);
        //  CMTime duration = CMTimeMakeWithSeconds(3.0, 600);
        //  CMTimeRange range = CMTimeRangeMake(start, duration);
        //   exportSession.timeRange = range;
        //  UNCOMMENT ABOVE LINES FOR CROP VIDEO
        [exportSession exportAsynchronouslyWithCompletionHandler:^{

            switch ([exportSession status]) {

                case AVAssetExportSessionStatusFailed:
                    NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);

                    break;

                case AVAssetExportSessionStatusCancelled:

                    NSLog(@"Export canceled");

                    break;

                default:

                    break;

            }
            UISaveVideoAtPathToSavedPhotosAlbum(self.videoPath, self, nil, nil);
            [exportSession release];

        }];

    }

Export failed: Cannot Save;

0

There are 0 answers