AVExportSession工作在模拟器,iPad 2的而不是iPad的4

问题描述:

更新:奇怪的是这个代码工作正常在iPad 2,但没有一个iPad 4日创AVExportSession工作在模拟器,iPad 2的而不是iPad的4

更新#2:如果我改变presetName:AVAssetExportPresetHighestQualitypresetName:AVAssetExportPresetPassThrough视频成功出口但我无法在设备中播放它。如果我通过xCode的组织者将应用程序包关闭到我的电脑,我可以播放它。再次,这个问题只发生在iPad 4上,而不是iPad 2,64位模拟器,视网膜模拟器或1x模拟器。

我正在使用AVExportSession混合一些音频和视频。它在模拟器和iPad 2上运行相当愉快,但不是iPad第4代。导出会话出现-11820错误(AVErrorExportFailed),但这是我能够从流程中获得的有用信息的范围。源文件存在,其他所有内容都在流畅地运行,但不是AVExportSession

你能帮助我在设备上工作吗?

道歉的方法的详细程度。

-(NSURL*)bindAudioAndVideo:(NSString*)audioFileName videoFileName:(NSString*)videoFileName 
{ 

    //documents folder 
    NSArray  *paths    = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsFolder  = [[NSString alloc] initWithString:[paths objectAtIndex:0]]; //Get the docs directory 

    AVMutableComposition* mixComposition = [AVMutableComposition composition]; 

    NSString* audio_inputFileName = audioFileName; 
    NSString* audio_inputFilePath = [documentsFolder stringByAppendingPathComponent:audio_inputFileName]; 
    NSURL* audio_inputFileUrl = [NSURL fileURLWithPath:audio_inputFilePath]; 

    NSString* video_inputFileName = videoFileName; 
    NSString* video_inputFilePath = [documentsFolder stringByAppendingPathComponent:video_inputFileName]; 
    NSURL* video_inputFileUrl = [NSURL fileURLWithPath:video_inputFilePath]; 

    NSString* outputFileName  = @"outputFile.mp4"; 
    NSString* outputFilePath  = [documentsFolder stringByAppendingPathComponent:outputFileName]; 
    NSURL* outputFileUrl   = [NSURL fileURLWithPath:outputFilePath]; 

    //Check files actually exist before beginning (they do) 

    AVMutableComposition* mixComposition = [AVMutableComposition composition]; 
    CMTime nextClipStartTime = kCMTimeZero; 

    AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:video_inputFileUrl options:nil]; 
    CMTimeRange video_timeRange = CMTimeRangeMake(kCMTimeZero,videoAsset.duration); 
    AVMutableCompositionTrack *a_compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 
    [a_compositionVideoTrack insertTimeRange:video_timeRange ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:nextClipStartTime error:nil]; 


    AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audio_inputFileUrl options:nil]; 
    CMTimeRange audio_timeRange = CMTimeRangeMake(kCMTimeZero, audioAsset.duration); 
    AVMutableCompositionTrack *b_compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; 
    [b_compositionAudioTrack insertTimeRange:audio_timeRange ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:nextClipStartTime error:nil]; 



    AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality]; 
    _assetExport.outputFileType = @"com.apple.quicktime-movie"; 
    _assetExport.outputURL = outputFileUrl; 

    [_assetExport exportAsynchronouslyWithCompletionHandler: 
    ^(void) { 
     [self addSkipBackupAttributeToItemAtURL:outputFileUrl]; 
     NSLog(@"Completed. Tidy time."); 

     switch ([_assetExport status]) { 
      case AVAssetExportSessionStatusCompleted: 
       NSLog(@"Export Completed"); 
       break; 
      case AVAssetExportSessionStatusFailed: 
       NSLog(@"Export failed: %@", [[_assetExport error] localizedDescription]); 
       NSLog (@"FAIL %@",_assetExport.error); //-11820! I AM A USELESS ERROR CODE 
       NSLog (@"supportedFileTypes: %@", _assetExport.supportedFileTypes); 
       break; 
      case AVAssetExportSessionStatusCancelled: 
       NSLog(@"Export cancelled"); 
       break; 
      default: 
       break; 
     } 


      NSTimer *refreshTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(exportCompleteRefreshView) userInfo:Nil repeats:NO]; 

     //Throw back to main thread unuless you want really long delays for no reason. 
     [[NSRunLoop mainRunLoop] addTimer:refreshTimer forMode:NSRunLoopCommonModes]; 
    } 
    ]; 



    return outputFileUrl; 
} 
+0

为什么你不使用常量作为文件类型?而t =你如何构建你的outputFileURL。在模拟器/设备中,我发现许多问题是由于URL。 – Linuxios

+0

我已经添加了如何构建路径。 outputFileURL在导出后存在,但它是'零KB'。不知道为什么我不使用常量作为文件类型,我该怎么做才能改变它? – glenstorey

+0

源视频和音频文件的格式是什么? – ChrisH

如果问题与视网膜iPad连接 - 这与设备分辨率有关,由于某种原因,模拟器没有模拟。

由于我是在设备上创建视频,我在视网膜设备上制作了2048x1536视频(而在非视网膜设备上是1024x768)。显然这只是AVExportSession处理的像素太多,或者iPad可以正常播放,所以它只是在播放或导出时向我发送了各种模糊的错误信息。在点分辨率而不是像素分辨率下录制似乎解决了问题。

该模拟器似乎是一个红色的鲱鱼,因为它拥有一个健康的mac相对无限的资源,而不是A6。