pili-engineering / PLStreamingKit

PLStreamingKit 是 Pili 直播 SDK 的 iOS 推流端,是不带采集模块老版本 SDK。如果是新用户接入,请使用 PLDroidMediaStreaming。该版本支持 RTMP 推流,h.264 和 AAC 编码,软编硬编支持。具有丰富的数据和状态回调,方便用户根据自己的业务定制化开发。具有直播场景下的重要功能,如:美颜、背景音乐、水印等功能。
https://github.com/pili-engineering/PLMediaStreamingKit
Apache License 2.0
250 stars 61 forks source link

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

Closed haemi closed 8 years ago

haemi commented 8 years ago

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

iobroyles commented 8 years ago

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 commented 8 years ago

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

longbai commented 8 years ago

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

haemi commented 8 years ago

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

longbai commented 8 years ago

you can modify the GPUimageFilter and add this method