Changeset - a60a73463ef0
[Not reviewed]
default
0 4 0
drewp@bigasterisk.com - 15 years ago 2010-06-09 07:05:40
drewp@bigasterisk.com
vidref now pretty much saves and loads frames
Ignore-this: 80fa2ddda0ae744071cd43b9a16fdc18
4 files changed with 72 insertions and 68 deletions:
0 comments (0 inline, 0 general)
light9/networking.py
Show inline comments
 
@@ -11,8 +11,12 @@ def dmxServerUrl():
 
def dmxServerPort():
 
    return 8030
 
    
 
def musicUrl():
 
    return "http://score:%s" % musicPort()
 
def musicUrl(api='xmlrpc'):
 
    site = "http://dash:%s/" % musicPort()
 
    if api == 'rest':
 
        return site + "api/"
 
    else:
 
        return site + "RPC2"
 

	
 
def musicPort():
 
    return 8040
light9/showconfig.py
Show inline comments
 
@@ -41,7 +41,8 @@ def findMpdHome():
 
    including trailing slash"""
 
    
 
    mpdHome = None
 
    for mpdConfFilename in ["~/.mpdconf", "/etc/mpd.conf"]:
 
    for mpdConfFilename in ["/my/dl/modified/mpd/src/mpdconf-testing",
 
                            "~/.mpdconf", "/etc/mpd.conf"]:
 
        try:
 
            mpdConfFile = open(path.expanduser(mpdConfFilename))
 
        except IOError:
 
@@ -76,7 +77,10 @@ def songInMpd(song):
 
def songOnDisk(song):
 
    """given a song URI, where's the on-disk file that mpd would read?"""
 
    graph = getGraph()
 
    songFullPath = path.join(findMpdHome(), graph.value(song, L9['showPath']))
 
    showPath = graph.value(song, L9['showPath'])
 
    if not showPath:
 
        raise ValueError("no mpd path found for subject=%r" % song)
 
    songFullPath = path.join(findMpdHome(), showPath)
 
    return songFullPath
 

	
 
def songFilenameFromURI(uri):
light9/vidref/main.py
Show inline comments
 
@@ -22,23 +22,7 @@ logging.basicConfig(level=logging.WARN)
 
logging.getLogger().setLevel(logging.WARN)
 
#restkit.set_logging(logging.WARN)
 

	
 
print jsonlib.loads(restkit.Resource(networking.musicUrl()).get("api/position").body, use_float=True)
 

	
 
import StringIO
 
# gtk.gdk.pixbuf_new_from_data(img.tostring() seems like it would be better
 
# http://www.daa.com.au/pipermail/pygtk/2003-June/005268.html
 
def Image_to_GdkPixbuf (image):
 
    file = StringIO.StringIO ()
 
    image.save (file, 'ppm')
 
    contents = file.getvalue()
 
    file.close ()
 
    loader = gtk.gdk.PixbufLoader ('pnm')
 
    loader.write (contents, len (contents))
 
    pixbuf = loader.get_pixbuf ()
 
    loader.close ()
 
    return pixbuf
 

	
 
existingDir = "/tmp/vidref/play-light9.bigasterisk.com_show_dance2010_song7-1276057905"
 
existingDir = "/tmp/vidref/play-light9.bigasterisk.com_show_dance2010_song7-1276065914"
 
existingFrames = sorted([Decimal(f.split('.jpg')[0])
 
                         for f in os.listdir(existingDir)])
 

	
 
@@ -57,7 +41,7 @@ class VideoRecordSink(gst.Element):
 
        self.sinkpad.set_chain_function(self.chainfunc)
 
        self.lastTime = 0
 
        
 
        self.musicResource = restkit.Resource(networking.musicUrl())
 
        self.musicResource = restkit.Resource(networking.musicUrl(api='rest'))
 

	
 
        self.imagesToSave = Queue()
 
        self.startBackgroundImageSaver(self.imagesToSave)
 
@@ -66,8 +50,8 @@ class VideoRecordSink(gst.Element):
 
        """do image saves in another thread to not block gst"""
 
        def imageSaver():
 
            while True:
 
                position, img = imagesToSave.get()
 
                self.saveImg(position, img)
 
                args = imagesToSave.get()
 
                self.saveImg(*args)
 
                imagesToSave.task_done()
 
        
 
        t = Thread(target=imageSaver)
 
@@ -79,18 +63,16 @@ class VideoRecordSink(gst.Element):
 
        self.info("%s timestamp(buffer):%d" % (pad, buffer.timestamp))
 

	
 
        try:
 
            position = jsonlib.loads(self.musicResource.get("api/position").body,
 
            position = jsonlib.loads(self.musicResource.get("position").body,
 
                                     use_float=True)
 
            if not position['song']:
 
                return gst.FLOW_OK
 
            
 

	
 
            cap = buffer.caps[0]
 
            #img = Image.fromstring('RGB', (cap['width'], cap['height']),
 
            #                       buffer.data)
 
            #self.imagesToSave.put((position, img))
 
            #pixbuf = Image_to_GdkPixbuf(img)
 
            #otherPic.set_from_pixbuf(pixbuf)
 
            img = Image.fromstring('RGB', (cap['width'], cap['height']),
 
                                   buffer.data)
 
            self.imagesToSave.put((position, img, buffer.timestamp))
 
        except:
 
            traceback.print_exc()
 

	
 
@@ -101,7 +83,7 @@ class VideoRecordSink(gst.Element):
 
        
 
        return gst.FLOW_OK
 

	
 
    def saveImg(self, position, img):
 
    def saveImg(self, position, img, bufferTimestamp):
 
        outDir = "/tmp/vidref/play-%s-%d" % (
 
            position['song'].split('://')[-1].replace('/','_'),
 
            position['started'])
 
@@ -117,15 +99,17 @@ class VideoRecordSink(gst.Element):
 
        img.save(outFilename)
 

	
 
        now = time.time()
 
        print "wrote %s delay of %.2fms" % (outFilename,
 
                                        (now - self.lastTime) * 1000)
 
        print "wrote %s delay of %.2fms %s" % (outFilename,
 
                                        (now - self.lastTime) * 1000,
 
                                               bufferTimestamp)
 
        self.lastTime = now
 

	
 
    def updateOtherFrames(self, position):
 
        inPic = self.findClosestFrame(position['t']+.15)
 
        print "load", inPic
 
        inPic = self.findClosestFrame(position['t']+.2)
 
        #print "load", inPic
 
        with gtk.gdk.lock:
 
            otherPic.set_from_file(inPic)
 
            if 0:
 
            otherPic.queue_draw_area(0,0,320,240)
 
            otherPic.get_window().process_updates(True)
 

	
 
@@ -158,7 +142,7 @@ class Main(object):
 
        ##     source = makeElem("v4l2src", "vsource")
 
        ##     source.set_property("device", "/dev/video0")
 

	
 
        dv = "dv1394src ! dvdemux ! dvdec ! videoscale ! video/x-raw-yuv,width=320"
 
        dv = "dv1394src ! dvdemux ! dvdec ! videoscale ! video/x-raw-yuv,width=320,height=240;video/x-raw-rgb,width=320,height=240 ! queue name=vid"
 
        v4l = "v4l2src device=/dev/video0 ! hqdn3d name=vid" 
 

	
 
        pipeline = gst.parse_launch(dv)
light9/vidref/vidref.glade
Show inline comments
 
@@ -9,46 +9,25 @@
 
      <object class="GtkFixed" id="fixed1">
 
        <property name="visible">True</property>
 
        <child>
 
          <object class="GtkLabel" id="label1">
 
            <property name="width_request">85</property>
 
            <property name="height_request">20</property>
 
            <property name="visible">True</property>
 
            <property name="yalign">0.47999998927116394</property>
 
            <property name="label" translatable="yes">Live view</property>
 
          </object>
 
          <packing>
 
            <property name="x">5</property>
 
            <property name="y">16</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkImage" id="liveVideo">
 
            <property name="width_request">474</property>
 
            <property name="height_request">291</property>
 
            <property name="visible">True</property>
 
          </object>
 
          <packing>
 
            <property name="x">6</property>
 
            <property name="y">40</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkFrame" id="frame1">
 
            <property name="width_request">338</property>
 
            <property name="height_request">269</property>
 
            <property name="width_request">336</property>
 
            <property name="height_request">277</property>
 
            <property name="visible">True</property>
 
            <property name="label_xalign">0</property>
 
            <property name="shadow_type">out</property>
 
            <child>
 
              <object class="GtkAlignment" id="alignment1">
 
              <object class="GtkFixed" id="fixed2">
 
                <property name="visible">True</property>
 
                <property name="left_padding">12</property>
 
                <child>
 
                  <object class="GtkDrawingArea" id="vid3">
 
                    <property name="width_request">100</property>
 
                    <property name="height_request">80</property>
 
                    <property name="width_request">320</property>
 
                    <property name="height_request">240</property>
 
                    <property name="visible">True</property>
 
                  </object>
 
                  <packing>
 
                    <property name="x">7</property>
 
                    <property name="y">8</property>
 
                  </packing>
 
                </child>
 
              </object>
 
            </child>
 
@@ -61,8 +40,41 @@
 
            </child>
 
          </object>
 
          <packing>
 
            <property name="x">496</property>
 
            <property name="y">41</property>
 
            <property name="x">15</property>
 
            <property name="y">10</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkFrame" id="frame2">
 
            <property name="width_request">336</property>
 
            <property name="height_request">259</property>
 
            <property name="visible">True</property>
 
            <property name="label_xalign">0</property>
 
            <property name="shadow_type">out</property>
 
            <child>
 
              <object class="GtkAlignment" id="alignment1">
 
                <property name="visible">True</property>
 
                <property name="left_padding">12</property>
 
                <child>
 
                  <object class="GtkImage" id="liveVideo">
 
                    <property name="width_request">320</property>
 
                    <property name="height_request">240</property>
 
                    <property name="visible">True</property>
 
                  </object>
 
                </child>
 
              </object>
 
            </child>
 
            <child type="label">
 
              <object class="GtkLabel" id="label3">
 
                <property name="visible">True</property>
 
                <property name="label" translatable="yes">&lt;b&gt;Playback 1&lt;/b&gt;</property>
 
                <property name="use_markup">True</property>
 
              </object>
 
            </child>
 
          </object>
 
          <packing>
 
            <property name="x">373</property>
 
            <property name="y">23</property>
 
          </packing>
 
        </child>
 
      </object>
0 comments (0 inline, 0 general)