Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

iOS copying/saving video using AVAssetExportSession and writeVideoAtPathToSavedPhotosAlbum

Posted on 2013-11-13
2
Medium Priority
?
6,551 Views
Last Modified: 2013-11-14
I have some simple code that takes a video from the photo album and makes a copy of it.
The original video was created using the camera on the device (iPod Touch 5th Gen).

The code uses AVAssetExportSession to make a temporary copy of the video and then uses
writeVideoAtPathToSavedPhotosAlbum to save the copy back to the album.

The code works fine and makes a perfect copy except for the file type.

I am setting the OutputFileType as AVFileTypeMPEG4 and giving the temp file a name with a .mp4 extension, but the copy always ends up getting a new name with a .MOV extension.

Is that normal behavior for the writeVideoAtPathToSavedPhotosAlbum?

Here is the chunk of code that does the copying/saving -

asset = [AVURLAsset assetWithURL: [representation url]];
    NSURL *outputURL;
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset];
    if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]) {
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
                                               initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
        // Implementation continues.
        _success = false;
        NSString *filePath = nil;
        filePath = NSTemporaryDirectory();
            filePath = [filePath stringByAppendingPathComponent:@"test128"];
            filePath = [filePath stringByAppendingPathExtension:@".mp4"];
       
        outputURL = [NSURL fileURLWithPath:filePath];
        exportSession.outputURL = outputURL;
        exportSession.outputFileType = AVFileTypeMPEG4;
       
        [exportSession exportAsynchronouslyWithCompletionHandler:^{
           
            switch ([exportSession status]) {
                case AVAssetExportSessionStatusCompleted:
                    _success = true;
                    NSLog(@"Export Completed");
                    break;
                case AVAssetExportSessionStatusWaiting:
                    NSLog(@"Export Waiting");
                    break;
                case AVAssetExportSessionStatusExporting:
                    NSLog(@"Export Exporting");
                    break;
                case AVAssetExportSessionStatusFailed:
                {
                    NSError *error = [exportSession error];
                    NSLog(@"Export failed: %@", [error localizedDescription]);
                   
                    break;
                }
                case AVAssetExportSessionStatusCancelled:
                    NSLog(@"Export canceled");
                   
                    break;
                default:
                    break;
            }
           
            if (_success == true) {
               
                ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
                [assetLibrary writeVideoAtPathToSavedPhotosAlbum:outputURL completionBlock:^(NSURL *assetURL, NSError *error){
                    NSError *removeError = nil;
                    [[NSFileManager defaultManager] removeItemAtURL:outputURL error:&removeError];
                }];
               
            }
        }];
0
Comment
Question by:kevinvw1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
EZFrag earned 2000 total points
ID: 39647325
Hi There,

Yes, It seems to be the norm. Some people are complaining that the process of copying a movie file also takes a while. But I believe that it is Apple converting the video to the mov format before saving it to the media folder.

If this is the case, it might be better to set the output file type to mov from the beginning, and save some processing time.

I might be wrong, I might be right. But this is my take on it.

Kind Regards,
EZFrag
0
 

Author Closing Comment

by:kevinvw1
ID: 39648044
Excellent, thanks for the confirmation.  

My clips are all super small (less than 5 seconds) so conversion time so far is negligible.

Thanks!

Kevin.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you having trouble connecting or getting your iPhone / Samsung device(s) to sync with Microsoft Exchange Server?   What have you tried?   What haven't you tried?
After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question