如何从图像创建流,然后在objective-c中通过网络共享?

如何从图像创建流,然后在objective-c中通过网络共享?,objective-c,macos,cocoa,video-streaming,html5-video,Objective C,Macos,Cocoa,Video Streaming,Html5 Video,我正在开发一个应用程序,它可以连续拍摄静态图像,然后通过网络将这些图像作为MPEG视频流传输到HTML客户端。 我一直在看2014年WWDC的视频(开始时间:28:50至:35:40)。不幸的是,视频是非常高的水平,只显示了一点点的代码 基于这些细节,我编写了一个小测试程序(大纲如下所示) 通过网络将CMSampleBufferRef sampleBuffer分发到HTML客户端的下一步是什么 #import <Cocoa/Cocoa.h> #import <VideoTool

我正在开发一个应用程序,它可以连续拍摄静态图像,然后通过网络将这些图像作为MPEG视频流传输到HTML客户端。 我一直在看2014年WWDC的视频(开始时间:28:50至:35:40)。不幸的是,视频是非常高的水平,只显示了一点点的代码

基于这些细节,我编写了一个小测试程序(大纲如下所示)

通过网络将
CMSampleBufferRef sampleBuffer
分发到HTML客户端的下一步是什么

#import <Cocoa/Cocoa.h>
#import <VideoToolbox/VideoToolbox.h>

void compressionCallback(
        void *outputCallbackRefCon,
        void *sourceFrameRefCon,
        OSStatus status,
        VTEncodeInfoFlags infoFlags,
        CMSampleBufferRef sampleBuffer ){

    NSLog(@"received compressed image");
    // how to share the CMSampleBufferRef via the network to an HTML client?
}

int main(int argc, const char * argv[]) {

    // create VTCompressionSession stream
    VTCompressionSessionRef cpsession;
    VTCompressionSessionCreate(NULL, (CGFloat)width, (CGFloat)height, kCMVideoCodecType_H264, NULL, NULL, NULL, (void*)compressionCallback, NULL, &cpsession);

    while (true) {
        // take new image, stuff it into the session

        NSImage *NSWindowImage = /*taking the image*/
        // create a CVPixelbuffer from the image
        CVPixelBufferRef pixelbuffer = pixelBufferFromNSImage(NSWindowImage);

         // feed pixel into stream
        CMTime presentationTimeStamp = CMTimeMake(0, 1); // needs to be updated for every frame
        VTCompressionSessionEncodeFrame(cpsession, pixelbuffer, presentationTimeStamp, kCMTimeInvalid, NULL, NULL, NULL);
        VTCompressionSessionEndPass(cpsession, NO, NULL); 
    }

    return 0; // application never reaches this return statement
}
#导入
#进口
空隙压缩(
void*outputCallbackRefCon,
void*sourceFrameRefCon,
骨状态,
VTEncodeInfoFlags信息标志,
CMSampleBufferRef(采样缓冲区){
NSLog(@“接收到的压缩图像”);
//如何通过网络将CMSampleBufferRef共享给HTML客户端?
}
int main(int argc,const char*argv[]{
//创建VTCompressionSession流
VT压缩参考CPS压缩;
VTCompressionSessionCreate(NULL,(CGFloat)width,(CGFloat)height,kCMVideoCodecType_H264,NULL,NULL,NULL,(void*)compressionCallback,NULL,&cpsession);
while(true){
//拍摄新图像,将其放入会话中
NSImage*NSWindowImage=/*拍摄图像*/
//从图像创建CVPixelbuffer
CVPixelBufferRef PIXELBUFFERF=pixelBufferFromNSImage(NSWindowImage);
//将像素馈送到流中
CMTime presentationTimeStamp=CMTimeMake(0,1);//需要为每一帧更新
VTCompressionSessionCodeFrame(cpsession、pixelbuffer、presentationTimeStamp、KCMTIMEIVALID、NULL、NULL、NULL);
VTCompressionEndPass(压缩,否,空);
}
return 0;//应用程序从未到达此return语句
}
有关有效实施的信息,请参阅