3

その場で透かしをオーバーレイするように CVPixelBufferRef を変更するために、CMSampleBufferRef から CVPixelBufferRef を取得しようとしています。

私はCMSampleBufferGetImageBuffer(sampleBuffer)それを達成するために順番に使用しています。返された CVPixelBufferRef の結果を出力していますが、常に null です。

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

    CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

    NSLog(@"PixelBuffer %@",pixelBuffer);
...

}

足りないものはありますか?

4

2 に答える 2

7

何時間ものデバッグの後、サンプルがビデオまたはオーディオのサンプルである可能性があることが判明しました。そのため、オーディオ バッファから CVPixelBufferRef を取得しようとすると null が返されます。

先に進む前にサンプルの種類を確認することで解決しました。オーディオ サンプルには興味がないので、オーディオ サンプルの場合は単純に戻ります。

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

    CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

    CMFormatDescriptionRef formatDesc = CMSampleBufferGetFormatDescription(sampleBuffer);
    CMMediaType mediaType = CMFormatDescriptionGetMediaType(formatDesc);

    //Checking sample type before proceeding
    if (mediaType == kCMMediaType_Audio)
    {return;}

//Processing the sample...

}
于 2016-07-27T09:12:14.387 に答える