4
Я работаю над приложением, в котором я сочиняю видео и экспортирую в каталог. Он отлично работает в прошивке 7, но не в прошивке 8.AVVideoComposition не работает в iOS 8
Ниже мой код:
AVAsset *pVideoTrack = [AVAsset assetWithURL:[NSURL fileURLWithPath:assetPath]];
AVVideoComposition *origionalComposition = [AVVideoComposition videoCompositionWithPropertiesOfAsset:pVideoTrack];
AVAssetTrack *clipVideoTrack = [[pVideoTrack tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVMutableComposition* mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, pVideoTrack.duration)
ofTrack:clipVideoTrack
atTime:kCMTimeZero error:nil];
[compositionVideoTrack setPreferredTransform:[[[pVideoTrack tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]];
BOOL bIsPotrait = [self checkVideoOrientationProperty:[[pVideoTrack tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]];
CGSize videoSize = CGSizeMake(0, 0);
if(bIsPotrait)
videoSize = CGSizeMake([[[pVideoTrack tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] naturalSize].height, [[[pVideoTrack tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] naturalSize].width);
else
videoSize = [[[pVideoTrack tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] naturalSize];
AVMutableVideoComposition* videoComp = [AVMutableVideoComposition videoComposition];
videoComp.renderSize = videoSize;
AVAssetTrack *videoTrack = [[mixComposition tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVMutableVideoCompositionLayerInstruction* layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];
[layerInstruction setTransform:clipVideoTrack.preferredTransform atTime:kCMTimeZero];
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.layerInstructions = [NSArray arrayWithObject:layerInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, [mixComposition duration]);
videoComp.instructions = [NSArray arrayWithObject: instruction];
videoComp.frameDuration = origionalComposition.frameDuration;
videoComp.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:animatedWaterMarkLayer];
_assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];
_assetExport.videoComposition = videoComp;
NSString *CasheDirectory = [UICommonMethods GetLibraryCacheDirectoryPath];
NSString *outputPath = [CasheDirectory stringByAppendingPathComponent:kWatermarkVideoName];
NSURL *exportUrl = [NSURL fileURLWithPath:outputPath];
if ([[NSFileManager defaultManager] fileExistsAtPath:outputPath])
[[NSFileManager defaultManager] removeItemAtPath:outputPath error:nil];
_assetExport.outputFileType = AVFileTypeQuickTimeMovie;
_assetExport.outputURL = exportUrl;
_assetExport.shouldOptimizeForNetworkUse = NO;
[_assetExport exportAsynchronouslyWithCompletionHandler:^
{
dispatch_async(dispatch_get_main_queue(), ^{
switch ([_assetExport status]) {
case AVAssetExportSessionStatusExporting:
NSLog(@"Export in progress ");
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed (%d): %@", [[_assetExport error] code], [[_assetExport error] localizedFailureReason]);
[_assetExport cancelExport];
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"Export done");
NSLog (@"finished writing %f", [dtStartDate timeIntervalSinceNow]);
break;
case AVAssetExportSessionStatusWaiting:
NSLog (@"AVAssetExportSessionStatusWaiting");
break;
case AVAssetExportSessionStatusUnknown:
NSLog (@"AVAssetExportSessionStatusUnknown");
break;
}
});
}];
Это дает «Данные средства массовой информации не может быть расшифровано Это может быть повреждено.». Ошибка во время работы на прошивке 8.
Я не читать ваш код, но наше приложение действительно делает композицию и она отлично работает под iOS8. Я знаю, это вам не очень помогает, но, по крайней мере, вы знаете, что это не ошибка. –
@PaulCezanne: можете ли вы выслать код композиции – AltafBangash
Наверное, нет. Это огромное количество кода, а также проприетарный. Если я могу извлечь безопасный фрагмент, я это сделаю. Но сейчас я сомневаюсь. –