实时相机流媒体

时间:2013-12-20 23:44:43

标签: video-streaming wifi gamekit live-streaming nsstream

我正在尝试开发一个应用程序来进行实时流视频和音频监控服务。

从iPhone,iPad或iPod上捕捉相机,并在其他设备或iPhone,iPad或iPod等设备上实时显示。

同时,我想同时允许两个(或更多)设备之间进行音频通信和数据传输。

据我所知,Bonjour,GameKit和NSStream允许通过wifi或蓝牙在设备之间进行数据传输。

到目前为止,我已经使用AVCaptureSession(来自AVFoundation)从相机捕获每一帧并发送它 使用GKSession(从GameKit)到另一台设备(蓝牙或wifi)。

Here is the main process to send frames from the camera capturing:

    - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:   (CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
    {       
        // Get a CMSampleBuffer's Core Video image buffer for the media data
        CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

        // Lock the base address of the pixel buffer
        CVPixelBufferLockBaseAddress(imageBuffer, 0);

        // Get the number of bytes per row for the pixel buffer
        void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);

        // Get the number of bytes per row for the pixel buffer
        size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);

        // Get the pixel buffer width and height
        size_t width = CVPixelBufferGetWidth(imageBuffer);
        size_t height = CVPixelBufferGetHeight(imageBuffer);

        // Create a device-dependent RGB color space
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

        // Create a bitmap graphics context with the sample buffer data
        CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);

        // Create a Quartz image from the pixel data in the bitmap graphics context
        CGImageRef quartzImage = CGBitmapContextCreateImage(context);

        // Unlock the pixel buffer
        CVPixelBufferUnlockBaseAddress(imageBuffer,0);

        // Free up the context and color space
        CGContextRelease(context);
        CGColorSpaceRelease(colorSpace);

        // Create an image object from the Quartz image
        UIImage *image = [UIImage imageWithCGImage:quartzImage];

        NSData *data = UIImageJPEGRepresentation(image, 0.0);

        // Release the Quartz image
        CGImageRelease(quartzImage);

        // Send image data to peers, using GKSession from GameKit
        [self.gkSession sendDataToAllPeers:data withDataMode:GKSendDataReliable error:nil];

        CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
    }

And here is the other end (where i display the received frames in a UIImageView):

    - (void)receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context
    {
        // Receive image data from peers
        self.imageView.image = [UIImage imageWithData:data];
    }

我发现的问题是GameKit没有给我我需要的结果。

如果我想以温和的性能(15 fps)传输相机,发送器内图像的质量非常糟糕,接收器端更差。

如果我想通过相机以正常或高质量传输,接收器端只有0.2 fps(每5秒只有1个图像)

我希望以最佳图像质量和尽可能多的fps实时流式传输相机,以便拥有流畅而细致的实时相机流, 同时进行音频通信和数据传输。

我想知道实现这一目标的最佳方法是什么:如果我需要注册到服务器或者是否需要其他类型的软件或应用程序?

总结一下这个,我想在App(任何iPhone,iPad或iPod)中使用的功能:

发送或接收具有最佳质量和性能的相机(面部检测将用作我们的主要功能)

发送和接收具有最佳音频质量的麦克风。

发送或接收其他类型的数据(例如NSStrings,BOOL,NSArrays,C Arrays,Loops。

实现这些功能的最佳方法是什么?我需要使用哪些工具来实现这些功能?

非常感谢您提前

Pedro Monteverde

0 个答案:

没有答案
相关问题