ios保存GPUImagevideo

我使用GPUImage在video上添加了叠加层。 预览它看起来不错,但我怎么能写我的video文件? 我使用GPUMovieWriter,但我不能find这个文件,我甚至不知道它是否工作。 这是我的代码:

-(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 = [GPUImageiOSBlurFilter new]; filter.blurRadiusInPixels = 3.0; GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init]; blendFilter.mix = 1.0; NSDate *startTime = [NSDate date]; UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 240.0f, 320.0f)]; timeLabel.font = [UIFont systemFontOfSize:17.0f]; timeLabel.text = @"Time: 0.0 s"; timeLabel.textAlignment = UITextAlignmentCenter; timeLabel.backgroundColor = [UIColor clearColor]; timeLabel.textColor = [UIColor whiteColor]; [videoCamera addTarget:filter]; GPUImageView *filterView = (GPUImageView *)self.preview; filterView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill; NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"file.mov"]; 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; [filter addTarget:movieWriter]; uiElementInput = [[GPUImageUIElement alloc] initWithView:timeLabel]; [filter addTarget:blendFilter]; [uiElementInput addTarget:blendFilter]; [blendFilter addTarget:filterView]; __unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput; [filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){ timeLabel.text = [NSString stringWithFormat:@"Time: %fs", -[startTime timeIntervalSinceNow]]; [weakUIElementInput update]; }]; [videoCamera startCameraCapture]; } 

我怎样才能把我的电影写到AssetsLibrary?

我假设覆盖你的意思是你想用UIElement作为覆盖写video?

在这种情况下,你会想通过你的“blendFilter”而不是“filter”

删除这一行

 [filter addTarget:movieWriter]; 

并在初始化blendFilter之后添加它

 [blendFilter addTarget:movieWriter]; [blendFilter addTarget:filterView]; 

你的movieWriter的初始化似乎没问题,我唯一的区别是我使用“.m4v”作为video格式。 这是苹果的标准格式。

video应保存到应用程序主文件夹。 使用XCode中的“Orginizer”(“CMD + SHIFT + 2”)查看应用程序文件夹,video应该在“Documents”下。