Example #1
0
 def stop_record(self):
     a = gst.structure_from_string('letpass')
     event = gst.event_new_custom(gst.EVENT_EOS, a)
     for bin_name, bin in self.bins.iteritems():
         resultado = bin.send_event_to_src(event)
         #if resultado:
         #    print "EOS sended to src of: " + bin_name
     return True
Example #2
0
 def stop_record(self):
     a = gst.structure_from_string("letpass")
     event = gst.event_new_custom(gst.EVENT_EOS, a)
     for bin_name, bin in self.bins.iteritems():
         resultado = bin.send_event_to_src(event)
         # if resultado:
         #    print "EOS sended to src of: " + bin_name
     return True
Example #3
0
 def stop_record(self):
     self.__duration = self.__query_position() - self.__start_record_time
     a = gst.structure_from_string('letpass')
     event = gst.event_new_custom(gst.EVENT_EOS, a)
     for bin_name, bin in self.bins.iteritems():
         resultado = bin.send_event_to_src(event)
         #if resultado: 
         #    print "EOS sended to src of: " + bin_name
     return True
Example #4
0
 def stop_record_and_restart_preview(self):
     logger.debug("Stopping Recording and Restarting Preview")
     a = gst.structure_from_string('letpass')
     event = gst.event_new_custom(gst.EVENT_EOS, a)
     for bin_name, bin in self.bins.iteritems():
         resultado = bin.send_event_to_src(event)
         #if resultado: 
         #    print "EOS sended to src of: " + bin_name
     self.restart = True  # FIXME send user_data on the EOS to force restart
     if self.pipeline.get_state()[1] == gst.STATE_PAUSED: 
         # If paused ensure sending EOS
         self.pipeline.set_state(gst.STATE_PLAYING)
     return True
Example #5
0
 def stop_record_and_restart_preview(self):
     log.debug("Stopping Recording and Restarting Preview")
     a = gst.structure_from_string('letpass')
     event = gst.event_new_custom(gst.EVENT_EOS, a)
     for bin_name, bin in self.bins.iteritems():
         resultado = bin.send_event_to_src(event)
         #if resultado:
         #    print "EOS sended to src of: " + bin_name
     self.restart = True  # FIXME send user_data on the EOS to force restart
     if self.pipeline.get_state()[1] == gst.STATE_PAUSED:
         # If paused ensure sending EOS
         self.pipeline.set_state(gst.STATE_PLAYING)
     return True
Example #6
0
File: bin.py Project: clones/kaa
    def __init__(self):
        gst.Bin.__init__(self, 'v4lsrcbin_%d')
        self._device = '/dev/video0'
        self._norm = 'NTSC'
        self._tuner = Tuner(self._device, self._norm)
        self._src = gst.element_factory_make('v4lsrc')
        self._src.set_property('device', self._device)
        self._queue = gst.element_factory_make('queue')
        self.add(self._src, self._queue)

        # FIXME: make this a property
        size = 'width=%s,height=%s' % (720, 576)
        caps = gst.structure_from_string('video/x-raw-yuv,%s' % size)
        self._src.link_pads_filtered('src', self._queue, 'sink', gst.Caps(caps))

        pad = self._queue.get_pad('src')
        self._ghost = gst.GhostPad(pad.get_name(), pad)
        self.add_pad(self._ghost)
        self._chanlist = None
Example #7
0
    def get_pipeline_string(self, properties):
        # setup the properties
        self.bus = None
        self.videowidth = properties.get('width', 240)
        self.videoheight = properties.get(
            'height', int(576 * self.videowidth/720.))
        self.videoframerate = properties.get('framerate', (25, 2))
        self.filelocation = properties.get('location')

        vstruct = gst.structure_from_string(
            "video/x-raw-yuv,width=%(width)d,height=%(height)d" %
            dict(width=self.videowidth, height=self.videoheight))
        vstruct['framerate'] = gst.Fraction(self.videoframerate[0],
                                            self.videoframerate[1])

        vcaps = gst.Caps(vstruct)

        self.run_discoverer()

        template = (
            'filesrc location=%(location)s'
            '       ! oggdemux name=demux'
            '    demux. ! queue ! theoradec name=theoradec'
            '       ! identity name=videolive single-segment=true silent=true'
            '       ! videorate name=videorate'
            '       ! videoscale'
            '       ! %(vcaps)s'
            '       ! identity name=vident sync=true silent=true'
            '       ! @feeder:video@'
            '    demux. ! queue ! vorbisdec name=vorbisdec'
            '       ! identity name=audiolive single-segment=true silent=true'
            '       ! audioconvert'
            '       ! audio/x-raw-int,width=16,depth=16,signed=(boolean)true'
            '       ! identity name=aident sync=true silent=true'
            '       ! @feeder:audio@'
            % dict(location=self.filelocation, vcaps=vcaps))

        return template
Example #8
0
    def get_pipeline_string(self, properties):
        # setup the properties
        self.bus = None
        self.videowidth = properties.get('width', 240)
        self.videoheight = properties.get(
            'height', int(576 * self.videowidth/720.))
        self.videoframerate = properties.get('framerate', (25, 2))
        self.filelocation = properties.get('location')

        vstruct = gst.structure_from_string(
            "video/x-raw-yuv,width=%(width)d,height=%(height)d" %
            dict(width=self.videowidth, height=self.videoheight))
        vstruct['framerate'] = gst.Fraction(self.videoframerate[0],
                                            self.videoframerate[1])

        vcaps = gst.Caps(vstruct)

        self.run_discoverer()

        template = (
            'filesrc location=%(location)s'
            '       ! oggdemux name=demux'
            '    demux. ! queue ! theoradec name=theoradec'
            '       ! identity name=videolive single-segment=true silent=true'
            '       ! videorate name=videorate'
            '       ! videoscale'
            '       ! %(vcaps)s'
            '       ! identity name=vident sync=true silent=true'
            '       ! @feeder:video@'
            '    demux. ! queue ! vorbisdec name=vorbisdec'
            '       ! identity name=audiolive single-segment=true silent=true'
            '       ! audioconvert'
            '       ! audio/x-raw-int,width=16,depth=16,signed=(boolean)true'
            '       ! identity name=aident sync=true silent=true'
            '       ! @feeder:audio@'
            % dict(location=self.filelocation, vcaps=vcaps))

        return template
Example #9
0
    def get_pipeline_string(self, properties):
        capsString = properties.get('format', 'video/x-raw-yuv')

        if capsString == 'video/x-raw-yuv':
            capsString = '%s,format=(fourcc)I420' % capsString

        # Filtered caps
        struct = gst.structure_from_string(capsString)
        for k in 'width', 'height':
            if k in properties:
                struct[k] = properties[k]

        if 'framerate' in properties:
            framerate = properties['framerate']
            struct['framerate'] = gst.Fraction(framerate[0], framerate[1])

        # always set par
        struct['pixel-aspect-ratio']= gst.Fraction(1, 1)
        if 'pixel-aspect-ratio' in properties:
            par = properties['pixel-aspect-ratio']
            struct['pixel-aspect-ratio'] = gst.Fraction(par[0], par[1])

        # If RGB, set something ffmpegcolorspace can convert.
        if capsString == 'video/x-raw-rgb':
            struct['red_mask'] = 0xff00
        caps = gst.Caps(struct)

        is_live = 'is-live=true'

        overlay = ""
        overlayTimestamps = properties.get('overlay-timestamps', False)
        if overlayTimestamps:
            overlay = " timeoverlay ! "

        return "videotestsrc %s name=source ! " % is_live + overlay + \
            "identity name=identity silent=TRUE ! %s" % caps
Example #10
0
    def get_pipeline_string(self, properties):
        capsString = properties.get('format', 'video/x-raw-yuv')

        if capsString == 'video/x-raw-yuv':
            capsString = '%s,format=(fourcc)I420' % capsString

        # Filtered caps
        struct = gst.structure_from_string(capsString)
        for k in 'width', 'height':
            if k in properties:
                struct[k] = properties[k]

        if 'framerate' in properties:
            framerate = properties['framerate']
            struct['framerate'] = gst.Fraction(framerate[0], framerate[1])

        # always set par
        struct['pixel-aspect-ratio'] = gst.Fraction(1, 1)
        if 'pixel-aspect-ratio' in properties:
            par = properties['pixel-aspect-ratio']
            struct['pixel-aspect-ratio'] = gst.Fraction(par[0], par[1])

        # If RGB, set something ffmpegcolorspace can convert.
        if capsString == 'video/x-raw-rgb':
            struct['red_mask'] = 0xff00
        caps = gst.Caps(struct)

        is_live = 'is-live=true'

        overlay = ""
        overlayTimestamps = properties.get('overlay-timestamps', False)
        if overlayTimestamps:
            overlay = " timeoverlay ! "

        return "videotestsrc %s name=source ! " % is_live + overlay + \
            "identity name=identity silent=TRUE ! %s" % caps
Example #11
0
            # hack to get a GstDate which we cannot instantiate directly in
            # 0.10.15.1
            # FIXME: The dates are strings and must have the format 'YYYY',
            # 'YYYY-MM' or 'YYYY-MM-DD'.
            # GstDate expects a full date, so default to
            # Jan and 1st if MM and DD are missing
            date = self.metadata.release
            if date:
                log.debug('metadata',
                    'Converting release date %r to structure', date)
                if len(date) == 4:
                    date += '-01'
                if len(date) == 7:
                    date += '-01'

                s = gst.structure_from_string('hi,date=(GstDate)%s' %
                    str(date))
                ret[gst.TAG_DATE] = s['date']

            # no musicbrainz info for htoa tracks
            if number > 0:
                ret["musicbrainz-trackid"] = mbidTrack
                ret["musicbrainz-artistid"] = mbidTrackArtist
                ret["musicbrainz-albumid"] = mbidAlbum
                ret["musicbrainz-albumartistid"] = mbidTrackAlbum
                ret["musicbrainz-discid"] = mbDiscId

        # FIXME: gst.TAG_ISRC

        return ret

    def getHTOA(self):
Example #12
0
            # hack to get a GstDate which we cannot instantiate directly in
            # 0.10.15.1
            # FIXME: The dates are strings and must have the format 'YYYY',
            # 'YYYY-MM' or 'YYYY-MM-DD'.
            # GstDate expects a full date, so default to
            # Jan and 1st if MM and DD are missing
            date = self.metadata.release
            if date:
                log.debug('metadata',
                          'Converting release date %r to structure', date)
                if len(date) == 4:
                    date += '-01'
                if len(date) == 7:
                    date += '-01'

                s = gst.structure_from_string('hi,date=(GstDate)%s' %
                                              str(date))
                ret[gst.TAG_DATE] = s['date']

            # no musicbrainz info for htoa tracks
            if number > 0:
                ret["musicbrainz-trackid"] = mbidTrack
                ret["musicbrainz-artistid"] = mbidTrackArtist
                ret["musicbrainz-albumid"] = mbidAlbum
                ret["musicbrainz-albumartistid"] = mbidTrackAlbum
                ret["musicbrainz-discid"] = mbDiscId

        # FIXME: gst.TAG_ISRC

        return ret

    def getHTOA(self):
Example #13
0
            #     ret[gst.TAG_TRACK_COUNT] = len(self.metadata.tracks)
            # hack to get a GstDate which we cannot instantiate directly in
            # 0.10.15.1
            # FIXME: The dates are strings and must have the format 'YYYY',
            # 'YYYY-MM' or 'YYYY-MM-DD'.
            # GstDate expects a full date, so default to
            # Jan and 1st if MM and DD are missing
            date = self.metadata.release
            if date:
                log.debug("metadata", "Converting release date %r to structure", date)
                if len(date) == 4:
                    date += "-01"
                if len(date) == 7:
                    date += "-01"

                s = gst.structure_from_string("hi,date=(GstDate)%s" % str(date))
                ret[gst.TAG_DATE] = s["date"]

            # no musicbrainz info for htoa tracks
            if number > 0:
                ret["musicbrainz-trackid"] = mbidTrack
                ret["musicbrainz-artistid"] = mbidTrackArtist
                ret["musicbrainz-albumid"] = mbidAlbum
                ret["musicbrainz-albumartistid"] = mbidTrackAlbum
                ret["musicbrainz-discid"] = mbDiscId

        # FIXME: gst.TAG_ISRC

        return ret

    def getHTOA(self):
Example #14
0
    exit(-1)

# Start the pipeline
ret = pipeline.set_state(gst.STATE_PLAYING)
if ret ==  gst.STATE_CHANGE_FAILURE:
    print "Unable to set the pipeline to the playing state."
    exit(-1)

# Wait until error or EOS
bus = pipeline.get_bus()
bus.add_signal_watch()

# Gracefully break on ctrl+c
def sigint_handler(signum, frame):
    pipeline.set_state(gst.STATE_NULL)
    print "Ending video stream..."
    sys.exit()
 
signal.signal(signal.SIGINT, sigint_handler)

# Create keyframe event 
struct = gst.structure_from_string('GstForceKeyUnit')
event = gst.event_new_custom (gst.EVENT_CUSTOM_DOWNSTREAM, struct)

while True:
    # Send a force keyframe event every second to allow syncing
    pipeline.send_event(event)
    sleep(1)

# Free resources
pipeline.set_state(gst.STATE_NULL)