KSYLive_iOS icon indicating copy to clipboard operation
KSYLive_iOS copied to clipboard

原始视频数据回调

Open 4940654 opened this issue 8 years ago • 3 comments

_kit.cameraPosition = AVCaptureDevicePositionFront; _kit.gpuOutputPixelFormat = kCVPixelFormatType_420YpCbCr8Planar; _kit.capturePixelFormat = kCVPixelFormatType_420YpCbCr8Planar; _kit.videoProcessingCallback = ^(CMSampleBufferRef buf){ // 在此处添加自定义图像处理, 直接修改buf中的图像数据会传递到观众端 // 或复制图像数据之后再做其他处理, 则观众端仍然看到处理前的图像 // NSLog(@"videoProcessingCallback"); //kCVPixelFormatType_32ABGR //kCVPixelFormatType_32RGBA //获取视频缓冲区地址 CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(buf); CVPixelBufferLockBaseAddress(imageBuffer, 0);

    //获取yuvBuffer地址
    UInt8 *yBuffer = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0);
    UInt8 *uBuffer = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 1);
    UInt8 *vBuffer = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 2);
    
    int count = CVPixelBufferGetPlaneCount(imageBuffer);
    
    OSType type = CVPixelBufferGetPixelFormatType(imageBuffer);

无论怎么设置_kit.capturePixelFormat参数 返回总是420v vbuffer总是为空

4940654 avatar May 26 '17 11:05 4940654

获取 地址之前要lock一下, 请参考doc

CVPixelBufferLockBaseAddress(pixelBuffer, 0);

uint8_t *yDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
uint8_t *uvDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1);
// ....
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

pengbins avatar May 31 '17 03:05 pengbins

我要的不是yuv420sp 要的是yuv420 我需要计算整个yuv到rgba sp的格式没办法做加速 所以需要普通yuv420的格式

CVPixelBufferLockBaseAddress(pixelBuffer, 0);

uint8_t *yDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0); uint8_t *uDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1); 在才是需要的 uint8_t *vDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 2); 你们的sdk提供的是个null 不管我怎么强制设置格式为420 你们都返回420sp // .... CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

在 2017年5月31日,上午11:33,pengbin [email protected] 写道:

获取 地址之前要lock一下, 请参考doc https://developer.apple.com/reference/corevideo/1456821-cvpixelbuffergetbaseaddressofpla CVPixelBufferLockBaseAddress(pixelBuffer, 0);

uint8_t *yDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0); uint8_t *uvDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1); // .... CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ksvc/KSYLive_iOS/issues/88#issuecomment-305072701, or mute the thread https://github.com/notifications/unsubscribe-auth/Aboyt-xGVhdjdcZL-PomJxq9S9tAh1s6ks5r_N98gaJpZM4NneJy.

4940654 avatar Jun 01 '17 02:06 4940654

你最终需要的是rgba的么? 所以想拿到 yuv420 之后转成 rgba ?

如果是的话, 回调应该能直接提供rgba格式的, 可以避免你再转一次

_kit.capturePixelFormat = kCVPixelFormatType_32BGRA;

Apple采集的API, 不提供返回 I420格式的数据, 我们给你转好貌似也意义不大的.

pengbins avatar Jun 02 '17 07:06 pengbins