目前,我正处于iOS项目中,需要从IP摄像头捕获MJPEG。 (相机从显微镜捕获图像。根据相机供应商的说法,这台相机通过HTTP流传输MJPEG数据。我可以通过这样的网址获取流,http://192.168.1.156:8196/?action=stream。)
我需要在iPhone上显示流。这是通过使用NSURLSession来解析此流来完成的。代码如下。- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
completionHandler(NSURLSessionResponseAllow);
dispatch_async(dispatch_get_main_queue(), ^{
if ([[self.imageData contentTypeForImageData] isEqualToString:@"image/jpeg"]) {
UIImage *newImage = [UIImage imageWithData:self.imageData];
[self saveNewImageToImages:newImage];
}
[self refreshImageView];
self.imageData = [NSMutableData new];
});
}
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
dispatch_async(dispatch_get_main_queue(), ^{
[self.imageData appendData:data];
});
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
NSLog(@"%s - %@", __FUNCTION__, [NSThread currentThread]);
NSLog(@"error = %@", [error localizedDescription]);
}
2。我需要将这些图像与来自iPhone和RTMP服务器的音频一起推送到实时流。 enter image description here