Take snapshot from running pipeline in gstreamer with iOS
Macjon
jonah.hulselmans at flowpilots.com
Wed Aug 17 10:47:55 UTC 2016
I've got a peace of code that works. I removed the tee from my pipeline. And
now I have the following objective-c code:
-(UIImage*) takeSnapshot
{
GstSample *videobuffer = NULL;
GstCaps *caps;
gint width, height;
GstMapInfo map;
g_object_get(G_OBJECT(video_sink), "last-sample", &videobuffer, NULL);
if (videobuffer)
{
caps = gst_sample_get_caps(videobuffer);
if (!caps) {
return NULL;
}
GstStructure *s = gst_caps_get_structure(caps, 0);
/* we need to get the final caps on the buffer to get the size */
gboolean res;
res = gst_structure_get_int (s, "width", &width);
res |= gst_structure_get_int (s, "height", &height);
if (!res) {
return NULL;
}
GstBuffer *snapbuffer = gst_sample_get_buffer(videobuffer);
if (snapbuffer && gst_buffer_map (snapbuffer, &map, GST_MAP_READ))
{
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL,
map.data,
height *
width * 4,
NULL);
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent =
kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(width,
height,
8,
4 * 8,
width * 4,
colorSpaceRef,
bitmapInfo,
provider,
NULL,
NO,
renderingIntent);
UIImage *uiImage = [UIImage imageWithCGImage:imageRef];
CGColorSpaceRelease(colorSpaceRef);
CGImageRelease(imageRef);
return uiImage;
}
return NULL;
}
return NULL;
}
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Take-snapshot-from-running-pipeline-in-gstreamer-with-iOS-tp4678410p4679126.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list