2016-05-03 12 views
0

私はライブアプリを開発中です。ビデオバッファにフィルタを追加する必要があります。 次に、GPUImageフレームワークを使用してフィルタを作成しました。それはうまく見えますが、バッファは 'willOutputSampleBuffer:'関数にフィルタの効果がありません。ここでiOS GPUImageフィルタをビデオバッファに混在させることはできません

は、いくつかのキーコードです:

self.videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:self.sessionPreset cameraPosition:AVCaptureDevicePositionFront]; 
    self.videoCamera.delegate = self; 
    self.videoCamera.horizontallyMirrorFrontFacingCamera = YES; 

    self.filterView = [[GPUImageView alloc] init]; 

    GPUImageBeautifyFilter *beautifyFilter = [[GPUImageBeautifyFilter alloc] init]; 
    [self.videoCamera addTarget:beautifyFilter]; 
    [beautifyFilter addTarget:self.filterView]; 


    dispatch_async(dispatch_get_main_queue(), ^{ 
     [self.view insertSubview:self.filterView atIndex:1]; 
     [self.filterView mas_makeConstraints:^(MASConstraintMaker *make) { 
      make.edges.equalTo(self.view); 
     }]; 
     [self.videoCamera startCameraCapture]; 
    }); 

は私が無視任意の詳細はありますか?ありがとう!!!

答えて

0

フィルタのターゲットに新しい出力を追加する必要があるので、それらのコードをプロジェクトに追加してから、フィルタを使用してバッファを取得します。

GPUImageRawDataOutput *rawDataOutput = [[GPUImageRawDataOutput alloc] initWithImageSize:CGSizeMake(720, 1280) resultsInBGRAFormat:YES]; 

[self.beautifyFilter addTarget:rawDataOutput]; 

__weak GPUImageRawDataOutput *weakOutput = rawDataOutput; 

[rawDataOutput setNewFrameAvailableBlock:^{ 

    __strong GPUImageRawDataOutput *strongOutput = weakOutput; 
    [strongOutput lockFramebufferForReading]; 
    GLubyte *outputBytes = [strongOutput rawBytesForImage]; 
    NSInteger bytesPerRow = [strongOutput bytesPerRowInOutput]; 
    CVPixelBufferRef pixelBuffer = NULL; 
    CVPixelBufferCreateWithBytes(kCFAllocatorDefault, 720, 1280, kCVPixelFormatType_32BGRA, outputBytes, bytesPerRow, nil, nil, nil, &pixelBuffer); 

    //Do something with pixelBuffer 

    [strongOutput unlockFramebufferAfterReading];   
    CFRelease(pixelBuffer); 

}]; 
関連する問題