def transform(input_uri, out_type, out_file, num_buffers=-1): """Creates GStreamer pipeline using source URI and output type and location parameters ------------------ input_uri - URI locator for source video stream out_type - type of output file/s. Options "mp4", "frames" out_file - output file name, e.g. /tmp/out.mp4 or /tmp/out_%d.jpg (for multiple jpg files) num_buffer - limit for input frames """ src = element_make_from_uri(input_uri) if not src: raise Exception("Invalid source for URI {}".format(input_uri)) try: src.set_property("num-buffers", num_buffers) except: pass transcoder = None sink = None if out_type == "mp4": transcoder = Rtp2mp4() sink = elmake("filesink", location=out_file) elif out_type == "frame": transcoder = Rtp2jpeg() sink = elmake("multifilesink", location=out_file) else: raise Exception("Invalid out type {}".format(out_type)) client = GstPipeline(src, transcoder, sink) client.run()
def __init__(self): super(Rtp2app, self).__init__() # Create elements depay = elmake('rtph264depay', None) decoder = elmake('decodebin', None) self.appsink = elmake('appsink', 'appsink', asdict={ "max-buffers": 3000, 'emit-signals': True, 'sync': False }) self.appsink.connect( 'new-sample', self.on_new_buffer) # connect signal to callable func els = (depay, decoder, self.appsink) # Add elements to Bin for item in els: self.add(item) depay.link(decoder) decoder.connect("pad-added", self.decodebin_pad_added) # Add Ghost Pads self.add_pad(Gst.GhostPad.new('sink', depay.get_static_pad('sink')))
def __init__(self): super(Rtp2mp4, self).__init__() # Create elements depay = elmake('rtph264depay', None) parser = elmake('h264parse', None) #muxer = elmake('mp4mux', None) muxer = elmake('matroskamux', None) # Add elements to Bin self.add(depay) self.add(parser) self.add(muxer) # Link elements depay.link(parser) parser.link(muxer) # Add Ghost Pads self.add_pad(Gst.GhostPad.new('sink', depay.get_static_pad('sink'))) self.add_pad(Gst.GhostPad.new('src', muxer.get_static_pad('src')))
def test_elmake_negative(self): with self.assertRaises(Exception): elmake("") with self.assertRaises(Exception): elmake("okthen") with self.assertRaises(TypeError): elmake("fakesrc", num=1)
def constructPipeline(self): """ Create an instance of gst.Pipeline, create, add element objects to this pipeline. Create appropriate connections between the elements. """ self.filter1 = elmake("capsfilter", 'filter1') self.filter1.set_property('caps', Gst.Caps.from_string(CAPS)) self.src.connect("pad-added", self._src_pad_added) for item in (self.src, self.filter1, self.video): if item: self.pipeline.add(item) else: raise Exception("Element null") if self.filesink: self.pipeline.add(self.filesink) self.src.link(self.filter1) self.filter1.link(self.video) if self.filesink: self.video.link(self.filesink)
def __init__(self): super(Rtp2jpeg, self).__init__() # Create elements depay = elmake('rtph264depay', None) decoder = elmake('decodebin', None) self.vconvert = elmake('videoconvert', None) vscale = elmake('videoscale', None) vrate = elmake('videorate', None) filter1 = elmake("capsfilter", 'filter1') filter1.set_property( 'caps', Gst.Caps.from_string("video/x-raw,framerate=1/10")) queue1 = elmake('queue', None) queue1.set_property("leaky", 2) queue1.set_property("max-size-buffers", 10) jpegenc = elmake('jpegenc', None) jpegenc.set_property("idct-method", 1) jpegenc.set_property("quality", 100) els = (depay, decoder, self.vconvert, vscale, vrate, filter1, queue1, jpegenc) # Add elements to Bin for item in els: self.add(item) depay.link(decoder) els2 = (self.vconvert, vrate, filter1, jpegenc) # Link elements for pair in zip(els2, els2[1:]): pair[0].link(pair[1]) decoder.connect("pad-added", self.decodebin_pad_added) # Add Ghost Pads self.add_pad(Gst.GhostPad.new('sink', depay.get_static_pad('sink'))) self.add_pad(Gst.GhostPad.new('src', jpegenc.get_static_pad('src')))
def test_elmake(self): self.assertNotEqual(elmake("fakesrc"), None) self.assertNotEqual(elmake("fakesrc", filltype="zero"), None) self.assertNotEqual(elmake("fakesrc", asdict={"is-live": True}), None)
def test_jpeg(self): client = GstPipeline(elmake("fakesrc", asdict={"num-buffers": 100}), Rtp2jpeg(), elmake("fakesink")) client.pipeline.set_state(Gst.State.PLAYING) sleep(0.1) client.pipeline.send_event(Gst.Event.new_eos())