[英]AVExportSession works on Simulator, iPad 2 but not iPad 4
更新:奇怪的是,此代碼在iPad 2上運行良好,但在iPad 4th Gen上卻無法運行。
更新#2:如果我將視頻成功導出,但將我的presetName:AVAssetExportPresetPassThrough
presetName:AVAssetExportPresetHighestQuality
更改為presetName:AVAssetExportPresetHighestQuality
presetName:AVAssetExportPresetPassThrough
,但我無法在設備中播放該視頻。 如果我通過xCode的管理器將應用程序捆綁包拉到計算機上,則可以播放它。 同樣,僅在iPad 4,iPad 2、64位模擬器,視網膜模擬器或1x模擬器上不會出現此問題。
我正在使用AVExportSession
混合一些音頻和視頻。 它在模擬器和iPad 2上運行得很愉快,但在iPad 4th Gen上卻不行。導出會話會產生-11820
錯誤( AVErrorExportFailed
),但這是我可以從過程中得到的有用信息的范圍。 源文件存在,其他所有內容都可以正常運行,但AVExportSession
不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;
}
如果問題出在視網膜iPads上,則與設備分辨率有關,由於某種原因,模擬器無法進行模擬。
由於我是在設備上創建視頻的,因此我在視網膜設備上制作了2048x1536的視頻(在非視網膜設備上制作了1024x768)。 顯然, AVExportSession
無法處理太多像素,iPad也無法正常播放,因此它在播放或導出時向我拋出了各種模糊的錯誤消息。 以點分辨率而不是像素分辨率記錄似乎已解決了該問題。
該模擬器似乎是一條紅鯡魚,因為它擁有相當多的健康Mac可用資源,而不是A6。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.