iOS programlama ve multimedya konusunda yeniyim ve this link numaralı telefondan Apple tarafından sağlanan RosyWriter adlı örnek bir projeden geçiyordum. pixelBufferReadyForDisplay
adında bir işlev pixelBufferReadyForDisplayCVImageBufferRef 'i CVPixelBufferRef' e Dönüştürme
CVPixelBufferRef
Prototip türde bir parametre tahmin ettiği denir Burada
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
if (connection == videoConnection) {
// Get framerate
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
[self calculateFramerateAtTimestamp:timestamp];
// Get frame dimensions (for onscreen display)
if (self.videoDimensions.width == 0 && self.videoDimensions.height == 0)
self.videoDimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
// Get buffer type
if (self.videoType == 0)
self.videoType = CMFormatDescriptionGetMediaSubType(formatDescription);
CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Synchronously process the pixel buffer to de-green it.
[self processPixelBuffer:pixelBuffer];
// Enqueue it for preview. This is a shallow queue, so if image processing is taking too long,
// we'll drop this frame for preview (this keeps preview latency low).
OSStatus err = CMBufferQueueEnqueue(previewBufferQueue, sampleBuffer);
if (!err) {
dispatch_async(dispatch_get_main_queue(), ^{
CMSampleBufferRef sbuf = (CMSampleBufferRef)CMBufferQueueDequeueAndRetain(previewBufferQueue);
if (sbuf) {
CVImageBufferRef pixBuf = CMSampleBufferGetImageBuffer(sbuf);
[self.delegate pixelBufferReadyForDisplay:pixBuf];
CFRelease(sbuf);
}
});
}
}
CFRetain(sampleBuffer);
CFRetain(formatDescription);
dispatch_async(movieWritingQueue, ^{
if (assetWriter) {
BOOL wasReadyToRecord = (readyToRecordAudio && readyToRecordVideo);
if (connection == videoConnection) {
// Initialize the video input if this is not done yet
if (!readyToRecordVideo)
readyToRecordVideo = [self setupAssetWriterVideoInput:formatDescription];
// Write video data to file
if (readyToRecordVideo && readyToRecordAudio)
[self writeSampleBuffer:sampleBuffer ofType:AVMediaTypeVideo];
}
else if (connection == audioConnection) {
// Initialize the audio input if this is not done yet
if (!readyToRecordAudio)
readyToRecordAudio = [self setupAssetWriterAudioInput:formatDescription];
// Write audio data to file
if (readyToRecordAudio && readyToRecordVideo)
[self writeSampleBuffer:sampleBuffer ofType:AVMediaTypeAudio];
}
BOOL isReadyToRecord = (readyToRecordAudio && readyToRecordVideo);
if (!wasReadyToRecord && isReadyToRecord) {
recordingWillBeStarted = NO;
self.recording = YES;
[self.delegate recordingDidStart];
}
}
CFRelease(sampleBuffer);
CFRelease(formatDescription);
});
}
: İşte kodunda kodunda captureOutput:didOutputSampleBuffer:fromConnection
adında bir fonksiyon aşağıda verilmiştir olduğunu gördük
- (void)pixelBufferReadyForDisplay:(CVPixelBufferRef)pixelBuffer;
Ancak yukarıdaki kodda bu işlev çağrılırken pixBuf
değişkenini geçirir ich, tip CVImageBufferRef
Bu yüzden sorum şu: CVImageBufferRef'i CVPixelBufferRef'e dönüştürmek için herhangi bir işlev veya typecasting kullanması gerekmiyor mu, yoksa derleyici tarafından dolaylı olarak mı yapıldı?
Teşekkürler. Xcode dokümanlarında CVPixelBufferRef üzerinde bir arama yaparsanız
Neden iOS'ta bir CVPixelBuffer'dan bir CIImage oluşturabiliyorsunuz, OSX değil? CIImage (CVPixelBuffer: currPixelBuffer), iOS'ta değil, OSX'te çalışır. CIImage (CVImageBuffer: currPixelBuffer) OSX'te çalışır. – Adam
Platformlar arasında bazı veri tipi farkı vardır. Bazen bunun için iyi bir sebep yok. –