Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it possible to "feed" the library with a manipulated video? #11

Closed
haemi opened this issue Mar 31, 2016 · 5 comments
Closed

is it possible to "feed" the library with a manipulated video? #11

haemi opened this issue Mar 31, 2016 · 5 comments

Comments

@haemi
Copy link

haemi commented Mar 31, 2016

I would like to modify the video coming from the device - is this possible somehow? E.g. with OpenCV?

@iobroyles
Copy link

You should be able to create a chain of filters using GPUImage which this project uses.

https://github.com/BradLarson/GPUImage#filtering-live-video

@haemi
Copy link
Author

haemi commented Apr 13, 2016

sorry, I don't get it yet; can you give a short example for how to achieve that?

@longbai
Copy link
Contributor

longbai commented Apr 14, 2016

here is sample
GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

// 创建一个 filter
GPUImageSketchFilter *filter = [[GPUImageSketchFilter alloc] init];
__weak typeof(self) wself = self;
filter.frameProcessingCompletionBlock = ^(GPUImageOutput *output, CMTime time) {
__strong typeof(wself) strongSelf = wself;
if (strongSelf && PLStreamStateConnected == strongSelf.session.streamState) {
// 从 filter 中读取 GPUImageFramebuffer 对象
GPUImageFramebuffer *imageFramebuffer = output.framebufferForOutput;

    // 通过上面添加的方法获取到 CVPixelBufferReft
    CVPixelBufferRef pixelBuffer = [imageFramebuffer renderTarget];

    if (pixelBuffer) {
        CVPixelBufferLockBaseAddress(pixelBuffer, 0);
        CVPixelBufferRetain(pixelBuffer);

        // 发送视频数据
        [strongSelf.session pushPixelBuffer:pixelBuffer completion:^{
            CVPixelBufferRelease(pixelBuffer);
            CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
        }];
    }
}

};

GPUImageView *filteredVideoView = [[GPUImageView alloc] initWithFrame:(CGRect){0, 64, width, height}];

// Add the view somewhere so it's visible
[self.view addSubview:filteredVideoView];

[videoCamera addTarget:filter];
[filter addTarget:filteredVideoView];

[videoCamera startCameraCapture];

@longbai longbai closed this as completed Apr 14, 2016
@haemi
Copy link
Author

haemi commented Apr 14, 2016

there is no renderTarget method on GPUImageFramebuffer - how can I achieve this conversion?

@longbai
Copy link
Contributor

longbai commented Apr 14, 2016

you can modify the GPUimageFilter and add this method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants