2017-03-26 12 views
1

비디오 캡처 파이프 라인에서 4 : 3 프레임을 16 : 9 프레임으로 변환하려고합니다. 변환 된 프레임은 추가 처리가 필요합니다. 따라서 덮여있는 프레임을 CVImageBufferRef으로 유지해야합니다. 나는이 스택 오버플로 스레드를 보았다, 그리고 여기 iOS - Scale and crop CMSampleBufferRef/CVImageBufferRefCVPixelBufferRef 샘플을 4 : 3에서 16 : 9로 변환합니다.

내가 무슨 짓을에서 몇 가지 아이디어를 빌려 :

int cropX0 = 0, cropY0 = 60, cropHeight = 360, cropWidth = 640, outWidth = 640, outHeight = 360; 
//get CVPixel buffer from CMSampleBuffer 
CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(cmSampleBuffer); 
CVPixelBufferLockBaseAddress(imageBuffer,0); 
void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer); 
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 

size_t startpos = cropY0 * bytesPerRow; 
void* cropStartAddr = ((char*)baseAddress) + startpos; 

CVPixelBufferRef cropPixelBuffer = NULL; 
int status = CVPixelBufferCreateWithBytes(kCFAllocatorDefault, 
              outWidth, 
              outHeight, 
              CVPixelBufferGetPixelFormatType(imageBuffer), 
              cropStartAddr, 
              bytesPerRow, 
              NULL, 
              0, 
              NULL, 
              &cropPixelBuffer); 
if(status == 0){ 
    OSStatus result = 0; 
} 

을하지만이 방법 후. Xcode에서 cropPixelBuffer를 검사하면됩니다. 그것은 부패 된 이미지처럼 보입니다.

enter image description here 는 원래 사진 내가 때문에 색상 형식이 될 수 있다고 생각이

enter image description here

처럼 보이는 것은 NV12의 YUV 픽셀 형식을 도와 감사하다

답변

1

이미지 데이터 인 경우 yuv라면 다중 비행기 데이터 (예 : 복수 rowbytes, 복수 baseAddrs 및 복수 width, height 및 여러 작물) 어떤 경우에는 사용해야합니까

CVPixelBufferCreateWithPlanarBytes() 

그래서 CVPixelBufferGetPixelFormatType(imageBuffer)은 무엇을 반환합니까?

+0

형식은 kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange입니다. 내가 따로 따로 UV를 건네야 할 것 같아. – user454083

+0

그래, 자르면 두 비트 맵이 있다는 뜻이야. –