GPUImage显示图像而不是实时视频 [英] GPUImage displaying image instead of live video

查看:264
本文介绍了GPUImage显示图像而不是实时视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经浏览了obj-c GPUImage框架,并且根据文档中的示例,我添加了以下代码片段,旨在显示已过滤的实时视频:

I've gone through the obj-c GPUImage framework, and as per the example in the documentation, I added the following snippet with intention to display filtered live video:

    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];

它有效,但不是视频我得到一个静止图像。我已经对它进行了审核并查看了示例,但无法确定它为何无法正常工作。任何帮助将不胜感激。

It works, but instead of video i get a single still image. I've reviewed it and looked at examples and can't really pinpoint why it isn't working correctly. Any help would be much appreciated.

谢谢!

推荐答案

你需要在某个地方挂起你的GPUImageVideoCamera。如果将上述内容放在方法中,并且为项目启用了ARC,则GPUImageVideoCamera实例将在该方法退出时立即释放。这将终止视频捕获,并可能导致其他令人不安的工件。

You need to hang on to your GPUImageVideoCamera somewhere. If the above is placed in a method, and ARC is enabled for the project, the GPUImageVideoCamera instance will be deallocated the instant that method exits. This will terminate the video capture and could lead to other unsettling artifacts.

在您的类中创建一个GPUImageVideoCamera实例变量,并将其用于上述内容。你也需要它,这样你就可以在完成后暂停和停止相机。

Make a GPUImageVideoCamera instance variable in your class, instead, and use that for the above. You're also going to need that so that you can pause and stop the camera when done.

这篇关于GPUImage显示图像而不是实时视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆