Error al extraer audio del file de video .m4v

Estoy intentando extraer el file de audio del video .m4v. Muestra el error como,

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x15e350d0 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x15d1c6b0 "The operation couldn't be completed. (OSStatus error -12124.)", NSLocalizedFailureReason=An unknown error occurnetworking (-12124)} 

Este es mi código:

 -(void)extractAudioFromVideo{ //Create a audia composition and add audio track AVMutableComposition *newAudioAsset = [AVMutableComposition composition]; AVMutableCompositionTrack *dstCompositionTrack = [newAudioAsset addMutableTrackWithMediaType:AVMediaTypeAudio prefernetworkingTrackID:kCMPersistentTrackID_Invalid]; //Get video asset from which the audio should be extracted NSURL *url = [[NSBundle mainBundle] URLForResource:@"sample_iPod" withExtension:@"m4v"]; AVAsset *srcAsset = [AVAsset assetWithURL:url]; NSArray *trackArray = [srcAsset tracksWithMediaType:AVMediaTypeAudio]; if(!trackArray.count){ NSLog(@"Track returns empty array for mediatype AVMediaTypeAudio"); return; } AVAssetTrack *srcAssetTrack = [trackArray objectAtIndex:0]; //Extract time range CMTimeRange timeRange = srcAssetTrack.timeRange; //Insert audio from the video to mutable avcomposition track NSError *err = nil; if(NO == [dstCompositionTrack insertTimeRange:timeRange ofTrack:srcAssetTrack atTime:kCMTimeZero error:&err]){ NSLog(@"Failed to insert audio from the video to mutable avcomposition track"); return; } //Export the avcompostion track to destination path NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0]; NSString *dstPath = [documentsDirectory stringByAppendingString:@"sample_audio.mp4"]; NSURL *dstURL = [NSURL fileURLWithPath:dstPath]; //Remove if any file already exists [[NSFileManager defaultManager] removeItemAtURL:dstURL error:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:newAudioAsset presetName:AVAssetExportPresetPassthrough]; NSLog(@"support file types= %@", [exportSession supportedFileTypes]); exportSession.outputFileType = @"public.mpeg-4"; exportSession.outputURL = dstURL; [exportSession exportAsynchronouslyWithCompletionHandler:^{ AVAssetExportSessionStatus status = exportSession.status; if(AVAssetExportSessionStatusCompleted != status){ NSLog(@"Export status not yet completed. Error: %@", exportSession.error.description); } }]; } 

¿Cómo puedo resolver este error?

He probado tu código en el simulador. Está funcionando bien en el simulador (IOS7). Pero cuando ejecuto en iPodTouch-5, muestra un error similar a lo que has mencionado. Dedique más de 15 minutos, error encontrado y tonto.

Obtención de la ruta como se muestra a continuación ( Documentssample_audio.mp4 ) cuando ejecuto en el Dispositivo ..

 @"file:///var/mobile/Applications/A1E1D85F-0198-4A0C-80F8-222F0DA1C31A/Documentssample_audio.mp4" 

así que he modificado la ruta como …

 NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0]; NSString *dstPath = [documentsDirectory stringByAppendingString:@"/sample_audio.mp4"]; 

Ahora obtengo la ruta como se muestra a continuación ( /Documents/sample_audio.mp4 ) y funciona bien. Pero no sé, cómo sucedió

 @"file:///var/mobile/Applications/A1E1D85F-0198-4A0C-80F8-222F0DA1C31A/Documents/sample_audio.mp4"