Я пытаюсь экспортировать аудио из видеофайла 3gpp, и он не работает ... Кто-нибудь знает, что я могу делать неправильно? Вот код, который я использую:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"newFile.m4a"];
NSString *tempFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"oldFile.3gp"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:tempFilePath] options:nil];
[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler:^ {
//HERE IS THE PROBLEM. THE ARRAY OF TRACKS IS EMPTY FOR SOME REASON.
AVAssetTrack* audioTrack = [[asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
AVMutableComposition* audioComposition = [AVMutableComposition composition];
AVMutableCompositionTrack* audioCompositionTrack = [audioComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
[audioCompositionTrack insertTimeRange:[audioTrack timeRange] ofTrack:audioTrack atTime:CMTimeMake(0, 1) error:nil];
AVAssetExportSession *exprortSession = [AVAssetExportSession exportSessionWithAsset:audioComposition presetName:AVAssetExportPresetAppleM4A];
NSURL *toFileURL = [NSURL URLWithString:filePath];
exprortSession.outputURL = toFileURL;
exprortSession.outputFileType = @"com.apple.m4a-audio";
NSLog(@"exportAsynchronouslyWithCompletionHandler will start");
[exprortSession exportAsynchronouslyWithCompletionHandler: ^(void) {
if (exprortSession.status == AVAssetExportSessionStatusCompleted) {
NSLog(@"Export success");
}
else {
NSLog(@"Export failed");
}
}];
}];