diff bin/vidref @ 1939:6f49dc917aa3

start vidref web version. v4l camera frames to web page is working Ignore-this: 34bcc3b6149a1a3bed31aa5f32a4ddc6
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 03 Jun 2019 09:50:29 +0000
parents 3c523c71da29
children 0dc3715050cf
line wrap: on
line diff
--- a/bin/vidref	Sun Jun 02 21:36:57 2019 +0000
+++ b/bin/vidref	Mon Jun 03 09:50:29 2019 +0000
@@ -1,22 +1,29 @@
 #!bin/python
+"""
+Camera images of the stage. View live on a web page and also save
+them to disk. Retrieve images based on the song and time that was
+playing when they were taken. Also, save snapshot images to a place
+they can be used again as thumbnails of effects.
+
+bin/vidref main
+light9/vidref/videorecorder.py capture frames and save them
+light9/vidref/replay.py backend for vidref.js playback element- figures out which frames go with the current song and time
+light9/vidref/index.html web ui for watching current stage and song playback
+light9/vidref/setup.html web ui for setup of camera params and frame crop
+light9/web/vidref.js LitElement for video playback
+
+"""
 from run_local import log
-import sys
-sys.path.append('/usr/lib/python2.7/dist-packages')  # For gtk
-from twisted.internet import gtk2reactor
-gtk2reactor.install()
+
 from twisted.internet import reactor, defer
-import gobject
-gobject.threads_init()
-import sys, logging, optparse, json
+
+import logging, optparse, json, base64
 import cyclone.web, cyclone.httpclient, cyclone.websocket
 from light9 import networking
-from light9.vidref.main import Gui
 from light9.vidref.replay import snapshotDir
+from light9.vidref import videorecorder
 from rdfdb.syncedgraph import SyncedGraph
-
-# find replay dirs correctly. show multiple
-# replays. trash. reorder/pin. dump takes that are too short; they're
-# just from seeking
+from io import BytesIO
 
 parser = optparse.OptionParser()
 parser.add_option("-v", "--verbose", action="store_true", help="logging.DEBUG")
@@ -47,6 +54,33 @@
             raise
 
 
+pipeline = videorecorder.GstSource(
+    '/dev/v4l/by-id/usb-Generic_FULL_HD_1080P_Webcam_200901010001-video-index0')
+
+
+class Live(cyclone.websocket.WebSocketHandler):
+
+    def connectionMade(self, *args, **kwargs):
+        pipeline.liveImages.subscribe(on_next=self.onFrame)
+
+    def connectionLost(self, reason):
+        0  #self.subj.dispose()
+
+    def onFrame(self, t_img):
+        t, img = t_img
+        if img is None: return
+        output = BytesIO()
+        img.save(output, 'jpeg', quality=80)
+
+        self.sendMessage(
+            json.dumps({
+                'jpeg':
+                base64.b64encode(output.getvalue()).decode('ascii'),
+                'description':
+                f't={t}',
+            }))
+
+
 class SnapshotPic(cyclone.web.StaticFileHandler):
     pass
 
@@ -63,24 +97,28 @@
 
 graph = SyncedGraph(networking.rdfdb.url, "vidref")
 
-gui = Gui(graph)
-
 port = networking.vidref.port
 reactor.listenTCP(
     port,
-    cyclone.web.Application(handlers=[
-        (r'/()', cyclone.web.StaticFileHandler, {
-            'path': 'light9/vidref',
-            'default_filename': 'vidref.html'
-        }),
-        (r'/snapshot', Snapshot),
-        (r'/snapshot/(.*)', SnapshotPic, {
-            "path": snapshotDir()
-        }),
-        (r'/time', Time),
-    ],
-                            debug=True,
-                            gui=gui))
+    cyclone.web.Application(
+        handlers=[
+            (r'/()', cyclone.web.StaticFileHandler, {
+                'path': 'light9/vidref',
+                'default_filename': 'vidref.html'
+            }),
+            (r'/setup/()', cyclone.web.StaticFileHandler, {
+                'path': 'light9/vidref',
+                'default_filename': 'setup.html'
+            }),
+            (r'/setup/live', Live),
+            (r'/snapshot', Snapshot),
+            (r'/snapshot/(.*)', SnapshotPic, {
+                "path": snapshotDir()
+            }),
+            (r'/time', Time),
+        ],
+        debug=True,
+    ))
 log.info("serving on %s" % port)
 
 reactor.run()