<div dir="ltr"><div>It sounds like Open CV may be better for this. I have done it before for that. just thought if I was using gstreamer for everyting else, I could use it here too. Bummer,<br></div>Jason<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sat, Aug 24, 2013 at 12:15 PM, Andrey Nechypurenko <span dir="ltr"><<a href="mailto:andreynech@googlemail.com" target="_blank">andreynech@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 24 August 2013 10:14, Jason (spot) Brower <<a href="mailto:encompass@gmail.com">encompass@gmail.com</a>> wrote:<br>
> I can take the picture and save the image to a file using just Gstreamer.<br>
> But I need to work with the image before I save it anyway, so how can I<br>
> convert it to PIL after I take the picture.<br>
> A code example would be handy. I have googled and no found it as far as I<br>
> have searched.<br>
<br>
</div></div>One possible way would be to create the pipeline which ends with<br>
fakesink element and use it's handoff mechanism to get access to raw<br>
frame. For example:<br>
<br>
videotestsrc is-live=true !<br>
video/x-raw-yuv,width=640,height=480,framerate=30/1 ! ffmpegcolorspace<br>
! video/x-raw-rgb, bpp=32, depth=32 ! fakesink sync=1<br>
<br>
The following code illustrates how to update OpenGL texture with it.<br>
Here on_gst_buffer(self, fakesink, buff, pad, data=None) will be<br>
invoked by gstreamer for each new frame and data contains raw decoded<br>
frame in format specified by the caps filter in front of fakesink.<br>
<br>
import ctypes<br>
<br>
import gobject<br>
import gst<br>
<br>
class Receiver(object):<br>
<br>
def __init__(self, video_tex_id, pipeline_string):<br>
self.tex_updated = True<br>
self.texdata = (ctypes.c_ubyte * 640 * 480 * 4)()<br>
self.video_tex_id = video_tex_id<br>
<br>
# Create GStreamer pipeline<br>
self.pipeline = gst.parse_launch(pipeline_string)<br>
<br>
# Create bus to get events from GStreamer pipeline<br>
self.bus = self.pipeline.get_bus()<br>
self.bus.add_signal_watch()<br>
self.bus.connect('message::eos', self.on_eos)<br>
self.bus.connect('message::error', self.on_error)<br>
<br>
self.fakesink = self.pipeline.get_by_name('fakesink0')<br>
self.fakesink.props.signal_handoffs = True<br>
self.fakesink.connect("handoff", self.on_gst_buffer)<br>
<br>
self.pipeline.set_state(gst.STATE_PLAYING)<br>
<br>
<br>
def on_gst_buffer(self, fakesink, buff, pad, data=None):<br>
self.tex_updated = False<br>
ctypes.memmove(self.texdata, buff.data, buff.size)<br>
return gst.FLOW_OK<br>
<br>
<br>
def updateTexture(self):<br>
if not self.tex_updated and not self.texdata == None:<br>
glBindTexture(GL_TEXTURE_2D, self.video_tex_id)<br>
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 640, 480, GL_RGBA,<br>
GL_UNSIGNED_BYTE, self.texdata)<br>
self.tex_updated = True<br>
<br>
<br>
def on_eos(self, bus, msg):<br>
print('on_eos(): seeking to start of video')<br>
self.pipeline.seek_simple(<br>
gst.FORMAT_TIME,<br>
gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_KEY_UNIT,<br>
0L<br>
)<br>
<br>
<br>
def on_error(self, bus, msg):<br>
print('on_error():', msg.parse_error())<br>
<br>
<br>
HTH,<br>
Andrey.<br>
_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
</blockquote></div><br></div>