0

나는 AVFoundation을 사용하여 카메라에서 CMSampleBufferRef을 캡처 한 다음 CVPixelBufferRef로 변환하여 비디오에 씁니다. 내가하고 싶은 것은 비디오 프레임 안의 어떤 픽셀을 수정하는 것입니다. 그래서 CMSampleBuffer에서 CVPixelBufferRef을 가져와야합니다. 내 문제는 내가 원래 CMSampleBuffer의 오디오 데이터를 포함하지 수 있다는 내 나는 또한 CVPixelBufferRefCMSampleBuffer을 다시 시도했지만 그것은 나에게 오류를 반환 CVPixelBufferRef오디오가 포함 된 CVPixelBuffer

새로운 :

- (CMSampleBufferRef)newModifyImage:(CMSampleBufferRef)sampleBuffer { 
    CVImageBufferRef cvimgRef = CMSampleBufferGetImageBuffer(sampleBuffer); 
    CVPixelBufferLockBaseAddress(cvimgRef,0); 

    uint8_t *buf=(uint8_t *)CVPixelBufferGetBaseAddress(cvimgRef); 

    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(cvimgRef); 
    size_t width = CVPixelBufferGetWidth(cvimgRef); 
    size_t height = CVPixelBufferGetHeight(cvimgRef); 


    CVPixelBufferRef pixelBufRef = NULL; 
    CMSampleBufferRef newSampleBuffer = NULL; 
    CMSampleTimingInfo timimgInfo = kCMTimingInfoInvalid; 
    CMSampleBufferGetSampleTimingInfo(sampleBuffer, 0, &timimgInfo); 

    OSStatus result = 0; 

    OSType pixFmt = CVPixelBufferGetPixelFormatType(cvimgRef); 

    CVPixelBufferCreateWithBytes(kCFAllocatorDefault, width, height, pixFmt, buf, bytesPerRow, NULL, NULL, NULL, &pixelBufRef); 

    CMVideoFormatDescriptionRef videoInfo = NULL; 

    result = CMVideoFormatDescriptionCreateForImageBuffer(NULL, pixelBufRef, &videoInfo); 

    CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBufRef, true, NULL, NULL, videoInfo, &timimgInfo, &newSampleBuffer); 
    return newSampleBuffer; 
} 

답변

관련 문제