[gst-devel] Save a stream to different file every hour

Eric Streit eric at yojik.eu
Wed Jun 17 20:13:20 CEST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi again,

the file joined is not the good one, excuse me: here is the good one.

Eric!
- ----

#!/usr/bin/env python
# -*- coding: UTF8 -*-

import pygst
pygst.require("0.10")
import gst
import pygtk
# obligatoire pour être portable sur les install qui ont aussi pygtk1:
pygtk.require("2.0")
import gtk
import gtk.glade
import os, sys

class Main(object):

    def __init__(self):
        self.wTree = gtk.glade.XML("gui.glade", "mainwindow")
        signals = {
            "on_play_clicked" : self.OnPlay,
            "on_stop_clicked" : self.OnStop,
            "on_quit_clicked" : self.OnQuit,
        }
        self.wTree.signal_autoconnect(signals)

        self.pipeline = gst.Pipeline("mypipeline")

        self.source = gst.element_factory_make("alsasrc","audio")
        self.pipeline.add(self.source)

        self.convert =
gst.element_factory_make("audioconvert","audioconvert")
        self.pipeline.add(self.convert)

        self.cutter = gst.element_factory_make ("cutter", "cutter");
        self.cutter.set_property("threshold-dB", -25.0)
        self.cutter.set_property("run-length", 300000000)
        self.cutter.set_property("pre-length", 100000000 )
        self.cutter.set_property("leaky", False)
        self.pipeline.add(self.cutter)


        self.sink = gst.element_factory_make("fdsink", "fdsink")
	    # 1ère différence: au départ, tout envoyer dans /dev/null
        self.sink.set_property("fd", self.createTargetFD())
        self.pipeline.add(self.sink)

        self.source.link(self.convert)
        self.convert.link(self.cutter)
        self.cutter.link(self.sink)

        self.bus = self.pipeline.get_bus()
        self.bus.add_signal_watch();
        self.bus.connect('message::element',self.message_handler )

        self.window = self.wTree.get_widget("mainwindow")
        self.window.show_all()
        # en bonus: démo d'un "générateur" !
        self.nameGen = self.generateFormatted ("tata%03d.raw")

    def generateFormatted (self,format="%d", next=1, step=1) :
	    while True :
	        yield format % next
	        next = next+step

    def createTargetFD (self) :
	    # TODO: error management
        #self.targetFile = open ("/dev/null","w")
        #self.targetFD = self.targetFile.fileno()
	    # ou plus directement:
	    self.targetName = "/dev/null"
	    self.targetFD = os.open (self.targetName, os.O_WRONLY)
	    print "init target fd=%s -=> %s" % (self.targetFD, self.targetName)
	    return self.targetFD

    def message_handler(self,l_bus,l_message):
        if  l_message.structure.get_name() == 'cutter':
            st = l_message.structure
            niveau = "below"
            if st['above']:
                niveau = 'above'
                self.changeTargetFile (self.nameGen.next ())
            else:
    	        self.changeTargetFile ()
                #print niveau, " ", gst.TIME_ARGS(st['timestamp'])
        return True

    def changeTargetFile (self,name="/dev/null") :
	    # TODO: error management
	    print "change target -=>", name
	    fd = os.open (name, os.O_WRONLY|os.O_CREAT)
	    os.dup2 (fd, self.targetFD)
	    os.close (fd) # ne pas oublier de fermer après duplication
	    self.targetName = name

    def affiche(self):
        print "*"

    def OnPlay(self, widget):
        print "Record"
        self.pipeline.set_state(gst.STATE_PLAYING)

    def OnStop(self, widget):
        print "Stop"
        self.pipeline.set_state(gst.STATE_READY)

    def OnQuit(self, widget):
        gtk.main_quit()

start=Main()
gtk.main()


Eric Streit a écrit :
> hi,
> 
> I do it differently: here is the python program which implement the
> feature you're looking for.
> 
> Eric!
> ----
> 
> 
> 
> Viraj Karandikar a écrit :
>> Hi Jura,
>> I guess to have this functionality you will have to write C code for
>> creating a pipeline.
>> And after every hour you will have to: pause the pipeline, create new
>> filesink, disconnect old filesink, connect new filesink and close old
>> filesink.
>> You can do above things in another independent thread which will just
>> wait till 1 hour is complete.
> 
>> Regards,
>> Viraj
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAko5MkAACgkQkouUNm4lemxyEwCgjaWk5lbCpCDfHLV9Yqb5O5CH
1mcAn2v0PHk1ah93ZGQyOaBkULMGILyY
=1XED
-----END PGP SIGNATURE-----




More information about the gstreamer-devel mailing list