cleanup and trying to catch frames
This commit is contained in:
77
gstreamer/capturing-frames.lisp
Normal file
77
gstreamer/capturing-frames.lisp
Normal file
@@ -0,0 +1,77 @@
|
||||
;(load (sb-ext:posix-getenv "ASDF"))
|
||||
(asdf:load-system 'cl-cffi-gtk)
|
||||
(asdf:load-system 'cl-gobject-introspection)
|
||||
|
||||
(defpackage :capturing-frames
|
||||
(:use :cl))
|
||||
|
||||
(in-package :capturing-frames)
|
||||
(gir:require-namespace "GLib")
|
||||
(defvar *gstreamer* (gir:require-namespace "Gst"))
|
||||
|
||||
(defun cast-with-videobox (&optional stream-num)
|
||||
(gir:invoke (*gstreamer* 'init) '())
|
||||
(let* ((pipeline (gir:invoke (*gstreamer* "Pipeline" 'new) "video-pipeline"))
|
||||
(source (gir:invoke (*gstreamer* "ElementFactory" 'make) (if stream-num
|
||||
"pipewiresrc"
|
||||
"videotestsrc") "source"))
|
||||
(convert (gir:invoke (*gstreamer* "ElementFactory" 'make) "videoconvert" "convert"))
|
||||
(tee (gir:invoke (*gstreamer* "ElementFactory" 'make) "tee" "tee"))
|
||||
(queue1 (gir:invoke (*gstreamer* "ElementFactory" 'make) "queue" "queue1"))
|
||||
(queue2 (gir:invoke (*gstreamer* "ElementFactory" 'make) "queue" "queue2"))
|
||||
(sink (gir:invoke (*gstreamer* "ElementFactory" 'make) "autovideosink" "sink"))
|
||||
(appsink (gir:invoke (*gstreamer* "ElementFactory" 'make) "appsink" "appsink")))
|
||||
(when stream-num
|
||||
;; Set pipewiresrc properties, such as the path
|
||||
(setf (gir:property source 'path) (format nil "~A" stream-num)))
|
||||
|
||||
;; Add and link elements in the pipeline
|
||||
(gir:invoke (pipeline 'add) source)
|
||||
(gir:invoke (pipeline 'add) convert)
|
||||
(gir:invoke (pipeline 'add) tee)
|
||||
(gir:invoke (pipeline 'add) queue1)
|
||||
(gir:invoke (pipeline 'add) queue2)
|
||||
(gir:invoke (pipeline 'add) sink)
|
||||
(gir:invoke (pipeline 'add) appsink)
|
||||
|
||||
(gir:invoke (source 'link) convert)
|
||||
(gir:invoke (convert 'link) tee)
|
||||
(gir:invoke (tee 'link) queue1)
|
||||
(gir:invoke (tee 'link) queue2)
|
||||
(gir:invoke (queue1 'link) sink)
|
||||
(gir:invoke (queue2 'link) appsink)
|
||||
|
||||
;; Configure appsink
|
||||
(setf (gir:property appsink "emit-signals") t
|
||||
(gir:property appsink "max-buffers") 1
|
||||
(gir:property appsink "drop") t)
|
||||
|
||||
(gir:invoke (pipeline 'set-state) (gir:nget *gstreamer* "State" :playing))
|
||||
|
||||
;; Example: Move the video 10 pixels down and 20 pixels to the right
|
||||
pipeline))
|
||||
|
||||
(defun process-frame (sample)
|
||||
(let* ((buffer (gir:invoke (sample 'get-buffer)))
|
||||
(info (gir:invoke (buffer 'get-memory) 0))
|
||||
(map-info (gir:invoke (info 'map) (gir:nget *gstreamer* "MapFlags" :read)))
|
||||
(data (gir:property map-info 'data))
|
||||
(size (gir:property map-info 'size)))
|
||||
;; Process the frame data here
|
||||
(format t "Received frame of size ~A bytes~%" size)
|
||||
;; Example: Calculate average brightness
|
||||
(let ((sum 0))
|
||||
(dotimes (i size)
|
||||
(incf sum (aref data i)))
|
||||
(format t "Average brightness: ~A~%" (/ sum size)))
|
||||
;; Unmap the memory when done
|
||||
(gir:invoke (info 'unmap) map-info)))
|
||||
|
||||
(defun start-processing (appsink)
|
||||
(gir:connect appsink "new-sample"
|
||||
(lambda (appsink)
|
||||
(let ((sample (gir:invoke (appsink 'pull-sample))))
|
||||
(when sample
|
||||
(process-frame sample)
|
||||
(gir:invoke (sample 'unref))))
|
||||
(gir:nget *gstreamer* "FlowReturn" :ok))))
|
||||
@@ -11,6 +11,13 @@
|
||||
(defvar *gtk* (gir:require-namespace "Gtk" "3.0"))
|
||||
(gir:nget *gtk* "WindowType" :toplevel) ; get enum value
|
||||
|
||||
(defun huh-window ()
|
||||
(gir:invoke (*gtk* 'init) nil)
|
||||
(let ((window (gir:invoke (*gtk* "Window" 'new)
|
||||
(gir:nget *gtk* "WindowType" :toplevel))))
|
||||
(gir:invoke (window 'show))
|
||||
(gir:invoke (*gtk* 'main))))
|
||||
|
||||
;; name wildly from
|
||||
;; https://stackoverflow.com/questions/36296165/python-bindings-for-gstreamer-how-to-import-typelib
|
||||
(defvar *gstreamer* (gir:require-namespace "Gst"))
|
||||
@@ -68,9 +75,10 @@
|
||||
(format nil "pipewiresrc path=~A ! videoconvert ! videobox name=move ! autovideosink" stream-num)
|
||||
;"playbin uri=https://gstreamer.freedesktop.org/data/media/sintel_trailer-480p.webm"
|
||||
))
|
||||
(move-element (gir:invoke (pipeline 'get-by-name) "move")))
|
||||
;(move-element (gir:invoke (pipeline 'get-by-name) "move"))
|
||||
)
|
||||
(gir:invoke (pipeline 'set-state) (gir:nget *gstreamer* "State" :playing))
|
||||
(values pipeline move-element)))
|
||||
pipeline))
|
||||
|
||||
;; well, pipewire is not part of what's added to env
|
||||
;; not sure if i can add it
|
||||
@@ -113,7 +121,7 @@
|
||||
(sink (gir:invoke (*gstreamer* "ElementFactory" 'make) "autovideosink" "sink")))
|
||||
(when stream-num
|
||||
;; Set pipewiresrc properties, such as the path
|
||||
(gir:invoke (source 'set-property) 'path stream-num))
|
||||
(setf (gir:property source 'path) (format nil "~A" stream-num)))
|
||||
|
||||
;; Add and link elements in the pipeline
|
||||
(gir:invoke (pipeline 'add) source)
|
||||
|
||||
Reference in New Issue
Block a user