6

का उपयोग करके एक आईओएस डिवाइस से दूसरे में कैमरे को स्टीम करने के लिए कैसे करें IOS 7 में ब्लूटूथ या वाईफाई का उपयोग करके हम एक आईओएस डिवाइस से दूसरे में कैमरा फीड को कुशलतापूर्वक कैसे स्थानांतरित कर सकते हैं। स्टीम बफर प्राप्त करने के लिए नीचे कोड है।मल्टी पीयर कनेक्टिविटी

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
     didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 
    // Create a UIImage from the sample buffer data 
    UIImage *image = [self imageFromSampleBuffer:sampleBuffer]; 


} 

    // Create a UIImage from sample buffer data 
- (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer 
{ 
    // 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]; 

    // Release the Quartz image 
    CGImageRelease(quartzImage); 

    return (image); 
} 

यहां हम आईओएस कैमरा द्वारा प्राप्त की जा रही छवि प्राप्त कर सकते हैं।

क्या हम मल्टी पीयर का उपयोग करके नमूना बफर जानकारी सीधे किसी अन्य डिवाइस पर भेज सकते हैं या क्या अन्य आईओएस उपकरणों को डेटा भाप करने का कोई प्रभावी तरीका है?

धन्यवाद।

+0

मल्टीपायर कनेक्टिविटी वैध विकल्प की तरह लगता है। लेकिन आपको प्रदर्शन की जांच करनी होगी। असंपीड़ित छवियों को भेजने के लिए संभवतः बहुत अधिक बैंडविड्थ की आवश्यकता होगी ताकि आपको लाइव कैप्चर को स्थानांतरित करने में सक्षम होने के लिए शायद एक वास्तविक वीडियो स्ट्रीम बनाना पड़े। – allprog

+0

संपादन 6 वर्ण होने चाहिए, इसलिए जब तक हम फिलर के साथ नहीं आते हैं, यह पोस्ट हमेशा –

+0

फ़ीड को भाप लेगा। अच्छा सवाल संदीभाई, उपरोक्त .. – NSPratik

उत्तर

0

मुझे ऐसा करने का तरीका मिला है, हम संपीड़ित छवियों को स्ट्रीम करने के लिए बहु सहकर्मी कनेक्टिविटी का उपयोग कर सकते हैं ताकि यह कैमरे की स्ट्रीमिंग की तरह दिखाई दे।

एक सहकर्मी जो धारा भेजने के लिए इस code.In captureOutput प्रतिनिधि विधि का प्रयोग करेंगे जा रहा है:

 NSData *imageData = UIImageJPEGRepresentation(cgBackedImage, 0.2); 

    // maybe not always the correct input? just using this to send current FPS... 
    AVCaptureInputPort* inputPort = connection.inputPorts[0]; 
    AVCaptureDeviceInput* deviceInput = (AVCaptureDeviceInput*) inputPort.input; 
    CMTime frameDuration = deviceInput.device.activeVideoMaxFrameDuration; 
    NSDictionary* dict = @{ 
          @"image": imageData, 
          @"timestamp" : timestamp, 
          @"framesPerSecond": @(frameDuration.timescale) 
          }; 
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dict]; 


    [_session sendData:data toPeers:_session.connectedPeers withMode:MCSessionSendDataReliable error:nil]; 

और प्राप्त करने की ओर:

- (void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCPeerID *)peerID { 

// NSLog(@"(%@) Read %d bytes", peerID.displayName, data.length); 

    NSDictionary* dict = (NSDictionary*) [NSKeyedUnarchiver unarchiveObjectWithData:data]; 
    UIImage* image = [UIImage imageWithData:dict[@"image"] scale:2.0]; 
    NSNumber* framesPerSecond = dict[@"framesPerSecond"]; 


} 

हम एफपीएस मूल्य प्राप्त होगा और उसके अनुसार हम अपनी स्ट्रीमिंग छवियों को प्रबंधित करने के लिए पैरामीटर सेट कर सकते हैं।

आशा है कि इससे मदद मिलेगी।

धन्यवाद।

+0

सैंडिप ने मल्टी-पीयर का उपयोग करके दो आईफोन उपकरणों के बीच ऑडियो फ़ाइलों को स्ट्रीम करने का प्रयास किया था? –

0

यहाँ यह करने के लिए सबसे अच्छा तरीका है (और, मैं अंत में कर इसका कारण):

IOS डिवाइस छवि डेटा भेजने पर:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 
{ 
    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 

    CVPixelBufferLockBaseAddress(imageBuffer,0); 
    uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); 
    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 
    size_t width = CVPixelBufferGetWidth(imageBuffer); 
    size_t height = CVPixelBufferGetHeight(imageBuffer); 

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); 
    CGImageRef newImage = CGBitmapContextCreateImage(newContext); 


    UIImage *image = [[UIImage alloc] initWithCGImage:newImage scale:1 orientation:UIImageOrientationUp]; 
    CGImageRelease(newImage); 
    CGContextRelease(newContext); 
    CGColorSpaceRelease(colorSpace); 
    CVPixelBufferUnlockBaseAddress(imageBuffer, 0); 

    if (image) { 
     NSData *data = UIImageJPEGRepresentation(image, 0.7); 
     NSError *err; 
     [((ViewController *)self.parentViewController).session sendData:data toPeers:((ViewController *)self.parentViewController).session.connectedPeers withMode:MCSessionSendDataReliable error:&err]; 
    } 
} 

iOS डिवाइस पर छवि डेटा प्राप्त :

typedef struct { 
    size_t length; 
    void *data; 
} ImageCacheDataStruct; 

- (void)session:(nonnull MCSession *)session didReceiveData:(nonnull NSData *)data fromPeer:(nonnull MCPeerID *)peerID 
{ 
    dispatch_async(self.imageCacheDataQueue, ^{ 
     dispatch_semaphore_wait(self.semaphore, DISPATCH_TIME_FOREVER); 
     const void *dataBuffer = [data bytes]; 
     size_t dataLength = [data length]; 
     ImageCacheDataStruct *imageCacheDataStruct = calloc(1, sizeof(imageCacheDataStruct)); 
     imageCacheDataStruct->data = (void*)dataBuffer; 
     imageCacheDataStruct->length = dataLength; 

     __block const void * kMyKey; 
     dispatch_queue_set_specific(self.imageDisplayQueue, &kMyKey, (void *)imageCacheDataStruct, NULL); 

     dispatch_sync(self.imageDisplayQueue, ^{ 
      ImageCacheDataStruct *imageCacheDataStruct = calloc(1, sizeof(imageCacheDataStruct)); 
      imageCacheDataStruct = dispatch_queue_get_specific(self.imageDisplayQueue, &kMyKey); 
      const void *dataBytes = imageCacheDataStruct->data; 
      size_t length = imageCacheDataStruct->length; 
      NSData *imageData = [NSData dataWithBytes:dataBytes length:length]; 
      UIImage *image = [UIImage imageWithData:imageData]; 
      if (image) { 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        [((ViewerViewController *)self.childViewControllers.lastObject).view.layer setContents:(__bridge id)image.CGImage]; 
        dispatch_semaphore_signal(self.semaphore); 
       }); 
      } 
     }); 
    }); 
} 

सेमाफोर और अलग GCD कतारों के लिए वजह साफ है: आप फ्रेम बराबर समय अंतराल पर प्रदर्शित करना चाहते हैं। अन्यथा, वीडियो पकड़ने के क्रम में सामान्य से पहले की गति तेज करने से ठीक पहले, कभी-कभी धीमा प्रतीत होता है। मेरी योजना यह सुनिश्चित करती है कि नेटवर्क बैंडविड्थ बाधाओं के बावजूद, प्रत्येक फ्रेम एक ही गति से दूसरे के बाद एक-दूसरे के बाद खेलता है।

संबंधित मुद्दे