我已经了解了 obj-c GPUImage 框架,并且根据文档中的示例,我添加了以下代码片段以显示过滤后的实时视频:
CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];
GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
GPUImageFilter *customFilter = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"PositionColor"];
GPUImageView *filteredVideoView = [[GPUImageView alloc] initWithFrame:mainScreenFrame];
// Add the view somewhere so it's visible
[self.view addSubview:filteredVideoView];
[videoCamera addTarget:customFilter];
[customFilter addTarget:filteredVideoView];
[videoCamera startCameraCapture];
它有效,但我得到的不是视频,而是一张静止图像。我查看了它并查看了示例,但无法真正查明它无法正常工作的原因。任何帮助将不胜感激。
谢谢!
最佳答案
你需要在某个地方卡在你的 GPUImageVideoCamera 上。如果将上面的内容放在一个方法中,并且为项目启用了 ARC,则 GPUImageVideoCamera 实例将在该方法退出的那一刻被释放。这将终止视频捕获并可能导致其他令人不安的伪像。
改为在您的类中创建一个 GPUImageVideoCamera 实例变量,并将其用于上述操作。您还需要它,以便在完成后可以暂停和停止相机。
关于objective-c - GPUImage 显示图像而不是实时视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21999138/