Я использую GPUImage, чтобы показать некоторые наложения на записанное видео. На данный момент я показываю изображение в своем видео с помощью GPUImageAlphaBlendFilter, но теперь мне нужно показать это изображение с некоторой «всплывающей» анимацией. Я хочу сделать это, масштабируя это изображение от очень маленького до нормального размера, но моя проблема в том, что я действительно не знаю, как это сделать. Есть ли способ сделать анимацию во время записи видео? Ниже я прилагаю код, который у меня есть на данный момент:
-(void)setUpCameraWithPosition:(bool)switchToFrontCamera
{
if(videoCamera != nil)
{
[videoCamera stopCameraCapture];
}
if(switchToFrontCamera) {
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront];
}
else {
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
}
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
videoCamera.horizontallyMirrorFrontFacingCamera = NO;
videoCamera.horizontallyMirrorRearFacingCamera = NO;
filter = [GPUImageBrightnessFilter new];
filter.brightness = 0.0;
GPUImageTransformFilter *transitionFilter = [[GPUImageTransformFilter alloc] init];
CGAffineTransform trans = CGAffineTransformTranslate(CGAffineTransformIdentity, 0.0, 0.5);
[transitionFilter setAffineTransform:trans];
GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 1.0;
UIImage *img = [UIImage imageNamed:@"logo-background-medium-cropped.png"];
iv = [[UIImageView alloc] initWithImage:img];
iv.backgroundColor = [UIColor clearColor];
[videoCamera addTarget:filter];
GPUImageView *filterView = (GPUImageView *)self.preview;
filterView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
NSLog(@"%@",pathToMovie);
unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)];
movieWriter.encodingLiveVideo = YES;
movieWriter.shouldPassthroughAudio = YES;
uiElementInput = [[GPUImageUIElement alloc] initWithView:iv];
[filter addTarget:blendFilter atTextureLocation:0];
[uiElementInput addTarget:transitionFilter];
[transitionFilter addTarget:blendFilter atTextureLocation:1];
[blendFilter addTarget:filterView];
[blendFilter addTarget:movieWriter];
[videoCamera startCameraCapture];
__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;
[filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){
[weakUIElementInput update];
}];
}
-(IBAction)stopCameraTouchUp:(id)sender
{
if(recording)
{
saving = YES;
recording = NO;
dispatch_after(0, dispatch_get_main_queue(), ^(void) {
[filter removeTarget:movieWriter];
videoCamera.audioEncodingTarget = nil;
[movieWriter finishRecording];
NSLog(@"Movie completed");
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
NSLog(@"%@",path);
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:path] completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(@"Error %@", error);
} else {
NSLog(@"Success");
recordButton.hidden = NO;
[videoCamera stopCameraCapture];
[self.navigationController popViewControllerAnimated:YES];
}
}];
});
}
else if(!saving)
{
recording = NO;
[self.navigationController popViewControllerAnimated:YES];
}
}
- (IBAction)startRecordingTouchUp:(id)sender
{
__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;
[filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){
[weakUIElementInput update];
}];
dispatch_after(0.0, dispatch_get_main_queue(), ^(void) {
NSLog(@"Start recording");
recording = YES;
[movieWriter startRecording];
});
}