How to capture image of Video Stream (iOS)

970 views
Skip to first unread message

Jaim Zuber

unread,
Nov 4, 2015, 6:49:11 PM11/4/15
to discuss-webrtc
All,

I'm trying to capture an image from a video stream on an iOS device. Has anyone done this?


I'm considering two approaches:

1. Get image data from the RTCEAGLVideoView.  

Unfortunately, the standard 

- (void)renderInContext:(CGContextRef)ctx;

doesn't render any of the video content. It only renders the background of the view.


2. Capture frame and convert it
Add an object as a Renderer
Convert the received RTCI420Frame data to RBG
Create image with CGImageCreate
Save image

My questions:

Approach 1 doesn't capture the video image. Is there a way to get it to render video data?

Does approach 2 sound reasonable? Will a single YUV frame be usable to create an RBG image?


Thanks for any advice.

Jaim

Alvaro Gil

unread,
Feb 4, 2016, 12:07:41 PM2/4/16
to discuss-webrtc
Jaim Zuber, did you were able to do it?

I was trying to do the same but notice that is not possible to add a new output to the AVCaptureSession instance webrtc is using.

Han Woz

unread,
Apr 13, 2016, 8:48:40 AM4/13/16
to discuss-webrtc
 approach 2 can work.On Android devices,you can capture a frame in this method:

SurfaceViewRenderer.renderFrame(VideoRenderer.I420Frame frame)


like this:http://www.webrtcbbs.com/forum.php?mod=viewthread&tid=304&page=1&extra=#pid578


If you captureToTexture,the frame's type is "oes texure",It is hard to change a image.Now I'm searching  the answer.


在 2015年11月5日星期四 UTC+8上午7:49:11,Jaim Zuber写道:

Alvaro Gil

unread,
Apr 13, 2016, 9:32:53 AM4/13/16
to discuss-webrtc
Hi Jaim,

Hope this helps, is the easiest I can found, sadly not through the API.


- (UIImage *)captureFrameFromRTCView {
   
UIView *view;
   
for (UIView *v in _localVideoView.subviews) {
       
if ([v isKindOfClass:[GLKView class]]) {
            view
= v;
       
}
   
}

   
if (!view) {
       
return nil;
   
} else {
       
return [(GLKView *)view snapshot];
   
}
}

devil 2010

unread,
Jul 31, 2020, 1:49:40 AM7/31/20
to discuss-webrtc

hello, i can not found GLKView, can you help?
Vào lúc 20:32:53 UTC+7 ngày Thứ Tư, 13 tháng 4, 2016, Alvaro Gil đã viết:
Reply all
Reply to author
Forward
0 new messages