objective-c - GPUImage 显示图像而不是实时视频

标签 objective-c xcode ios7 gpuimage

我已经了解了 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/

相关文章:

iphone - 我如何将 NSData 转换为 const uint8_t?或者在通过 Wifi 传递 NSData 时出现错误

ios - 如何在 View 上应用渐变模糊效果?

ios - 我的导航栏出现在故事​​板中,但未出现在模拟器中

ios - 蓝牙耳机无法用作 iOS 和 OpenEars 的录音捕获

ios - 在 UILabel 中显示 2 行半行文本

ios - iOS在后台使用多个对象执行任务

ios - UIPageViewController 索引错误

ios - 在 ext 设备上构建时,Xcode 签名证书无效

iphone - 在 iOS 7 上禁用 SKStoreProductViewController 速率

objective-c - UITabBar 未在 ios 7 中显示所选项目图像