def on_new_pad(self, element, pad): padname = pad.get_name() caps = pad.get_caps() name = caps[0].get_name() bin = None queue = None if 'video' in name and not self.has_video: bin = gst.parse_bin_from_description(self.VIDEO_BIN, False) if bin: queue = bin.get_by_name("vqueue") self.has_video = True elif 'audio' in name and not self.has_audio: bin = gst.parse_bin_from_description(self.AUDIO_BIN, False) if bin: queue = bin.get_by_name("aqueue") self.has_audio = True if bin and queue: targetpad = queue.get_pad('sink') ghostpad = gst.GhostPad('sink', targetpad) bin.add_pad(ghostpad) self.bin.add(bin) bin.set_state(gst.STATE_READY) pad.link(ghostpad) bin.sync_state_with_parent() # ensure to preroll the sinks self.bin.lost_state_full(True)
def __on_stream_created(self, channel, stream): """ On signal "stream-created">, connect signals on stream and add source. Then we link the stream's sink-pad to source's src-pad. """ print print "=== %s __on_stream_created ===" % self print stream.connect('src-pad-added', self.__on_src_pad_added) stream.connect('closed', debug_callback, "closed") # Not used stream.connect('error', debug_callback, "error") # Not used stream.connect('free-resource', debug_callback, "free") # Not used # creating src pipes type = stream.get_property("media-type") if type == farsight.MEDIA_TYPE_AUDIO: source = gst.parse_bin_from_description("autoaudiosrc", True) elif type == farsight.MEDIA_TYPE_VIDEO: source = gst.parse_bin_from_description( "v4l2src ! ffmpegcolorspace ! videoscale ! video/x-raw-yuv,width=320,height=240 ! ffmpegcolorspace", True) self.pipeline.add(source) source.get_pad("src").link(stream.get_property("sink-pad")) source.set_state(gst.STATE_PLAYING)
def _trySetupDecoder(cls, ext, dec): # FIXME might even save the bin's already, not just the description try: gst.parse_bin_from_description(dec, 0) except gobject.GError, e: logger.warning("GST can't parse %s; Not adding %s to decoderMap" % (dec, ext)) return False
def src_pad_added (self, stream, pad, codec): type = stream.get_property ("media-type") if type == farsight.MEDIA_TYPE_AUDIO: sink = gst.parse_bin_from_description("audioconvert ! audioresample ! audioconvert ! autoaudiosink", True) elif type == farsight.MEDIA_TYPE_VIDEO: sink = gst.parse_bin_from_description("ffmpegcolorspace ! videoscale ! autovideosink", True) self.pipeline.add(sink) pad.link(sink.get_pad("sink")) sink.set_state(gst.STATE_PLAYING)
def Main(file_path, cue_points): import gobject import sys pipeline = gst.Pipeline("pipeline") filesrc = CuePointsFileSrc() filesrc.set_property("location", file_path) filesrc.set_property("cuepoints", cue_points) filesrc.set_property("seek-guard", 2*gst.SECOND) videosink = gst.parse_bin_from_description( "queue max-size-time=0 name=vid_queue ! autovideosink sync=true", True) audiosink = gst.parse_bin_from_description( "queue max-size-time=0 name=aud_queue ! autoaudiosink sync=true", True) def on_new_pad(element, pad): caps = str(pad.get_caps()) if "video" in caps: pad.set_active(True) pad.link(videosink.get_pad("sink")) elif "audio" in caps: pad.set_active(True) pad.link(audiosink.get_pad("sink")) pipeline.add(filesrc) pipeline.add(audiosink) pipeline.add(videosink) def on_error(bus, message): _, m = message.parse_error() pipeline.set_state(gst.STATE_NULL) sys.exit(1) def on_eos(bus, message): pipeline.set_state(gst.STATE_NULL) sys.exit(0) bus = pipeline.get_bus() bus.add_signal_watch() bus.connect("message::eos", on_eos) bus.connect("message::error", on_error) filesrc.connect("pad-added", on_new_pad) pipeline.set_state(gst.STATE_PLAYING) gobject.threads_init() gobject.MainLoop().run()
def __on_src_pad_added(self, stream, pad, codec): """ On signal "src-pad-added", we display stream view """ print print "=== %s __src_pad_added ===" % self print type = stream.get_property("media-type") if type == farsight.MEDIA_TYPE_AUDIO: queue_sink = gst.parse_bin_from_description( "queue ! audioconvert ! audioresample ! audioconvert ! autoaudiosink", True) audioadder = gst.element_factory_make("liveadder") tee = gst.element_factory_make("tee") # Add & Link self.pipeline.add(audioadder, tee, queue_sink) gst.element_link_many(audioadder, tee, queue_sink) pad.link(audioadder.get_pad("sink%d")) queue_sink.set_state(gst.STATE_PLAYING) tee.set_state(gst.STATE_PLAYING) audioadder.set_state(gst.STATE_PLAYING) elif type == farsight.MEDIA_TYPE_VIDEO: queue_ff = gst.parse_bin_from_description( "queue ! ffmpegcolorspace", True) sink = gst.parse_bin_from_description( "videoscale ! video/x-raw-yuv,width=320,height=240 ! autovideosink", True) videofunnel = gst.element_factory_make("fsfunnel") tee = gst.element_factory_make("tee") # Add & Link self.pipeline.add(videofunnel, tee, queue_ff, sink) gst.element_link_many(videofunnel, tee, queue_ff, sink) pad.link(videofunnel.get_pad("sink%d")) sink.set_state(gst.STATE_PLAYING) queue_ff.set_state(gst.STATE_PLAYING) tee.set_state(gst.STATE_PLAYING) videofunnel.set_state(gst.STATE_PLAYING) self.pipeline.set_state(gst.STATE_PLAYING)
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) aux = pipestr.replace('gc-v4l2-preview', 'sink-' + self.options['name']) if 'image/jpeg' in self.options['caps']: aux = aux.replace('gc-v4l2-dec', 'jpegdec ! queue !') else: aux = aux.replace('gc-v4l2-dec', '') bin = gst.parse_bin_from_description(aux, True) self.add(bin) self.set_option_in_pipeline('location', 'gc-v4l2-src', 'device') #element = self.get_by_name('gc-v4l2-src') #element.set_property('device', self.options['location']) self.set_value_in_pipeline(path.join(self.options['path'], self.options['file']), 'gc-v4l2-sink', 'location') #element = self.get_by_name('gc-v4l2-sink') #element.set_property('location', path.join(self.options['path'], self.options['file'])) self.set_option_in_pipeline('caps', 'gc-v4l2-filter', 'caps', gst.Caps) #element = self.get_by_name('gc-v4l2-filter') #element.set_property('caps', gst.Caps(self.options['caps'])) fr = re.findall("framerate *= *[0-9]+/[0-9]+", self.options['caps']) if fr: newcaps = 'video/x-raw-yuv,' + fr[0] self.set_value_in_pipeline(newcaps, 'gc-v4l2-vrate', 'caps', gst.Caps) #element2 = self.get_by_name('gc-v4l2-vrate') #element2.set_property('caps', gst.Caps(newcaps)) for pos in ['right','left','top','bottom']: self.set_option_in_pipeline('videocrop-'+pos, 'gc-v4l2-crop', pos, int)
def main(): sink = "autoaudiosink" if in_pathlist("gstreamer-properties"): sink = "gconfaudiosink" try: options, arguments = getopt.getopt(sys.argv[1:], "h", ["help", "sink="]) except getopt.GetoptError as er: print er print_help() sys.exit() for option, argument in options: if option in ("-h", "--help"): print_help() sys.exit() elif option == "--sink": print "sink", argument sink = argument config = Config(CONFIG_PATH) try: config.load() except IOError: pass sink = gst.parse_bin_from_description(sink, True) win = MainWindow(sink, config) if arguments: uri = arguments[0] if not uri.startswith("file://"): uri = "file://" + os.path.abspath(uri) win.filechooser.set_uri(uri) win.filechanged(uri=uri) win.show_all() gtk.main()
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) # Para usar con el gtk.DrawingArea bin = gst.parse_bin_from_description(pipestr.replace("gc-hauppauge-preview", "sink-" + self.options['name']), True) # bin = gst.parse_bin_from_description(pipestr.replace("gc-hauppauge-preview", "sink-" + self.options['name']), True) self.add(bin) sink = self.get_by_name("gc-hauppauge-device-src") sink.set_property("device", self.options["locprevideo"]) sink = self.get_by_name("gc-hauppauge-file-src") sink.set_property("location", self.options["location"]) sink = self.get_by_name("gc-hauppauge-audio-src") sink.set_property("location", self.options["locpreaudio"]) if self.options["player"] == False: self.mute = True element = self.get_by_name("gc-hauppauge-volume") element.set_property("mute", True) else: self.mute = False sink = self.get_by_name("gc-hauppauge-sink") sink.set_property('location', path.join(self.options['path'], self.options['file'])) if self.options["vumeter"] == False: level = self.get_by_name("gc-hauppauge-level") level.set_property("message", False)
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) # FIXME check route in conf/recorderui and define options if "background" not in self.options: background= (path.join(path.dirname(path.abspath(galicaster.__file__)), "..", "resources", "bg.png") ) else: background = (path.join(path.dirname(path.abspath(galicaster.__file__)), "..", self.options["background"])) if self.options["drivertype"] == "v4l": driver_type = "v4lsrc" else: driver_type = "v4l2src" aux = (pipestr.replace("gc-epiphan-preview", "sink-" + self.options['name']) .replace('gc-epiphan-enc', self.options['videoencoder']) .replace('gc-epiphan-mux', self.options['muxer'])) size = self.options['resolution'] width, height = [int(a) for a in size.split(re.search('[,x:]',size).group())] bin_end = gst.parse_bin_from_description(aux, True) logger.info("Setting background for Epiphan: %s", background) bin_start = Switcher("canguro", self.options['location'], background, driver_type, [width,height], self.options['framerate']) self.bin_start=bin_start self.add(bin_start, bin_end) bin_start.link(bin_end) sink = self.get_by_name("gc-epiphan-sink") sink.set_property('location', path.join(self.options['path'], self.options['file']))
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options["name"]) bin = gst.parse_bin_from_description(pipestr.replace("gc-audiotest-preview", "sink-" + self.options["name"]), True) self.add(bin) sink = self.get_by_name("gc-audiotest-sink") sink.set_property('location', path.join(self.options['path'], self.options['file'])) if "player" in self.options and self.options["player"] == False: self.mute = True element = self.get_by_name("gc-audiotest-volume") element.set_property("mute", True) else: self.mute = False if "vumeter" in self.options: level = self.get_by_name("gc-audiotest-level") if self.options["vumeter"] == False: level.set_property("message", False) if "amplification" in self.options: ampli = self.get_by_name("gc-audiotest-amplify") ampli.set_property("amplification", float(self.options["amplification"])) sink = self.get_by_name("gc-audiotest-src") sink.set_property("freq", int(self.options["frequency"])) sink.set_property("volume", float(self.options["volume"])) sink.set_property("wave", str(self.options["pattern"])) if not self.options["vumeter"]: level = self.get_by_name("gc-audiotest-level") level.set_property("message", False)
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) aux = (pipestr.replace('gc-rtp-preview', 'sink-' + self.options['name']) .replace('gc-rtp-depay', pipe_config[self.options['cameratype']]['depay']) .replace('gc-rtp-videoparse', pipe_config[self.options['cameratype']]['parse']) .replace('gc-rtp-dec', pipe_config[self.options['cameratype']]['dec']) .replace('gc-rtp-muxer', self.options['muxer'])) if self.options["audio"]: self.has_audio = True aux += (audiostr.replace("gc-rtp-audio-depay", pipe_config_audio[self.options['audiotype']]['depay']) .replace("gc-rtp-audioparse", pipe_config_audio[self.options['audiotype']]['parse']) .replace("gc-rtp-audio-dec", pipe_config_audio[self.options['audiotype']]['dec'])) else: self.has_audio = False bin = gst.parse_bin_from_description(aux, False) self.add(bin) self.set_option_in_pipeline('location', 'gc-rtp-src', 'location') self.set_value_in_pipeline(path.join(self.options['path'], self.options['file']), 'gc-rtp-sink', 'location') if self.has_audio: if "player" in self.options and self.options["player"] == False: self.mute = True element = self.get_by_name("gc-rtp-volume") element.set_property("mute", True) else: self.mute = False if "vumeter" in self.options: level = self.get_by_name("gc-rtp-level") if self.options["vumeter"] == False: level.set_property("message", False)
def _setup_mixer(self): if not settings.MIXER: logger.info("Not setting up audio mixer") return if settings.MIXER == "software": self._software_mixing = True logger.info("Audio mixer is using software mixing") return try: mixerbin = gst.parse_bin_from_description(settings.MIXER, ghost_unconnected_pads=False) except gobject.GError as ex: logger.warning('Failed to create audio mixer "%s": %s', settings.MIXER, ex) return # We assume that the bin will contain a single mixer. mixer = mixerbin.get_by_interface(b"GstMixer") if not mixer: logger.warning('Did not find any audio mixers in "%s"', settings.MIXER) return if mixerbin.set_state(gst.STATE_READY) != gst.STATE_CHANGE_SUCCESS: logger.warning('Setting audio mixer "%s" to READY failed', settings.MIXER) return track = self._select_mixer_track(mixer, settings.MIXER_TRACK) if not track: logger.warning("Could not find usable audio mixer track") return self._mixer = mixer self._mixer_track = track self._mixer_scale = (self._mixer_track.min_volume, self._mixer_track.max_volume) logger.info('Audio mixer set to "%s" using track "%s"', mixer.get_factory().get_name(), track.label)
def main(): sink = "autoaudiosink" if in_pathlist("gstreamer-properties"): sink = "gconfaudiosink" options, arguments = getopt.getopt(sys.argv[1:], "h", ["help", "sink="]) for option, argument in options: if option in ("-h", "--help"): print "Usage: playitslowly [OPTIONS]... [FILE]" print "Options:" print '--sink=sink specify gstreamer sink for playback' sys.exit() elif option == "--sink": print "sink", argument sink = argument config = Config(CONFIG_PATH) try: config.load() except IOError: pass sink = gst.parse_bin_from_description(sink, True) win = MainWindow(sink, config) if arguments: uri = arguments[0] if not uri.startswith("file://"): uri = "file://" + os.path.abspath(uri) win.filechooser.set_uri(uri) win.filechanged(uri=uri) win.show_all() gtk.main()
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) # FIXME check route in conf/recorderui and define options if "background" not in self.options: background = (path.join( path.dirname(path.abspath(galicaster.__file__)), "..", "resources", "bg.png")) else: background = (path.join( path.dirname(path.abspath(galicaster.__file__)), "..", self.options["background"])) if self.options["drivertype"] == "v4l": driver_type = "v4lsrc" else: driver_type = "v4l2src" bin_end = gst.parse_bin_from_description( pipestr.replace("gc-vga2usb-preview", "sink-" + self.options['name']), True) log.info("Setting background for Epiphan: %s", background) bin_start = Switcher("canguro", self.options['location'], background, driver_type) self.bin_start = bin_start self.add(bin_start, bin_end) bin_start.link(bin_end) sink = self.get_by_name("gc-vga2usb-sink") sink.set_property( 'location', path.join(self.options['path'], self.options['file']))
def prepare_pipeline(self): gstsink = gst.parse_bin_from_description(self.sink, True) self.pipeline = Pipeline(gstsink) self.pipeline.reset() self.pipeline.set_file("file://" + self.filepath) self.pipeline.set_speed(self.speed) self.pipeline.set_on_eos_cb(self.on_eos)
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) aux = pipestr.replace('gc-blackmagic-preview', 'sink-' + self.options['name']) bin = gst.parse_bin_from_description(aux, True) # replace identity self.add(bin) element = self.get_by_name('gc-blackmagic-sink') element.set_property( 'location', path.join(self.options['path'], self.options['file'])) element = self.get_by_name('gc-blackmagic-src') try: value = int(self.options['input']) except ValueError: value = self.options['input'] element.set_property('input', value) element = self.get_by_name('gc-blackmagic-src') try: mode = int(self.options['input-mode']) except ValueError: mode = self.options['input-mode'] element.set_property('input-mode', mode) for pos in ['right', 'left', 'top', 'bottom']: element = self.get_by_name('gc-blackmagic-crop') element.set_property(pos, int(self.options['videocrop-' + pos]))
def construct_pipeline(self): //http://svn.jejik.com/viewvc.cgi/jukebox/jukebox/trunk/audioplayer.py?view=markup playbin = self.playbin = gst.element_factory_make('playbin2') fakesink = gst.element_factory_make('fakesink') sink_description = string.Template('vorbisenc ! oggmux ! \ shout2send sync=0 mount=${mount} ip=${ip} port=${port} \ password=${password} streamname="${name}" description="${description}"') # sink_description = string.Template('lame vbr=4 ! \ # shout2send mount=${mount} ip=${ip} port=${port} \ # password=${password} streamname="${name}" description="${description}"') # sink_description = string.Template('alsasink') sink_description = sink_description.substitute( mount = self.stream.server.mount, ip = self.stream.server.host, port = self.stream.server.port, password = self.stream.server.password, name = self.stream.name, description = self.stream.description ) sink = gst.parse_bin_from_description(sink_description, True) playbin.set_property('video-sink', fakesink) playbin.set_property('audio-sink', sink) bus = playbin.get_bus() bus.add_signal_watch() bus.connect("message", self.on_message) playbin.connect('about-to-finish', self.on_about_to_finish)
def on_about_to_finish(self, playbin): try: old_uri = self.uri new_uri = self.uri = self.stream.source.get() except Exception: new_uri = self.uri = 'file://%s' % self.stream.interval_sound sink_description = string.Template('vorbisenc ! oggmux ! \ shout2send mount=${mount} ip=${ip} port=${port} \ password=${password} streamname="${name}" description="${description}"') sink_description = sink_description.substitute( mount = self.stream.server.mount, ip = self.stream.server.host, port = self.stream.server.port, password = self.stream.server.password, name = self.stream.name, description = self.stream.description ) sink = gst.parse_bin_from_description(sink_description, True) playbin.set_property('audio-sink', sink) self.playbin = playbin playbin.set_property('uri', new_uri) playbin.set_state(gst.STATE_PLAYING) self.stream.hooks.source.call('transition', old_uri, new_uri) self.stream.hooks.source.call('eof', old_uri) self.stream.hooks.source.call('start_play', new_uri)
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) aux = pipestr.replace('gc-blackmagic-preview', 'sink-' + self.options['name']) bin = gst.parse_bin_from_description(aux, True) # replace identity self.add(bin) element = self.get_by_name('gc-blackmagic-sink') element.set_property('location', path.join(self.options['path'], self.options['file'])) element = self.get_by_name('gc-blackmagic-src') try: value = int(self.options['input']) except ValueError: value = self.options['input'] element.set_property('input', value) element = self.get_by_name('gc-blackmagic-src') try: mode = int(self.options['input-mode']) except ValueError: mode = self.options['input-mode'] element.set_property('input-mode', mode) for pos in ['right','left','top','bottom']: element = self.get_by_name('gc-blackmagic-crop') element.set_property(pos, int(self.options['videocrop-' + pos]))
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) global pipestr if self.options['name'] == None: self.options['name'] = "rtp" # 2/3-2012 [email protected] use pipestr from conf.ini if it exists if "pipestr" in self.options: pipestr = self.options["pipestr"].replace("\n", " ") gst.Bin.__init__(self, self.options['name']) aux = pipestr.replace("gc-rtp-preview", "sink-" + self.options['name']) bin = gst.parse_bin_from_description(aux, False) self.add(bin) self.set_value_in_pipeline(self.options['location'], 'gc-rtp-src', 'location') self.set_value_in_pipeline( path.join(self.options['path'], self.options['file']), 'gc-rtp-sink', 'location') for opt in [ 'debug', 'protocols', 'retry', 'timeout', 'latency', 'tcp-timeout', 'connection-speed', 'nat-method', 'do-rtcp', 'proxy', 'rtp-blocksize', 'user-id', 'user-pw', 'buffer-mode', 'port-range', 'udp-buffer-size' ]: if opt in options: self.set_value_in_pipeline(self.options[opt], 'gc-rtp-src', opt)
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options["name"]) aux = (pipestr.replace("gc-audio-preview", "sink-" + self.options["name"]) .replace("gc-audio-enc", self.options["encoder"])) bin = gst.parse_bin_from_description(aux, True) self.add(bin) if self.options['location'] != "default": sink = self.get_by_name("gc-audio-src") sink.set_property("device", self.options['location']) sink = self.get_by_name("gc-audio-sink") sink.set_property('location', path.join(self.options['path'], self.options['file'])) if "player" in self.options and self.options["player"] == False: self.mute = True element = self.get_by_name("gc-audio-volume") element.set_property("mute", True) else: self.mute = False if "vumeter" in self.options: level = self.get_by_name("gc-audio-level") if self.options["vumeter"] == False: level.set_property("message", False) if "amplification" in self.options: ampli = self.get_by_name("gc-audio-amplify") ampli.set_property("amplification", float(self.options["amplification"]))
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options["name"]) bin = gst.parse_bin_from_description( pipestr.replace("gc-audio-preview", "sink-" + self.options["name"]), True) self.add(bin) if self.options['location'] != "default": sink = self.get_by_name("gc-audio-src") sink.set_property("device", self.options['location']) sink = self.get_by_name("gc-audio-sink") sink.set_property( 'location', path.join(self.options['path'], self.options['file'])) if "player" in self.options and self.options["player"] == False: self.mute = True element = self.get_by_name("gc-audio-volume") element.set_property("mute", True) else: self.mute = False if "vumeter" in self.options: level = self.get_by_name("gc-audio-level") if self.options["vumeter"] == False: level.set_property("message", False) if "amplification" in self.options: ampli = self.get_by_name("gc-audio-amplify") ampli.set_property("amplification", float(self.options["amplification"]))
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) # Para usar con el gtk.DrawingArea bin = gst.parse_bin_from_description( pipestr.replace("gc-hauppauge-preview", "sink-" + self.options['name']), True) # bin = gst.parse_bin_from_description(pipestr.replace("gc-hauppauge-preview", "sink-" + self.options['name']), True) self.add(bin) sink = self.get_by_name("gc-hauppauge-device-src") sink.set_property("device", self.options["locprevideo"]) sink = self.get_by_name("gc-hauppauge-file-src") sink.set_property("location", self.options["location"]) sink = self.get_by_name("gc-hauppauge-audio-src") sink.set_property("location", self.options["locpreaudio"]) if self.options["player"] == False: self.mute = True element = self.get_by_name("gc-hauppauge-volume") element.set_property("mute", True) else: self.mute = False sink = self.get_by_name("gc-hauppauge-sink") sink.set_property( 'location', path.join(self.options['path'], self.options['file'])) if self.options["vumeter"] == False: level = self.get_by_name("gc-hauppauge-level") level.set_property("message", False)
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) aux = pipestr.replace('gc-videotest-preview', 'sink-' + self.options['name']) # Usable by the Drawing Area bin = gst.parse_bin_from_description(aux, False) # replace identity self.add(bin) self.get_by_name('gc-videotest-sink').set_property('location', path.join(self.options['path'], self.options['file'])) #self.get_by_name('gc-videotest-filter').set_property('caps', gst.Caps(self.options['caps'])) #fr = re.findall("framerate *= *[0-9]+/[0-9]+", self.options['caps']) #if fr: # newcaps = 'video/x-raw-yuv,' + fr[0] #self.get_by_name('gc-videotest-vrate').set_property('caps', gst.Caps(newcaps)) source = self.get_by_name('gc-videotest-src') source.set_property('pattern', int(self.options['pattern'])) coloured = False for properties in gobject.list_properties(source): if properties.name == 'foreground-color': coloured = True if self.options["color1"] and coloured: source.set_property('foreground-color', int(self.options['color1']))
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options["name"]) aux = pipestr.replace("gc-blackmagic-preview", "sink-" + self.options["name"]) bin = gst.parse_bin_from_description(aux, True) # replace identity self.add(bin) element = self.get_by_name("gc-blackmagic-sink") element.set_property("location", path.join(self.options["path"], self.options["file"])) element = self.get_by_name("gc-blackmagic-src") try: value = int(self.options["input"]) except ValueError: value = self.options["input"] element.set_property("input", value) element = self.get_by_name("gc-blackmagic-src") try: mode = int(self.options["input-mode"]) except ValueError: mode = self.options["input-mode"] element.set_property("input-mode", mode) for pos in ["right", "left", "top", "bottom"]: element = self.get_by_name("gc-blackmagic-crop") element.set_property(pos, int(self.options["videocrop-" + pos]))
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) global pipestr if self.options['name'] == None: self.options['name'] = "rtp" # 2/3-2012 [email protected] use pipestr from conf.ini if it exists if "pipestr" in self.options: pipestr = self.options["pipestr"].replace("\n", " ") gst.Bin.__init__(self, self.options['name']) aux = pipestr.replace("gc-rtp-audio-preview", "sink-" + self.options['name']) bin = gst.parse_bin_from_description(aux, False) self.add(bin) self.set_value_in_pipeline(self.options['location'], 'gc-rtp-audio-src', 'location') self.set_value_in_pipeline(path.join(self.options['path'], self.options['file']), 'gc-rtp-audio-sink', 'location') for opt in ['debug', 'protocols', 'retry', 'timeout', 'latency', 'tcp-timeout', 'connection-speed', 'nat-method', 'do-rtcp', 'proxy', 'rtp-blocksize', 'user-id', 'user-pw', 'buffer-mode', 'port-range', 'udp-buffer-size']: if opt in options: self.set_value_in_pipeline(self.options[opt], 'gc-rtp-audio-src', opt) if "vumeter" in self.options and self.options["vumeter"] == "False": self.get_by_name("gc-rtp-audio-level").set_property("message", False) if "amplification" in self.options: self.get_by_name("gc-rtp-audio-amplify").set_property("amplification", float(self.options["amplification"]))
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) # FIXME check route in conf/recorderui and define options if "background" not in self.options: background= (path.join(path.dirname(path.abspath(galicaster.__file__)), "..", "resources", "bg.png") ) else: background = (path.join(path.dirname(path.abspath(galicaster.__file__)), "..", self.options["background"])) if self.options["drivertype"] == "v4l": driver_type = "v4lsrc" else: driver_type = "v4l2src" aux = (pipestr.replace("gc-vga2usb-preview", "sink-" + self.options['name']) .replace('gc-vga2usb-enc', self.options['encoder']) .replace('gc-vga2usb-mux', self.options['muxer'])) bin_end = gst.parse_bin_from_description(aux, True) log.info("Setting background for Epiphan: %s", background) bin_start = Switcher("canguro", self.options['location'], background, driver_type) self.bin_start=bin_start self.add(bin_start, bin_end) bin_start.link(bin_end) sink = self.get_by_name("gc-vga2usb-sink") sink.set_property('location', path.join(self.options['path'], self.options['file']))
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) aux = (pipestr.replace( 'gc-rtpraw-preview', 'sink-' + self.options['name']).replace( 'gc-rtpraw-depay', pipe_config[self.options['cameratype']]['depay']).replace( 'gc-rtpraw-videoparse', pipe_config[self.options['cameratype']]['parse']).replace( 'gc-rtpraw-dec', pipe_config[self.options['cameratype']] ['dec']).replace('gc-rtpraw-enc', self.options['videoencoder']).replace( 'gc-rtpraw-muxer', self.options['muxer'])) bin = gst.parse_bin_from_description(aux, False) self.add(bin) self.set_option_in_pipeline('caps', 'gc-rtpraw-filter', 'caps', gst.Caps) self.set_option_in_pipeline('location', 'gc-rtpraw-src', 'location') self.set_value_in_pipeline( path.join(self.options['path'], self.options['file']), 'gc-rtpraw-sink', 'location')
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) aux = pipestr.replace('gc-videotest-preview', 'sink-' + self.options['name']) # Usable by the Drawing Area bin = gst.parse_bin_from_description(aux, False) # replace identity self.add(bin) self.get_by_name('gc-videotest-sink').set_property( 'location', path.join(self.options['path'], self.options['file'])) #self.get_by_name('gc-videotest-filter').set_property('caps', gst.Caps(self.options['caps'])) #fr = re.findall("framerate *= *[0-9]+/[0-9]+", self.options['caps']) #if fr: # newcaps = 'video/x-raw-yuv,' + fr[0] #self.get_by_name('gc-videotest-vrate').set_property('caps', gst.Caps(newcaps)) source = self.get_by_name('gc-videotest-src') source.set_property('pattern', int(self.options['pattern'])) coloured = False for properties in gobject.list_properties(source): if properties.name == 'foreground-color': coloured = True if self.options["color1"] and coloured: source.set_property('foreground-color', int(self.options['color1']))
def __init__(self, source_pipeline_description, sink_pipeline_description): gobject.threads_init() imageprocessing = " ! ".join([ # Buffer the video stream, dropping frames if downstream # processors aren't fast enough: "queue name=q leaky=2", # Convert to a colorspace that templatematch can handle: "ffmpegcolorspace", # Detect motion when requested: "stbt-motiondetect name=motiondetect enabled=false", # OpenCV image-processing library: "stbt-templatematch name=templatematch method=1", ]) xvideo = " ! ".join([ # Convert to a colorspace that xvimagesink can handle: "ffmpegcolorspace", sink_pipeline_description, ]) screenshot = ("appsink name=screenshot max-buffers=1 drop=true " "sync=false") pipe = " ".join([ imageprocessing, "! tee name=t", "t. ! queue leaky=2 !", screenshot, "t. ! queue leaky=2 !", xvideo ]) # Gstreamer loads plugin libraries on demand, when elements that need # those libraries are first mentioned. There is a bug in gst-opencv # where it erroneously claims to provide appsink, preventing the # loading of the real appsink -- so we load it first. # TODO: Fix gst-opencv so that it doesn't prevent appsink from being # loaded. gst.parse_launch("appsink") self.source_pipeline_description = source_pipeline_description self.source_bin = self.create_source_bin() self.sink_bin = gst.parse_bin_from_description(pipe, True) self.pipeline = gst.Pipeline("stb-tester") self.pipeline.add(self.source_bin, self.sink_bin) gst.element_link_many(self.source_bin, self.sink_bin) self.templatematch = self.pipeline.get_by_name("templatematch") self.motiondetect = self.pipeline.get_by_name("motiondetect") self.screenshot = self.pipeline.get_by_name("screenshot") self.bus = self.pipeline.get_bus() self.bus.connect("message::error", self.on_error) self.bus.connect("message::warning", self.on_warning) self.bus.add_signal_watch() self.pipeline.set_state(gst.STATE_PLAYING) # Handle loss of video (but without end-of-stream event) from the # Hauppauge HDPVR capture device. self.queue = self.pipeline.get_by_name("q") self.underrun_timeout_id = None self.queue.connect("underrun", self.on_underrun) self.queue.connect("running", self.on_running)
def get_kuscheduler(self, interval): if not gstreamer.element_factory_exists('keyunitsscheduler'): register() kubin = gst.parse_bin_from_description('keyunitsscheduler interval=%s ' 'name=scheduler' % interval, True) self._kuscheduler = kubin.get_by_name('scheduler') return kubin
def _setup_output(self): try: output = gst.parse_bin_from_description(settings.OUTPUT, ghost_unconnected_pads=True) self._playbin.set_property("audio-sink", output) logger.info('Audio output set to "%s"', settings.OUTPUT) except gobject.GError as ex: logger.error('Failed to create audio output "%s": %s', settings.OUTPUT, ex) process.exit_process()
def get_kuscheduler(self, interval): if not gstreamer.element_factory_exists('keyunitsscheduler'): register() kubin = gst.parse_bin_from_description( 'keyunitsscheduler interval=%s ' 'name=scheduler' % interval, True) self._kuscheduler = kubin.get_by_name('scheduler') return kubin
def _createSourceBin(self): sourceBin = gst.parse_bin_from_description( self._sourcePipelineDescription + " ! capsfilter name=padforcer caps=video/x-raw-yuv", False) self._pad = gst.GhostPad( "source", sourceBin.get_by_name("padforcer").src_pads().next()) sourceBin.add_pad(self._pad) return sourceBin
def create_source_bin(self): source_bin = gst.parse_bin_from_description( self.source_pipeline_description + " ! capsfilter name=padforcer caps=video/x-raw-yuv", False) source_bin.add_pad( gst.GhostPad( "source", source_bin.get_by_name("padforcer").src_pads().next())) return source_bin
def build_sink(self): config = { 'mount': self.mount, 'ip': self.ip, 'port': self.port, 'password': self.password } print 'Sink config:\n%s' % config self.sink = gst.parse_bin_from_description(_GST_BIN % config, True) print 'Built sink.'
def _setup_output(self): try: output = gst.parse_bin_from_description( settings.OUTPUT, ghost_unconnected_pads=True) self._playbin.set_property('audio-sink', output) logger.info('Output set to %s', settings.OUTPUT) except gobject.GError as ex: logger.error('Failed to create output "%s": %s', settings.OUTPUT, ex) process.exit_process()
def setup_uri(self): self.reset_pipeline() # insert an identity with sleep-time to simulate a slower src when # reading from a file if 'file://' in self.uri: bin = gst.parse_bin_from_description('%s ! ' \ 'identity sleep-time=200 ! mpegtsparse ! %s' % \ (self.uri, self.DEMUX_BIN), False) else: bin = gst.parse_bin_from_description('%s ! mpegtsparse ! %s' % \ (self.uri, self.DEMUX_BIN), False) if bin: self.bin = bin demux = bin.get_by_name("demux") demux.connect('pad-added', self.on_new_pad) self.pipeline.add(bin) bin.sync_state_with_parent()
def setup_uri (self): self.reset_pipeline() # insert an identity with sleep-time to simulate a slower src when # reading from a file if 'file://' in self.uri: bin = gst.parse_bin_from_description('%s ! ' \ 'identity sleep-time=200 ! mpegtsparse ! %s' % \ (self.uri, self.DEMUX_BIN), False) else: bin = gst.parse_bin_from_description('%s ! mpegtsparse ! %s' % \ (self.uri, self.DEMUX_BIN), False) if bin: self.bin = bin demux = bin.get_by_name("demux") demux.connect('pad-added', self.on_new_pad) self.pipeline.add(bin) bin.sync_state_with_parent()
def add_output(self, description): # XXX This only works for pipelines not in use until #790 gets done. try: output = gst.parse_bin_from_description(description, ghost_unconnected_pads=True) except gobject.GError as ex: logger.error('Failed to create audio output "%s": %s', description, ex) raise exceptions.AudioException(bytes(ex)) self._add(output) logger.info('Audio output set to "%s"', description)
def _setup_mixer(self): mixer_desc = self._config['audio']['mixer'] track_desc = self._config['audio']['mixer_track'] volume = self._config['audio']['mixer_volume'] if mixer_desc is None: logger.info('Not setting up audio mixer') return if mixer_desc == 'software': self._software_mixing = True logger.info('Audio mixer is using software mixing') if volume is not None: self.set_volume(volume) logger.info('Audio mixer volume set to %d', volume) return try: mixerbin = gst.parse_bin_from_description( mixer_desc, ghost_unconnected_pads=False) except gobject.GError as ex: logger.warning( 'Failed to create audio mixer "%s": %s', mixer_desc, ex) return # We assume that the bin will contain a single mixer. mixer = mixerbin.get_by_interface(b'GstMixer') if not mixer: logger.warning( 'Did not find any audio mixers in "%s"', mixer_desc) return if mixerbin.set_state(gst.STATE_READY) != gst.STATE_CHANGE_SUCCESS: logger.warning( 'Setting audio mixer "%s" to READY failed', mixer_desc) return track = self._select_mixer_track(mixer, track_desc) if not track: logger.warning('Could not find usable audio mixer track') return self._mixer = mixer self._mixer_track = track self._mixer_scale = ( self._mixer_track.min_volume, self._mixer_track.max_volume) logger.info( 'Audio mixer set to "%s" using track "%s"', str(mixer.get_factory().get_name()).decode('utf-8'), str(track.label).decode('utf-8')) if volume is not None: self.set_volume(volume) logger.info('Audio mixer volume set to %d', volume)
def _setup_output(self): output_desc = self._config['audio']['output'] try: output = gst.parse_bin_from_description( output_desc, ghost_unconnected_pads=True) self._playbin.set_property('audio-sink', output) logger.info('Audio output set to "%s"', output_desc) except gobject.GError as ex: logger.error( 'Failed to create audio output "%s": %s', output_desc, ex) process.exit_process()
def add_output(self, description): # XXX This only works for pipelines not in use until #790 gets done. try: output = gst.parse_bin_from_description( description, ghost_unconnected_pads=True) except gobject.GError as ex: logger.error('Failed to create audio output "%s": %s', description, ex) raise exceptions.AudioException(bytes(ex)) self._add(output) logger.info('Audio output set to "%s"', description)
def recording_command(rec_dir, rec_name): pipe=gst.Pipeline() tracks=[] for i,launch in izip(count(),config['CAPTURE_PIPES']): s={'file':'%s/%s-%d.%s'%(rec_dir,rec_name,i,launch['suffix']),'preview':'%s/%s.jpeg'%(PREVIEW_DIR,i)} pipe.add(gst.parse_bin_from_description(launch['launch']%s,False)) tracks.append((launch['flavor'],s['file'])) if pipe.set_state(gst.STATE_PLAYING)==gst.StateChangeReturn(gst.STATE_CHANGE_FAILURE): return None def f(): pipe.set_state(gst.STATE_NULL) return tracks return f
def make_bin_from_config(self, config_key, pipeline, text): pipeline = pipeline % gajim.config.get(config_key) try: bin = gst.parse_bin_from_description(pipeline, True) return bin except GError, error_str: gajim.nec.push_incoming_event(InformationEvent(None, conn=self.session.connection, level='error', pri_txt=_('%s configuration error') % text.capitalize(), sec_txt=_("Couldn't setup %s. Check your configuration.\n\n" "Pipeline was:\n%s\n\nError was:\n%s") % (text, pipeline, error_str))) raise JingleContentSetupException
def __init__(self, options={}): base.Base.__init__(self, options) gst.Bin.__init__(self, self.options['name']) aux = (pipestr.replace('gc-rtpvideo-preview', 'sink-' + self.options['name']) .replace('gc-rtpvideo-depay', pipe_config[self.options['cameratype']]['depay']) .replace('gc-rtpvideo-videoparse', pipe_config[self.options['cameratype']]['videoparse']) .replace('gc-rtpvideo-dec', pipe_config[self.options['cameratype']]['dec']) .replace('gc-rtpvideo-mux', self.options['videomux'])) bin = gst.parse_bin_from_description(aux, False) self.add(bin) self.set_option_in_pipeline('location', 'gc-rtpvideo-src', 'location') self.set_value_in_pipeline(path.join(self.options['path'], self.options['file']), 'gc-rtpvideo-sink', 'location')
def _makeBin(self, *args): bin = gst.Bin() fx = gst.element_factory_make(self.effectname, "effect") if isinstance(self.input_streams[0], VideoStream): csp = gst.element_factory_make("ffmpegcolorspace") else: csp = gst.parse_bin_from_description( "audioconvert ! audioresample", True) bin.add(fx, csp) csp.link(fx) bin.add_pad(gst.GhostPad("sink", csp.get_pad("sink"))) bin.add_pad(gst.GhostPad("src", fx.get_pad("src"))) return bin
def GetRecordingSampleRate(device=None): """ Checks for available recording sample rates. Parameters: device -- Backend dependent device to poll for values. Returns: any of the following depending on the sound card: 1) an int representing the only supported sample rate. 2) an IntRange class with IntRange.low and IntRange.high being the min and max sample rates. 3) a list of ints representing all the supported sample rates. """ src = Globals.settings.recording["audiosrc"] try: bin = gst.parse_bin_from_description(src, False) except (gobject.GError, gst.ElementNotFoundError): Globals.debug("Cannot get sample rate: cannot parse bin", src) return list() try: element = bin.iterate_sources().next() except StopIteration: Globals.debug("Cannot get sample rate: no source device in the bin", src) return list() if device: element.set_property("device", device) # open device (so caps are probed) bin.set_state(gst.STATE_PAUSED) try: pad = element.src_pads().next() caps = pad.get_caps() val = caps[0]["rate"] except: val = None # clean up bin.set_state(gst.STATE_NULL) del element, bin return val
def ListCaptureDevices(src=None, probe_name=True): if not src: # get preference from Globals src = Globals.settings.recording["audiosrc"] try: bin = gst.parse_bin_from_description(src, False) except (gobject.GError, gst.ElementNotFoundError): Globals.debug("Cannot list capture devices: cannot parse bin", src) return list() try: element = bin.iterate_sources().next() except StopIteration: Globals.debug( "Cannot list capture devices: no source device in the bin", src) return ListDeviceProbe(element, probe_name)
def ListPlaybackDevices(sink=None, probe_name=True): if not sink: # get preference from Globals sink = Globals.settings.playback["audiosink"] try: bin = gst.parse_bin_from_description(sink, False) except (gobject.GError, gst.ElementNotFoundError): Globals.debug("Cannot list playback devices: cannot parse bin", sink) return list() try: element = bin.sinks().next() except StopIteration: Globals.debug( "Cannot list playback devices: no sink device in the bin", sink) return ListDeviceProbe(element, probe_name)
def __init__(self): self.playbin = playbin = gst.element_factory_make("playbin2") fakesink = gst.element_factory_make("fakesink") self.sink = sink = gst.element_factory_make('pipeline') audioconvert = gst.element_factory_make('audioconvert') self.tee = tee = gst.element_factory_make('tee') self.vb0 = vb0 = vorbisencode_bin.VorbisencodeBin() self.vb1 = vb1 = vorbisencode_bin.VorbisencodeBin() self.inputselector = inputselector = gst.element_factory_make( 'input-selector') shout2send = gst.parse_bin_from_description( 'shout2send mount=test.ogg \ ip=basil port=9000 password=hackmePbq11Kz streamname=test', True) sink.add(audioconvert, tee, vb0, inputselector, shout2send) gst.element_link_many(audioconvert, tee, vb0, inputselector, shout2send) sink.add(vb1) gst.element_link_many(tee, vb1, inputselector) self.tee.get_pad('src0').set_active(True) self.tee.get_pad('src1').set_active(False) self.inputselector.set_property('active-pad', self.inputselector.get_pad('sink0')) sink.add_pad(gst.GhostPad('sink', audioconvert.get_pad("sink"))) bus = playbin.get_bus() bus.add_signal_watch() bus.connect("message", self.on_message) playbin.connect('about-to-finish', self.on_about_to_finish) playbin.set_property("video-sink", fakesink) playbin.set_property("audio-sink", sink) playbin.set_property('uri', songs[1]) playbin.set_state(gst.STATE_PLAYING)