|
|
2009-09-19
, 05:53
|
|
|
Posts: 2,427 |
Thanked: 2,986 times |
Joined on Dec 2007
|
#12
|
#! /usr/bin/env python
import string
import platform
import gtk
import gst
class ShowMe:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Webcam-Viewer")
window.connect("destroy", gtk.main_quit, "WM destroy")
vbox = gtk.VBox()
window.add(vbox)
self.movie_window = gtk.DrawingArea()
vbox.add(self.movie_window)
hbox = gtk.HBox()
vbox.pack_start(hbox, False)
hbox.set_border_width(10)
hbox.pack_start(gtk.Label())
self.takePicture = 0
self.button0 = gtk.Button("Snap")
self.button0.connect("clicked", self.onTakePicture)
hbox.pack_start(self.button0, False)
self.button = gtk.Button("Start")
self.button.connect("clicked", self.start_stop)
hbox.pack_start(self.button, False)
self.button2 = gtk.Button("Quit")
self.button2.connect("clicked", self.exit)
hbox.pack_start(self.button2, False)
hbox.add(gtk.Label())
window.show_all()
self.machine = platform.uname()[4]
if self.machine == 'armv6l':
self.player = gst.Pipeline('ThePipe')
src = gst.element_factory_make("gconfv4l2src","src")
self.player.add(src)
for p in src.pads():
#print p.get_caps().to_string()
print p.get_name()
caps = gst.element_factory_make("capsfilter", "caps")
caps.set_property('caps', gst.caps_from_string(
'video/x-raw-rgb,width=352,height=288,bpp=16,depth=16,\
framerate=15/1'))
#caps.set_property('caps', gst.caps_from_string(
#'video/x-raw-rgb,width=352,height=288,\
#framerate=15/1'))
#red_mask=224,green_mask=28,blue_mask=3,framerate=15/1'))
self.player.add(caps)
filt = gst.element_factory_make("ffmpegcolorspace", "filt")
self.player.add(filt)
caps2 = gst.element_factory_make("capsfilter", "caps2")
caps2.set_property('caps', gst.caps_from_string(
'video/x-raw-rgb,width=352,height=288,bpp=16,depth=16,\
framerate=15/1'))
self.player.add(caps2)
#sink = gst.element_factory_make("xvimagesink", "sink")
sink = gst.element_factory_make("autovideosink", "sink")
self.player.add(sink)
pad = src.get_pad('src')
pad.add_buffer_probe(self.doBuffer)
src.link(caps)
caps.link(filt)
filt.link(caps2)
caps2.link(sink)
else:
self.player = gst.Pipeline('ThePipe')
src = gst.element_factory_make("v4l2src","src")
src.set_property('device','/dev/video0')
self.player.add(src)
sink = gst.element_factory_make("autovideosink", "sink")
self.player.add(sink)
pad = src.get_pad('src')
pad.add_buffer_probe(self.doBuffer)
src.link(sink)
# Set up the gstreamer pipeline
#self.player = gst.parse_launch ('gconfv4l2src ! video/x-raw-yuv,width=352,height=288,framerate=(fraction)15/1 ! autovideosink')
#self.player = gst.parse_launch ('gconfv4l2src ! video/x-raw-yuv,width=352,height=288,framerate=(fraction)15/1 ! tee name=qole qole. ! ffmpegcolorspace ! queue ! filesink location=qole.raw qole. ! queue ! autovideosink')
#self.player = gst.parse_launch ('gconfv4l2src ! video/x-raw-rgb,width=352,height=288,framerate=(fraction)15/1 ! tee name=qole qole. ! ffmpegcolorspace ! jpegenc ! filesink location=qole.raw qole. ! queue ! autovideosink')
#self.player = gst.parse_launch ('v4l2src ! autovideosink')
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
bus.connect("sync-message::element", self.on_sync_message)
def onTakePicture(self, w):
self.takePicture = 1
def doBuffer(self, pad, buffer):
if self.takePicture:
self.takePicture = 0
print 'buffer length =',len(buffer)
caps = buffer.get_caps()
#struct = caps.get_structure(0)
struct = caps[0]
print 'caps',caps
for i in range(0,struct.n_fields()):
fn = struct.nth_field_name(i)
print ' ',fn,'=',struct[fn]
# 63488 2016 31
# 0xf8 0x07,0xe0 0x1f
return True
p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,352,288)
pa = p.get_pixels()
pal = list(pa)
for i in range(0,len(buffer)/2):
pal[i*3] = "%c" % (0xf8 & ord(buffer[i*2+1]))
pal[i*3+1] = "%c" % (((0x07 & ord(buffer[i*2+1])) << 5) |\
((0xe0 & ord(buffer[i*2])) >> 5))
pal[i*3+2] = "%c" % ((0x1f & ord(buffer[i*2])) << 3)
js = string.join(pal,'')
pb = gtk.gdk.pixbuf_new_from_data(js,gtk.gdk.COLORSPACE_RGB, False,8,352,288,1056)
pb.save('/home/user/MyDocs/.images/daperl00.png','png')
print pb.get_width(),pb.get_height()
return True
def start_stop(self, w):
if self.button.get_label() == "Start":
self.button.set_label("Stop")
self.player.set_state(gst.STATE_PLAYING)
else:
self.player.set_state(gst.STATE_NULL)
self.button.set_label("Start")
def exit(self, widget, data=None):
gtk.main_quit()
def on_message(self, bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
self.player.set_state(gst.STATE_NULL)
self.button.set_label("Start")
elif t == gst.MESSAGE_ERROR:
err, debug = message.parse_error()
print "Error: %s" % err, debug
self.player.set_state(gst.STATE_NULL)
self.button.set_label("Start")
def on_sync_message(self, bus, message):
if message.structure is None:
return
message_name = message.structure.get_name()
if message_name == "prepare-xwindow-id":
# Assign the viewport
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_xwindow_id(self.movie_window.window.xid)
if __name__ == "__main__":
gtk.gdk.threads_init()
ShowMe()
gtk.main()
|
|
2009-09-19
, 17:09
|
|
|
Posts: 2,427 |
Thanked: 2,986 times |
Joined on Dec 2007
|
#13
|
|
|
2009-09-20
, 10:14
|
|
|
Posts: 3,105 |
Thanked: 11,088 times |
Joined on Jul 2007
@ Mountain View (CA, USA)
|
#14
|
| The Following 4 Users Say Thank You to qgil For This Useful Post: | ||
|
|
2009-09-21
, 05:20
|
|
|
Posts: 2,427 |
Thanked: 2,986 times |
Joined on Dec 2007
|
#15
|
/* Initialize the the Gstreamer pipeline. Below is a diagram * of the pipeline that will be created: * * |Screen| |Screen| * ->|queue |->|sink |-> Display * |Camera| |CSP | |Tee|/ * |src |->|Filter|->| |\ |Image| |Image | |Image| * ->|queue|-> |filter|->|sink |-> JPEG file */
| The Following User Says Thank You to daperl For This Useful Post: | ||
|
|
2009-09-21
, 05:33
|
|
|
Posts: 2,427 |
Thanked: 2,986 times |
Joined on Dec 2007
|
#16
|
if self.machine == 'armv6l':

|
|
2009-09-21
, 05:41
|
|
Posts: 182 |
Thanked: 540 times |
Joined on Aug 2009
@ Finland
|
#17
|
| The Following User Says Thank You to abbra For This Useful Post: | ||
|
|
2009-09-21
, 06:09
|
|
|
Moderator |
Posts: 7,109 |
Thanked: 8,820 times |
Joined on Oct 2007
@ Vancouver, BC, Canada
|
#18
|
|
|
2009-09-21
, 06:31
|
|
|
Posts: 2,427 |
Thanked: 2,986 times |
Joined on Dec 2007
|
#19
|
Just a note, guys. The original post is talking about Diablo and the tablets, not Fremantle and the N900...
I know that's where everyone's head is these days, but read closely...
qole.org --- twitter --- Easy Debian wiki page
Please don't send me a private message, post to the appropriate thread.
Thank you all for your donations!