[英]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.