maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Fremantle GStreamer (https://talk.maemo.org/showthread.php?t=31666)

qole 2009-09-14 17:14

Fremantle GStreamer
 
Hi all,

I'm willing to test GStreamer applications on Fremantle hardware.

It would really help multimedia developers if someone could provide GStreamer Editor for Fremantle, to help figure out how to build correct pipelines.

qole 2009-09-14 17:26

Re: Fremantle GStreamer
 
Ok, basic gstreamer pipeline from camera to screen:

v4l2src device=/dev/video0 ! autovideosink

For high resolution (back) camera, it is /dev/video0 and for the front web camera, it is /dev/video1.

The output needs to be massaged, so that the aspect ratio is correct, etc.

daperl 2009-09-14 17:41

Re: Fremantle GStreamer
 
Can you change the self.player line to the one below and try again. Post the output here.

Code:

self.player = gst.parse_launch ('v4l2src device=/dev/video0 ! video/x-raw-yuv,width=320,height=240,framerate=(fraction)15/1 ! autovideosink')

qole 2009-09-14 17:56

Re: Fremantle GStreamer
 
Just trying that pipeline from the command line (gst-launch), I start getting "cannot negotiate format" as soon as I start adding the width, height, or framerate values...

How do you check what the device's capabilities are? There's got to be a way to query the device for acceptable parameters...

daperl 2009-09-14 18:08

Re: Fremantle GStreamer
 
Use the following generic string instead. It should either work or dump out an error message with some width/height info.

Code:

self.player = gst.parse_launch ('v4l2src device=/dev/video0  ! autovideosink')
Is the lense cap off? :)

qole 2009-09-14 18:44

Re: Fremantle GStreamer
 
Yes, that very simple pipeline works. It displays the back camera's view in a square window in the middle of the screen (above your two buttons). I'd post a screenshot, but it appears that the screenshot utility doesn't capture the picture, just a black square where the picture is.

There was no output on the command line.

qole 2009-09-17 22:20

Re: Fremantle GStreamer
 
Just a note for future reference, since it is in a completely different thread; daperl's original camera script can be found here.

lardman 2009-09-18 07:39

Re: python / gstreamer / camera / xvimagesink issues
 
Ok, so the output of the large camera is 640 x 492 encoded as YUYV.

lardman 2009-09-18 07:56

Re: python / gstreamer / camera / xvimagesink issues
 
Actually although that gives you good Y data, the U and V data are probably arranged a little differently in the data stream (as for each of these you get two images side by side).

More testing...

daperl 2009-09-19 00:04

Re: Fremantle GStreamer
 
The script you pointed to doesn't really do anything. The following really, really bad hack will actually take a picture and create a .png file on an n800. As is, it won't work on an n900, but the changes should be obvious.

Also, the file creation is really, really slow; about 25 seconds. It's strictly just a hard-coded, proof-of-concept that a picture can be taken on a tablet with just using PyGTK and GStreamer. Obviously, plenty of room for improvement.

Code:

#! /usr/bin/env python

import string
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()

                if 1 == 1:
                    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")
                    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)

                # 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.get_caps()
                # 63488 2016 31
                # 0xf8  0x07,0xe0  0x1f
                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()



All times are GMT. The time now is 08:22.

vBulletin® Version 3.8.8