[maemo-developers] Single frame capture with gstreamer

From: Manuel.Serrano at sophia.inria.fr Manuel.Serrano at sophia.inria.fr
Date: Thu Nov 19 16:10:45 EET 2009
Hi Fabrice,

> I'm trying to build a gstreamer pipeline to take snapshots (only on 
> picture) from the camera. I'd like one for the N810 and one for the N900.
> On the N810, I came up with :
> gst-launch v4l2src num-buffers=1 ! video/x-raw-
> rgb,width=640,height=480,framerate=8/1 ! ffmpegcolorspace ! jpegenc ! 
> filesink location=test.jpg
> The pipeline is executed as it should, but the jpeg file is a black 
> frame... I tested v4l2src ! ffmpegcolorspace ! xvimagesink to check the 
> camera hardware and it's ok.
> For the N900, I'd be grateful for any help since I don't have this lovely 
> device yet ;-)
I have tried something similar: take a snapshot on the N810. I have found
a solution that almost works except that from to time, I also get a black
frame. Here is the code I'm using (this is a Hop (http://hop.inria.fr) 
source code but I'm sure you will manage to transpose it in your own



(define (gstreamer-v4l-init!)
   (set! *src*
	 (gst-element-factory-make "v4l2src" "video-src"))
   (set! *csp-filter*
	 (gst-element-factory-make "ffmpegcolorspace" "csp_filter1"))
   (set! *img-enc*
	 (gst-element-factory-make "jpegenc" "img-enc"))
   (set! *pipeline*
	 (gst-pipeline-new "webcam-pipeline"))
   (gst-bin-add! *pipeline* *src* *csp-filter* *img-enc*)
   (gst-element-link! *src* *csp-filter*)
   (gst-element-link-mime! *csp-filter* *img-enc*
			   :width 640 :height 480
			   :framerate '(fraction 8 1))

   (gst-object-property-set! *src* :num-buffers 1))

(define-service (hopcam/snapshot #!key key)
   (with-lock *mutex-snapshot*
      (lambda ()
	 (let* ((path (let ((p (make-file-name *tmp* "hopcam.jpeg")))
			 (when (file-exists? p) (delete-file p))
		(sink (gst-element-factory-make "filesink" "image-sink"
						:location path))
		(bus (gst-pipeline-bus *pipeline*)))
	    (gst-bin-add! *pipeline* sink)
	    (gst-element-link! *img-enc* sink)
	    (gst-element-state-set! *pipeline* 'playing)
	       (let loop ((play 0))
		  (let ((msg (gst-bus-poll bus)))
			((gst-message-eos? msg)
			 (gst-element-state-set! *pipeline* 'null)
			    (file path)))
			((gst-message-error? msg)
			 (tprint (gst-message-error-string msg))
			 (error 'hopcam/snapshot
				"Cannot produce image"
				(gst-message-error-string msg)))
			 (loop play)))))
	       (gst-bin-remove! *pipeline* sink))))))
More information about the maemo-developers mailing list