Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAssetExport fails for some files

I have tried to export audio file from the iPod-Library. My objective is to create new file in app Document folder with this iPod-Library file .Its fails to create files for some items only . Below is my code snippet.

AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL: url options:nil];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

AVAssetExportSession *exporter = [[AVAssetExportSession alloc]
                                  initWithAsset: songAsset
                                  presetName: AVAssetExportPresetAppleM4A];

exporter.outputFileType = @"com.apple.m4a-audio";

NSString *songName  =   [filename stringByAppendingString:@".m4a"];

NSString *musicfilepath  = [documentsDirectory stringByAppendingPathComponent:@"musics/"];

[[NSFileManager defaultManager] createDirectoryAtPath:musicfilepath withIntermediateDirectories:YES attributes:nil error:nil];

NSString *exportFile = [musicfilepath stringByAppendingPathComponent:songName];



NSError *error1;

if([[NSFileManager defaultManager] fileExistsAtPath:exportFile]) 
{

    [[NSFileManager defaultManager] removeItemAtPath:exportFile error:&error1];

}

NSURL* exportURL = [[NSURL fileURLWithPath:exportFile] retain];

exporter.outputURL = exportURL; 

Am getting Error as shown below when tried with the error handler block :

    [exporter exportAsynchronouslyWithCompletionHandler:^{

    int exportStatus = exporter.status;

    switch (exportStatus) {

        case AVAssetExportSessionStatusFailed: {

            NSError *exportError = exporter.error;

            NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);

            break;
        }
  }
 }];

AVAssetExportSessionStatusFailed: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x214f20 {NSLocalizedFailureReason=An unknown error occurred (-12124), NSUnderlyingError=0x218270 "The operation couldn’t be completed. (OSStatus error -12124.)", NSLocalizedDescription=The operation could not be completed}

like image 404
Kannan Prasad Avatar asked Jul 03 '12 09:07

Kannan Prasad


1 Answers

Having played a lot with this myself, some of the answers may be relevant and correct. One other thing to watch out for is that I often used to get similar AVFoundation errors if trying to combine videos that had different frame-rates. Check the source files frame rate and check your CMTime's too. You may have to pre-process some files before adding them into a AVMutableComposition.

like image 96
mike.kz Avatar answered Nov 14 '22 08:11

mike.kz