def __init__(self, player, quality): gst.Bin.__init__(self) self.__player = player self.quality = quality self.audioconvert = gst.element_factory_make("audioconvert") # threads queue = gst.element_factory_make("queue") self.vorbisenc = gst.element_factory_make("vorbisenc") self.vorbisenc.set_property("quality", self.quality) self.vorbisparse = gst.element_factory_make('vorbisparse') self.add(queue, self.audioconvert, self.vorbisenc, self.vorbisparse) sink = queue.get_pad("sink") self.sink = gst.GhostPad("sink", sink) self.add_pad(self.sink) gst.element_link_many(queue, self.audioconvert, self.vorbisenc, self.vorbisparse) src = self.vorbisparse.get_pad("src") self.src = gst.GhostPad("src", src) self.add_pad(self.src) self.__player.pipe.add(self)
def __init__(self): gst.Bin.__init__(self) self.set_name('jpegenc_bin') queue = gst.element_factory_make('queue', "queue") queue.set_property("max-size-buffers", 1000) queue.set_property("max-size-bytes", 0) queue.set_property("max-size-time", 0) ffmpegcolorspace = gst.element_factory_make('ffmpegcolorspace', "ffmpegcolorspace") videorate = gst.element_factory_make('videorate', "videorate") jpegenc = gst.element_factory_make('jpegenc', 'jpegenc') try: videorate.set_property("max-rate", 30) except: pass self.add(queue) self.add(ffmpegcolorspace) self.add(videorate) self.add(jpegenc) queue.link(ffmpegcolorspace) ffmpegcolorspace.link(videorate) videorate.link(jpegenc) self.add_pad(gst.GhostPad("sink", queue.get_static_pad("sink"))) self.add_pad(gst.GhostPad("src", jpegenc.get_static_pad("src")))
def __init__(self): gst.Bin.__init__(self) self.colorspace = gst.element_factory_make("ffmpegcolorspace", "videoconvert_colorspace") self.add(self.colorspace) self.videorate = gst.element_factory_make("videorate", "videoconvert_videorate") self.add(self.videorate) self.videoscale = gst.element_factory_make("videoscale", "videoconvert_videoscale") self.add(self.videoscale) self.videoscale.set_property("method", 1) self.capsfilter = gst.element_factory_make("capsfilter", "videoconvert_capsfilter") self.add(self.capsfilter) gst.element_link_many(self.colorspace, self.videorate, self.videoscale, self.capsfilter) self.source_pad = gst.GhostPad("src", self.capsfilter.src_pads().next()) self.add_pad(self.source_pad) self.sink_pad = gst.GhostPad("sink", self.colorspace.sink_pads().next()) self.add_pad(self.sink_pad)
def __init__(self): gst.Bin.__init__(self) self.set_name('Balance_bin') self.config = { 'saturacion': 50.0, 'contraste': 50.0, 'brillo': 50.0, 'hue': 50.0, 'gamma': 10.0 } videobalance = gst.element_factory_make("videobalance", "videobalance") gamma = gst.element_factory_make("gamma", "gamma") videoflip = gst.element_factory_make("videoflip", "videoflip") self.add(videobalance) self.add(gamma) self.add(videoflip) videobalance.link(gamma) gamma.link(videoflip) self.add_pad(gst.GhostPad("sink", videobalance.get_static_pad("sink"))) self.add_pad(gst.GhostPad("src", videoflip.get_static_pad("src")))
def __init__(self, position=0, duration=2 * gst.SECOND, fadefromblack=True): gst.Bin.__init__(self) self.incsp = gst.element_factory_make("ffmpegcolorspace", "incsp") self.outcsp = gst.element_factory_make("ffmpegcolorspace", "outcsp") self.alpha = gst.element_factory_make("alpha", "alpha") self.vmix = gst.element_factory_make("videomixer", "videomix") self.vmix.set_property("background", 1) self.add(self.incsp, self.alpha, self.vmix, self.outcsp) gst.element_link_many(self.incsp, self.alpha, self.vmix, self.outcsp) self._sinkpad = gst.GhostPad("sink", self.incsp.get_pad("sink")) self._sinkpad.set_active(True) self._srcpad = gst.GhostPad("src", self.outcsp.get_pad("src")) self._srcpad.set_active(True) self.add_pad(self._sinkpad) self.add_pad(self._srcpad) self.startposition = position self.duration = duration self.fadefromblack = fadefromblack self.alphacontrol = gst.Controller(self.alpha, "alpha") self.alphacontrol.set_interpolation_mode("alpha", gst.INTERPOLATE_LINEAR) self._resetControllerValues()
def __init__(self, *args, **kwargs): # init parent gst.Bin.__init__(self, *args, **kwargs) # The wrapped decoder. The child classes should set the __decoder_factory__. self.decoder = gst.element_factory_make( self.__decoder_factory__.get_name()) self.add(self.decoder) # For every 'always' pad-template of the decoder create a ghost-pad for static_templ in self.__decoder_factory__.get_static_pad_templates( ): templ = static_templ.get() if templ.presence == gst.PAD_ALWAYS: if templ.direction == gst.PAD_SINK: # We want to delete timestamps before decoding, so we need a helper element before the sink element = ReStamp(templ) self.add(element) element.link(self.decoder) self.add_pad( gst.GhostPad(templ.name_template, element.get_pad('sink'))) elif templ.direction == gst.PAD_SRC: self.add_pad( gst.GhostPad(templ.name_template, self.decoder.get_pad( templ.name_template)))
def get_crossfade(duration): # To crossfade, we add an alpha channel to both streams. Then a video # mixer mixes them according to the alpha channel. We put a control # on the alpha channel to linearly sweep it over the duration of the # crossfade. The returned bin should get placed in a gnloperation. # The reason to put the alpha and final ffmpegcolorspace conversion # in this bin is that are only applied during the crossfade and not # all the time (saves some processing time). bin = gst.Bin() alpha1 = gst.element_factory_make("alpha") alpha2 = gst.element_factory_make("alpha") mixer = gst.element_factory_make("videomixer") color = gst.element_factory_make("ffmpegcolorspace") bin.add(alpha1, alpha2, mixer, color) alpha1.link(mixer) alpha2.link(mixer) mixer.link(color) controller = gst.Controller(alpha2, "alpha") controller.set_interpolation_mode("alpha", gst.INTERPOLATE_LINEAR) controller.set("alpha", 0, 0.0) controller.set("alpha", duration * gst.MILLISECOND, 1.0) bin.add_pad(gst.GhostPad("sink1", alpha1.get_pad("sink"))) bin.add_pad(gst.GhostPad("sink2", alpha2.get_pad("sink"))) bin.add_pad(gst.GhostPad("src", color.get_pad("src"))) return bin, controller # return the controller otherwise it will go out of scope and get deleted before it is even applied
def get_smpte(duration, transition=1): """ Not used right now. """ # To crossfade, we add an alpha channel to both streams. Then a video # mixer mixes them according to the alpha channel. We put a control # on the alpha channel to linearly sweep it over the duration of the # crossfade. The returned bin should get placed in a gnloperation. # The reason to put the alpha and final ffmpegcolorspace conversion # in this bin is that are only applied during the crossfade and not # all the time (saves some processing time). bin = gst.Bin() alpha1 = gst.element_factory_make("alpha") smpte = gst.element_factory_make("smptealpha") mixer = gst.element_factory_make("videomixer") color = gst.element_factory_make("ffmpegcolorspace") bin.add(alpha1, smpte, mixer, color) alpha1.link(mixer) smpte.link(mixer) mixer.link(color) smpte.set_property("type", transition) controller = gst.Controller(smpte, "position") controller.set_interpolation_mode("position", gst.INTERPOLATE_LINEAR) controller.set("position", 0, 1.0) controller.set("position", duration * gst.MILLISECOND, 0.0) bin.add_pad(gst.GhostPad("sink1", alpha1.get_pad("sink"))) bin.add_pad(gst.GhostPad("sink2", smpte.get_pad("sink"))) bin.add_pad(gst.GhostPad("src", color.get_pad("src"))) return bin, controller
def setupFadeBin(self): """ Creates a GStreamer bin element and adds elements necessary for fade out effect implementation Also creates and adds ghost pads. @see: self.addFadingEffect() """ self.audioconvert = gst.element_factory_make("audioconvert") self.volume = gst.element_factory_make("volume") self.audioconvert2 = gst.element_factory_make("audioconvert") self.fadeBin = gst.element_factory_make("bin", "fadeBin") self.fadeBin.add(self.audioconvert, self.volume, self.audioconvert2) gst.element_link_many(self.audioconvert, self.volume, self.audioconvert2) #Create Ghost pads for fadeBin sinkPad = self.audioconvert.get_pad("sink") self.fadeBinSink = gst.GhostPad("sink", sinkPad) self.fadeBinSrc = gst.GhostPad("src", self.audioconvert2.get_pad("src")) self.fadeBin.add_pad(self.fadeBinSink) self.fadeBin.add_pad(self.fadeBinSrc)
def _singlePadAddedCb(self, dbin, pad, topbin): self.debug("dbin:%r, pad:%r, topbin:%r", dbin, pad, topbin) if hasattr(topbin, "child"): topbin.child.sync_state_with_parent() if hasattr(topbin, "volume"): # make sure audio elements reach our same state. This is needed # since those elements are still unlinked downstream at this point, # so state change order doesn't happen in the usual # downstream-to-upstream way. for element in [ topbin.aconv, topbin.ares, topbin.arate, topbin.volume ]: element.sync_state_with_parent() pad.link(topbin.aconv.get_pad("sink")) topbin.ghostpad = gst.GhostPad("src", topbin.volume.get_pad("src")) elif hasattr(topbin, "alpha"): for element in [ topbin.queue, topbin.scale, topbin.csp, topbin.alpha, topbin.capsfilter ]: element.sync_state_with_parent() pad.link(topbin.queue.get_pad("sink")) topbin.ghostpad = gst.GhostPad("src", topbin.capsfilter.get_pad("src")) else: topbin.ghostpad = gst.GhostPad("src", pad) if pad.props.caps is not None: topbin.ghostpad.set_caps(pad.props.caps) topbin.ghostpad.set_active(True) topbin.add_pad(topbin.ghostpad)
def __init__(self, width, height, is_square, add_borders): gst.Bin.__init__(self) self._width = width self._height = height self._is_square = is_square self._add_borders = add_borders self._inpar = None # will be set when active self._inwidth = None self._inheight = None self._videoscaler = gst.element_factory_make("videoscale") self._capsfilter = gst.element_factory_make("capsfilter") self._videobox = gst.element_factory_make("videobox") self.add(self._videoscaler, self._capsfilter, self._videobox) self._videoscaler.link(self._capsfilter) self._capsfilter.link(self._videobox) # Create source and sink pads self._sinkPad = gst.GhostPad('sink', self._videoscaler.get_pad('sink')) self._srcPad = gst.GhostPad('src', self._videobox.get_pad('src')) self.add_pad(self._sinkPad) self.add_pad(self._srcPad) self._configureOutput() # Add setcaps callback in the sink pad self._sinkPad.set_setcaps_function(self._sinkSetCaps) # Add a callback for caps changes in the videoscaler source pad # to recalculate the scale correction self._videoscaler.get_pad('src').connect('notify::caps', self._scaleCorrectionCallback)
def _makeBin(self, *args): s = self.settings b = gst.Bin() # encoder enc = gst.element_factory_make(s.encoder) for k, v in s.encodersettings.iteritems(): enc.set_property(k, v) b.add(enc) # optional input stream if s.input_stream and s.modifyinput: filt = get_modifier_for_stream(output_stream=s.input_stream) mod = filt.makeBin() b.add(mod) mod.link(enc) gsink = gst.GhostPad("sink", mod.get_pad("sink")) else: gsink = gst.GhostPad("sink", enc.get_pad("sink")) gsink.set_active(True) b.add_pad(gsink) # optional output stream if s.output_stream and s.modifyoutput: outfilt = gst.element_factory_make("capsfilter") outfilt.props.caps = s.output_stream.caps b.add(outfilt) enc.link(outfilt) gsrc = gst.GhostPad("src", outfilt.get_pad("src")) else: gsrc = gst.GhostPad("src", enc.get_pad("src")) gsrc.set_active(True) b.add_pad(gsrc) return b
def _makeBin(self, *args): b = gst.Bin() idt = gst.element_factory_make("identity", "single-segment") idt.props.single_segment = True aconv = gst.element_factory_make("audioconvert", "aconv") ares = gst.element_factory_make("audioresample", "ares") arate = gst.element_factory_make("audiorate", "arate") b.add(idt, aconv, ares, arate) gst.element_link_many(idt, aconv, ares, arate) gsink = gst.GhostPad("sink", idt.get_pad("sink")) gsink.set_active(True) b.add_pad(gsink) # if we have an output stream specified, we add a capsfilter if len(self.output_streams): cfilter = gst.element_factory_make("capsfilter") cfilter.props.caps = self.output_streams[0].caps b.add(cfilter) arate.link(cfilter) gsrc = gst.GhostPad("src", cfilter.get_pad("src")) else: gsrc = gst.GhostPad("src", arate.get_pad("src")) gsrc.set_active(True) b.add_pad(gsrc) return b
def get_alpha_transition(config, element="alpha"): """Returns a bin that performs a transition between two input pads based on adding an alpha channel. You can specify the element of the second channel. Currently supported are "alpha" and "smptealpha" This bin adds an alpha channel to both streams, followed by a video mixer and an ffmpegcolorspace. The reason to put the alpha and final ffmpegcolorspace conversion in this bin is that are only applied during the crossfade and not all the time (saves some processing time). """ bin = gst.Bin() alpha1 = gst.element_factory_make("alpha", "alpha1") alpha2 = gst.element_factory_make(element, "alpha2") mixer = gst.element_factory_make(config["videomixer"]) mixer.props.background = "transparent" #color = gst.element_factory_make("ffmpegcolorspace") caps = gst.element_factory_make("capsfilter") caps.props.caps = config.get_video_caps("AYUV") bin.add(alpha1, alpha2, mixer, caps) alpha1.get_pad("src").link(mixer.get_pad("sink_0")) alpha2.get_pad("src").link(mixer.get_pad("sink_1")) mixer.link(caps) #color.link(caps) bin.add_pad(gst.GhostPad("sink1", alpha1.get_pad("sink"))) bin.add_pad(gst.GhostPad("sink2", alpha2.get_pad("sink"))) bin.add_pad(gst.GhostPad("src", caps.get_pad("src"))) # return the controller otherwise it will go out of scope and get # deleted before it is even applied return bin
def testNewDecodedPadNotFixed(self): video_template = gst.PadTemplate( 'video_00', gst.PAD_SRC, gst.PAD_ALWAYS, gst.Caps('video/x-raw-rgb, ' 'framerate=[0/1, %d/1]' % ((2**31) - 1))) audio_template = gst.PadTemplate( 'audio_00', gst.PAD_SRC, gst.PAD_ALWAYS, gst.Caps('audio/x-raw-int, ' 'rate=[1, %d]' % ((2**31) - 1))) video = gst.Pad(video_template) audio = gst.Pad(audio_template) video_ghost = gst.GhostPad("video", video) audio_ghost = gst.GhostPad("audio", audio) self.failUnlessEqual(self.discoverer.current_streams, []) self.discoverer._newDecodedPadCb(None, video_ghost, False) self.failUnlessEqual(len(self.discoverer.current_streams), 0) self.failUnlessEqual(self.discoverer.new_video_pad_cb, 1) self.discoverer._newDecodedPadCb(None, audio_ghost, False) self.failUnlessEqual(len(self.discoverer.current_streams), 0) self.failUnlessEqual(self.discoverer.new_video_pad_cb, 1) # fix the caps video.set_caps(gst.Caps('video/x-raw-rgb, framerate=25/1')) self.failUnlessEqual(len(self.discoverer.current_streams), 1) self.failUnlessEqual(self.discoverer.new_video_pad_cb, 1) audio.set_caps(gst.Caps('audio/x-raw-int, rate=44100')) self.failUnlessEqual(len(self.discoverer.current_streams), 2) self.failUnlessEqual(self.discoverer.new_video_pad_cb, 1)
def _makeBin(self, *args): b = gst.Bin() idt = gst.element_factory_make("identity", "single-segment") idt.props.single_segment = True csp = gst.element_factory_make("ffmpegcolorspace", "csp") vrate = gst.element_factory_make("videorate", "vrate") b.add(idt, csp, vrate) gst.element_link_many(idt, csp, vrate) gsink = gst.GhostPad("sink", idt.get_pad("sink")) gsink.set_active(True) b.add_pad(gsink) # if we have an output stream specified, we add a capsfilter vscale = SmartVideoScale() vscale.set_caps(self.output_streams[0].caps) b.add(vscale) vrate.link(vscale) self.debug("output_streams:%d", len(self.output_streams)) if len(self.output_streams) and self.output_streams[0].caps.is_fixed(): idt = gst.element_factory_make("capsfilter") idt.props.caps = self.output_streams[0].caps b.add(idt) vscale.link(idt) gsrc = gst.GhostPad("src", idt.get_pad("src")) else: gsrc = gst.GhostPad("src", vscale.get_pad("src")) gsrc.set_active(True) b.add_pad(gsrc) return b
def setup_playbin2_mode(self): print "using output filter for rgvolume and rglimiter" self.rgvolume = gst.element_factory_make("rgvolume") self.rgvolume.connect("notify::target-gain", self.playbin2_target_gain_cb) self.rglimiter = gst.element_factory_make("rglimiter") # on track changes, we need to reset the rgvolume state, otherwise it # carries over the tags from the previous track self.pec_id = self.shell_player.connect('playing-song-changed', self.playing_entry_changed) # watch playbin2's uri property to see when a new track is opened playbin = self.player.props.playbin if playbin is None: self.player.connect("notify::playbin", self.playbin2_notify_cb) else: playbin.connect("notify::uri", self.playbin2_uri_notify_cb) # try to work around bug #621632 if gobject.pygobject_version > (2, 21, 1): print "working around pygobject/gst-python refcount bug.." self.player.add_filter(self.rgvolume) self.player.add_filter(self.rglimiter) self.rgfilter = None else: self.rgfilter = gst.Bin() self.rgfilter.add(self.rgvolume, self.rglimiter) self.rgvolume.link(self.rglimiter) self.rgfilter.add_pad( gst.GhostPad("sink", self.rgvolume.get_static_pad("sink"))) self.rgfilter.add_pad( gst.GhostPad("src", self.rglimiter.get_static_pad("src"))) self.player.add_filter(self.rgfilter)
def __init__(self): gst.Bin.__init__(self) self.audioconvert = gst.element_factory_make("audioconvert", "audioconvert") self.add(self.audioconvert) self.audioresample = gst.element_factory_make("audioresample", "audioresample") self.add(self.audioresample) self.audiorate = gst.element_factory_make("audiorate", "audiorate") self.add(self.audiorate) self.capsfilter = gst.element_factory_make("capsfilter", "audioresample_capsfilter") self.add(self.capsfilter) self.audioconvert.link(self.audiorate) self.audiorate.link(self.audioresample) self.audioresample.link(self.capsfilter) self.sink_pad = gst.GhostPad("sink", self.audioconvert.sink_pads().next()) self.add_pad(self.sink_pad) self.src_pad = gst.GhostPad("src", self.capsfilter.src_pads().next()) self.add_pad(self.src_pad) self.audiorate_property = -1
def get_preview_backend(config, num_audio_tracks): backend = gst.Bin("backend") #audio_volume = gst.element_factory_make("volume","volume") video_caps = gst.element_factory_make("capsfilter") video_caps.props.caps = config.get_video_caps("I420", dict(border=0)) mqueue = gst.element_factory_make("multiqueue") mqueue.props.max_size_time = 10 * gst.SECOND mqueue.props.max_size_bytes = 0 mqueue.props.max_size_buffers = 0 video_sink = gst.element_factory_make("autovideosink") audio_sel = gst.element_factory_make("input-selector") audio_sink = gst.element_factory_make("autoaudiosink") backend.add(video_caps, mqueue, video_sink, audio_sel, audio_sink) gst.element_link_many(video_caps, mqueue, video_sink) gst.element_link_many(audio_sel, mqueue, audio_sink) audio_caps = [] for i in range(num_audio_tracks): caps = gst.element_factory_make("capsfilter") audio_caps.append(caps) caps.props.caps = config.get_audio_caps() backend.add(caps) caps.link(audio_sel) backend.add_pad(gst.GhostPad("video_sink", video_caps.get_pad("sink"))) for i, sink in enumerate(audio_caps): backend.add_pad( gst.GhostPad("audio_sink%d" % (i, ), sink.get_pad("sink"))) return backend
def make_bin_pads(bin, input, output): # Connect the source and sink pads of the bin to the appropriate elements. # I'm also not sure why these inputs and outputs seem logically reversed, # but this works. binsrc = gst.GhostPad("binsrc", output.get_pad("src")) bin.add_pad(binsrc) binsink = gst.GhostPad("binsink", input.get_pad("sink")) bin.add_pad(binsink)
def old(): filepipe = gst.Pipeline("filepipe") # fromfile = gst.element_factory_make('audiotestsrc','testfile') # fromfile = gst.element_factory_make('filesrc','testfile') # fromfile.set_property('location','falling.wav') # fromfile.set_state(gst.STATE_PLAYING) # gtk.main() append_pipe(filepipe, 'testfile', 'filesrc', {'location': 'falling.wav'}) append_pipe(filepipe, 'decodebin', 'decodebin2', {}) append_pipe(filepipe, 'audioconvert', 'audioconvert', {}) file_volume = append_pipe(filepipe, 'filevolume', 'volume', {}) file_ident = gst.element_factory_make("identity") filepipe.add(file_ident) # needed? fileoutcaps = gst.caps_from_string( "audio/x-raw-int,channels=2,rate=44100,depth=16") # isn't this just sequential 'link'? file_volume.link(file_ident, fileoutcaps) filepipe_srcpad = gst.GhostPad("src", file_ident.get_pad("src")) # append_pipe(filepipe, 'speaker', 'alsasink', {}) # filepipe.set_state(gst.STATE_PLAYING) ## Mic pipe micpipe = gst.Pipeline("micpipe") append_pipe(micpipe, 'mic', 'alsasrc', {}) mic_volume = append_pipe(micpipe, 'micvolume', 'volume', {}) mic_ident = gst.element_factory_make("identity") micpipe.add(mic_ident) # needed? micoutcaps = gst.caps_from_string( "audio/x-raw-int,channels=2,rate=44100,depth=16") # isn't this just sequential 'link'? mic_volume.link(mic_ident, micoutcaps) micpipe_srcpad = gst.GhostPad("src", mic_ident.get_pad("src")) # append_pipe(micpipe, 'speaker', 'alsasink', {}) # micpipe.set_state(gst.STATE_PLAYING) # MIX mix = gst.Pipeline("mix") mix.add(filepipe) mix.add(micpipe) mixer = append_pipe(mix, "adder", 'adder', {}) ch1 = mixer.get_request_pad('sink%d') filepipe_srcpad.link(ch1) ch2 = mixer.get_request_pad('sink%d') micpipe_srcpad.link(ch2) append_pipe(mix, 'audioconvert', 'audioconvert', {}) append_pipe(mix, 'mixspeaker', 'alsasink', {}) mix.set_state(gst.STATE_PLAYING) gtk.main()
def get_frontend(elements, config): video_bin, info = get_video_bin(elements, config) audio_bin = get_audio_bin(elements, config, info) frontend = gst.Bin("frontend") frontend.add(video_bin, audio_bin) frontend.add_pad(gst.GhostPad("video_src", video_bin.get_pad("src"))) for pad in audio_bin.pads(): frontend.add_pad(gst.GhostPad(pad.get_name(), pad)) return frontend, info
def get_videomixer_bin(self): bin = gst.Bin() # Video Rate videorate = gst.element_factory_make("videorate", "videorate") bin.add(videorate) videorate_cap = gst.element_factory_make("capsfilter", "video_rate_cap") videorate_cap.set_property( "caps", gst.caps_from_string( "%s, framerate=%d/1" % (self.config.input_type, self.config.framerate))) bin.add(videorate_cap) # --- End Video Rate # Video Scaler (Resolution) videoscale = gst.element_factory_make("videoscale", "videoscale") bin.add(videoscale) videoscale_cap = gst.element_factory_make("capsfilter", "videoscale_cap") # Change the resolution of the source video. log.debug("Record Resolution: %s", self.config.resolution) if self.config.resolution != "No Scaling": width, height = widget.resmap[self.config.resolution] videoscale_cap.set_property( 'caps', gst.caps_from_string("{}, width={}, height={}".format( self.config.input_type, width, height))) bin.add(videoscale_cap) # --- End Video Scaler colorspace = gst.element_factory_make("ffmpegcolorspace", "colorspace") bin.add(colorspace) # Link Elements videorate.link(videorate_cap) videorate_cap.link(videoscale) videoscale.link(videoscale_cap) videoscale_cap.link(colorspace) # Setup ghost pad sinkpad = videorate.get_pad("sink") sink_ghostpad = gst.GhostPad("sink", sinkpad) bin.add_pad(sink_ghostpad) srcpad = colorspace.get_pad("src") src_ghostpad = gst.GhostPad("src", srcpad) bin.add_pad(src_ghostpad) return bin
def __init__(self): gst.Bin.__init__(self) self.queue = gst.element_factory_make('queue') self.vorbisenc = gst.element_factory_make('vorbisenc') self.oggmux = gst.element_factory_make('oggmux') self.add(self.queue, self.vorbisenc, self.oggmux) gst.element_link_many(self.queue, self.vorbisenc, self.oggmux) self.add_pad(gst.GhostPad('sink', self.queue.get_pad("sink"))) self.add_pad(gst.GhostPad('src', self.oggmux.get_pad("src")))
def _makeBin(self, *args): s = self.settings b = gst.Bin() self.debug("Creating muxer") mux = gst.element_factory_make(s.muxer) for k, v in s.muxersettings.iteritems(): mux.set_property(k, v) b.add(mux) self.debug("Ghosting source pad") gsrc = gst.GhostPad("src", mux.get_pad("src")) gsrc.set_active(True) b.add_pad(gsrc) i = 0 # add all the encoders for setting in s.settings: self.debug("Creating encoder %d", i) b2 = EncoderFactory(setting).makeBin() b.add(b2) src2 = b2.get_pad("src") # request a compatible pad from the muxer n2 = get_compatible_sink_pad(s.muxer, src2.get_caps()) if n2 == None: raise Exception("can't find a compatible pad") # FIXME : We're assuming it's a request pad p2 = mux.get_request_pad(n2) if gst.version() < (0, 10, 22, 1): segment_eater = NewsegmentEater() b.add(segment_eater) segment_eater.get_pad('src').link(p2) p2 = segment_eater.get_pad('sink') src2.link(p2) # expose encoder sink pad gsink = gst.GhostPad("sink_%d" % i, b2.get_pad("sink")) gsink.set_active(True) b.add_pad(gsink) i += 1 self.debug("Done") return b
def __init__(self, mode, method): gst.Bin.__init__(self) self.keepFR = True self.deinterlacerName = PASSTHROUGH_DEINTERLACER self._interlaced = False # Create elements self._colorspace = gst.element_factory_make("ffmpegcolorspace") self._colorfilter = gst.element_factory_make("capsfilter") self._deinterlacer = gst.element_factory_make(PASSTHROUGH_DEINTERLACER) self._deinterlacer.set_property('silent', True) self._videorate = gst.element_factory_make("videorate") self._ratefilter = gst.element_factory_make("capsfilter") # Add elements to the bin self.add(self._colorspace, self._colorfilter, self._deinterlacer, self._videorate, self._ratefilter) # FIXME: I420 is the only format support by the ffmpeg deinterlacer. # Forcing it simplifies renegotiation issues if the input colorspace # is different and the ffmpeg deinterlacer is added after the # negotiation happened in a different colorspace. This makes this # element not-passthrough. self._colorfilter.set_property( 'caps', gst.Caps('video/x-raw-yuv, format=(fourcc)I420')) # Link elements self._colorspace.link(self._colorfilter) self._colorfilter.link(self._deinterlacer) self._deinterlacer.link(self._videorate) self._videorate.link(self._ratefilter) # Create source and sink pads self._sinkPad = gst.GhostPad('sink', self._colorspace.get_pad('sink')) self._srcPad = gst.GhostPad('src', self._ratefilter.get_pad('src')) self.add_pad(self._sinkPad) self.add_pad(self._srcPad) # Store deinterlacer's sink and source peer pads self._sinkPeerPad = self._colorspace.get_pad('src') self._srcPeerPad = self._videorate.get_pad('sink') # Add setcaps callback in the sink pad self._sinkPad.set_setcaps_function(self._sinkSetCaps) # Set the mode and method in the deinterlacer self._setMethod(method) self._setMode(mode)
def __init__(self, channels=None, samplerate=None, tolerance=DEFAULT_TOLERANCE): gst.Bin.__init__(self) self._samplerate = samplerate self._samplerate_caps = '' self._channels = channels self._channels_caps = '' if self._use_audiorate(): self._audiorate = gst.element_factory_make("audiorate") self._audiorate.set_property("skip-to-first", True) else: self._audiorate = gst.element_factory_make("identity") self._audiorate.set_property("silent", True) self._audioconv = gst.element_factory_make("audioconvert") resampler = 'audioresample' if gstreamer.element_factory_exists('legacyresample'): resampler = 'legacyresample' self._audioresample = gst.element_factory_make(resampler) self._capsfilter = gst.element_factory_make("capsfilter") self._identity = gst.parse_launch("identity silent=true") self.add(self._audiorate) self.add(self._audioconv) self.add(self._audioresample) self.add(self._capsfilter) self.add(self._identity) self._audiorate.link(self._audioconv) self._audioconv.link(self._audioresample) self._audioresample.link(self._capsfilter) self._capsfilter.link(self._identity) # Create source and sink pads self._sinkPad = gst.GhostPad('sink', self._audiorate.get_pad('sink')) self._srcPad = gst.GhostPad('src', self._identity.get_pad('src')) self.add_pad(self._sinkPad) self.add_pad(self._srcPad) self._sinkPad.set_event_function(self.eventfunc) self._setSamplerate(samplerate) self._setChannels(channels) self._setTolerance(tolerance)
def get_videomixer_bin(self): bin = gst.Bin() # Video Rate videorate = gst.element_factory_make("videorate", "videorate") bin.add(videorate) videorate_cap = gst.element_factory_make("capsfilter", "video_rate_cap") videorate_cap.set_property( "caps", gst.caps_from_string( "%s, framerate=%d/1" % (self.config.input_type, self.config.framerate))) bin.add(videorate_cap) # --- End Video Rate # Video Scaler (Resolution) videoscale = gst.element_factory_make("videoscale", "videoscale") bin.add(videoscale) videoscale_cap = gst.element_factory_make("capsfilter", "videoscale_cap") if self.config.resolution != "NOSCALE": videoscale_cap.set_property( 'caps', gst.caps_from_string('%s, width=640, height=480' % (self.config.input_type))) bin.add(videoscale_cap) # --- End Video Scaler colorspace = gst.element_factory_make("ffmpegcolorspace", "colorspace") bin.add(colorspace) # Link Elements videorate.link(videorate_cap) videorate_cap.link(videoscale) videoscale.link(videoscale_cap) videoscale_cap.link(colorspace) # Setup ghost pad sinkpad = videorate.get_pad("sink") sink_ghostpad = gst.GhostPad("sink", sinkpad) bin.add_pad(sink_ghostpad) srcpad = colorspace.get_pad("src") src_ghostpad = gst.GhostPad("src", srcpad) bin.add_pad(src_ghostpad) return bin
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 __init__(self): gst.Pipeline.__init__(self) self.set_name('jamedia_video_pipeline') convert = gst.element_factory_make('ffmpegcolorspace', 'convert') rate = gst.element_factory_make('videorate', 'rate') pantalla = gst.element_factory_make('xvimagesink', "pantalla") pantalla.set_property("force-aspect-ratio", True) try: # FIXME: xo no posee esta propiedad rate.set_property('max-rate', 30) except: pass self.add(convert) self.add(rate) self.add(pantalla) convert.link(rate) rate.link(pantalla) self.ghost_pad = gst.GhostPad("sink", convert.get_static_pad("sink")) self.ghost_pad.set_target(convert.get_static_pad("sink")) self.add_pad(self.ghost_pad)