Это действительно быстрый вопрос :)
Просто интересно, возможно ли для javascript выбирать объекты, которые не являются частью DOM ... например, выбирая : после
или : перед
контент, созданный с помощью CSS?
например ... > character_test ()
Я знаю, что у AV Foundation есть возможность объединять или рекомбинировать видео, а также добавлять звуковую дорожку, создавая единый объект видео.
Теперь ... моя цель немного другая. Хотелось бы создать видео с нуля. У меня есть набор UIImage, и мне нужно отобразить их все в одном видео. Я прочитал всю документацию Apple об AV Foundation и нашел класс AVVideoCompositionCoreAnimationTool, у которого есть возможность взять CoreAnimation и перекодировать его как видео. Я также проверил проект AVEditDemo, предоставленный Apple, но, похоже, что-то не работает с моим проектом.
Вот мои шаги:
1) Я создаю слой CoreAnimation
CALayer *animationLayer = [CALayer layer];
[animationLayer setFrame:CGRectMake(0, 0, 1024, 768)];
CALayer *backgroundLayer = [CALayer layer];
[backgroundLayer setFrame:animationLayer.frame];
[backgroundLayer setBackgroundColor:[UIColor blackColor].CGColor];
CALayer *anImageLayer = [CALayer layer];
[anImageLayer setFrame:animationLayer.frame];
CAKeyframeAnimation *changeImageAnimation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
[changeImageAnimation setDelegate:self];
changeImageAnimation.duration = [[albumSettings transitionTime] floatValue] * [uiImagesArray count];
changeImageAnimation.repeatCount = 1;
changeImageAnimation.values = [NSArray arrayWithArray:uiImagesArray];
changeImageAnimation.removedOnCompletion = YES;
[anImageLayer addAnimation:changeImageAnimation forKey:nil];
[animationLayer addSublayer:anImageLayer];
2) Затем я создаю экземпляр AVComposition
AVMutableComposition *composition = [AVMutableComposition composition];
composition.naturalSize = CGSizeMake(1024, 768);
CALayer *wrapLayer = [CALayer layer];
wrapLayer.frame = CGRectMake(0, 0, 1024, 768);
CALayer *videoLayer = [CALayer layer];
videoLayer.frame = CGRectMake(0, 0, 1024, 768);
[wrapLayer addSublayer:animationLayer];
[wrapLayer addSublayer:videoLayer];
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
AVMutableVideoCompositionInstruction *videoCompositionInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
videoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMake([imagesFilePath count] * [[albumSettings transitionTime] intValue] * 25, 25));
AVMutableVideoCompositionLayerInstruction *layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstruction];
videoCompositionInstruction.layerInstructions = [NSArray arrayWithObject:layerInstruction];
videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:wrapLayer];
videoComposition.frameDuration = CMTimeMake(1, 25); // 25 fps
videoComposition.renderSize = CGSizeMake(1024, 768);
videoComposition.instructions = [NSArray arrayWithObject:videoCompositionInstruction];
3) Я экспортирую видео по пути к документу
AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetLowQuality];
session.videoComposition = videoComposition;
NSString *filePath = nil;
filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
filePath = [filePath stringByAppendingPathComponent:@"Output.mov"];
session.outputURL = [NSURL fileURLWithPath:filePath];
session.outputFileType = AVFileTypeQuickTimeMovie;
[session exportAsynchronouslyWithCompletionHandler:^
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Export Finished: %@", session.error);
if (session.error) {
[[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL];
}
});
}];
В момент экспорта получаю эту ошибку:
Экспорт завершен: Error Domain = AVFoundationErrorDomain Code = -11822 «Невозможно открыть» UserInfo = 0x49a97c0 {NSLocalizedFailureReason = Этот формат мультимедиа не поддерживается., NSLocalizedDescription = Cannot Open}
Я нашел это в документации: AVErrorInvalidSourceMedia = -11822,
AVErrorInvalidSourceMedia Операция не может быть завершена, потому что некоторые исходные носители не могут быть прочитаны.
Я полностью уверен, что моя сборка CoreAnimation правильная, потому что я отрендерил ее в тестовом слое и смог правильно увидеть ход анимации.
Кто-нибудь может помочь мне понять, в чем моя ошибка?