0

trying to render using open source dav1d that can decode AV1 images.

Proceed in the order below

YUV420I -> CVPixelBufferRef -> CMSampleBufferRef -> AVSampleBufferDisplayLayer -> enqueueSampleBuffer

Error A is occurring.

2023-07-26 18:41:42.766557+0900 AV1[2166:528437] AVSampleBufferDisplayLayer: No formatDescription found in sampleBuffer

"formatDescription" contains the data below.

2023-07-26 18:41:42.766494+0900 AV1[2166:528437] <CMVideoFormatDescription 0x2801250e0 [0x20bd68660]> { mediaType:'vide' mediaSubType:'y420' mediaSpecific: { codecType: 'y420' dimensions: 1280 x 720 } extensions: {{ CVBytesPerRow = 1924; Version = 2; }} }

What's the problem?

while (dav1d_get_picture(ctx, &picture) >= 0) {
    
    int width = picture.p.w;
    int height = picture.p.h;
    uint8_t* yPlaneData = picture.data[0];
    uint8_t* uPlaneData = picture.data[1];
    uint8_t* vPlaneData = picture.data[2];
    CVReturn status;
    
    CVPixelBufferRef pixelBuffer = NULL;
    status = CVPixelBufferCreate(NULL,
                                          width, height,
                                          kCVPixelFormatType_420YpCbCr8Planar,
                                          NULL,
                                          &pixelBuffer);
    
    if (status != kCVReturnSuccess) {
        NSLog(@"Failed to create CVPixelBuffer, error: %d", status);
        return;
    }
    
    CVPixelBufferLockBaseAddress(pixelBuffer, 0);
    
    uint8_t *yDest = (uint8_t *)CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
    memcpy(yDest, yPlaneData, picture.stride[0] * height);
    
    uint8_t *uDest = (uint8_t *)CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1);
    memcpy(uDest, uPlaneData, picture.stride[1] * height / 2);

    uint8_t *vDest = (uint8_t *)CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 2);
    memcpy(vDest, vPlaneData, picture.stride[1] * height / 2);
    
    CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
    
    CMTime now = CMTimeMakeWithSeconds(CACurrentMediaTime(), 1000);
    CMSampleTimingInfo timingInfo;
    timingInfo.duration = CMTimeMakeWithSeconds(1, 1000);
    timingInfo.presentationTimeStamp = now;
    timingInfo.decodeTimeStamp = now;
    
    CMVideoFormatDescriptionRef formatDescription;
    CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, &formatDescription);
    
    NSLog(@"%@", formatDescription);
    
    CMSampleBufferRef sampleBuffer1;
    status = CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, true, NULL, NULL, formatDescription, &timingInfo, &sampleBuffer1);

    if (status != noErr) {
        NSLog(@"Unable to create sample buffer");
    }
    CVPixelBufferRelease(pixelBuffer);
    CFRelease(sampleBuffer1);
    [self.sampleLayer enqueueSampleBuffer:sampleBuffer1];
}

0 Answers0