如何从CMSampleBufferRef获取字节,通过网络发送

|| 借助Apple Foundation http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_MediaCapture.html%23//apple_ref/doc/ uid / TP40010188-CH5-SW2 现在我做了以下事情 1.创建
videoCaptureDevice
  2.创建
AVCaptureDeviceInput
并设置
videoCaptureDevice
  3.创建ѭ3并实现委托   4.创建Create4ѭ-将输入设置为AVCaptureDeviceInput并将输出设置为AVCaptureVideoDataOutput 5,在AVCaptureVideoDataOutput委托方法中
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
我得到了CMSamplebuffer并转换为UIImage并经过测试以使用以下命令打印UIImageview
[self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
一切顺利。 我的问题是 我需要通过UDP套接字发送视频帧,尽管以下尝试是一个坏主意,我尝试将UIImage传输到NSData并通过UDP Pocket发送。 BUt在视频处理上有这么多延迟。主要是由于UIImage到NSDate的问题 所以请给我解决方案 1)任何将CMSampleBUffer或CVImageBuffer转换为NSData的方法   2)像音频队列服务和视频队列一样存储UIImage并执行UIImage到NSDate    并发送??? 如果我骑错了算法,请引导我朝写方向前进 提前致谢     
已邀请:
        这是到达缓冲区的代码。此代码假定图像为平面(例如BGRA)。
NSData* imageToBuffer( CMSampleBufferRef source) {
    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(source);
    CVPixelBufferLockBaseAddress(imageBuffer,0);

    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
    size_t width = CVPixelBufferGetWidth(imageBuffer);
    size_t height = CVPixelBufferGetHeight(imageBuffer);
    void *src_buff = CVPixelBufferGetBaseAddress(imageBuffer);

    NSData *data = [NSData dataWithBytes:src_buff length:bytesPerRow * height];

    CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
    return [data autorelease];
}
一种更有效的方法是使用NSMutableData或缓冲池。 假设3个颜色通道,每秒发送480x360图像将需要4.1Mbps连接。     
        使用
CMSampleBufferGetImageBuffer
从样本缓冲区中获取
CVImageBufferRef
,然后使用
CVPixelBufferGetBaseAddress
从中获取位图数据。这样可以避免不必要地复制图像。     

要回复问题请先登录注册