def __init__(self): """build Fake input bin. Description of pipeline : | videotestsrc --> capsfilter --> | src pad """ super(FakeInputBin, self).__init__() ImageBinElems = [] MyVideoSrc = LG.element_factory_make('videotestsrc') ImageBinElems.append(MyVideoSrc) MyVideoSrcFilter = LG.element_factory_make("capsfilter", "MyVideoSrc") caps = LG.Caps( "video/x-raw-yuv, framerate=(fraction)10/1, width=720,height=576") MyVideoSrcFilter.set_property("caps", caps) ImageBinElems.append(MyVideoSrcFilter) for elem in ImageBinElems: self.add(elem) LG.element_link_many(MyVideoSrc, MyVideoSrcFilter) #this bin has only a src ghostPad self.add_pad(LG.GhostPad('src', MyVideoSrcFilter.get_pad('src')))
def __init__(self, videowidget, location, framerate="5", nbImages= -1, start_buf=0, on_eos_cb=None) : """ init of gstreamer player inputs : - videowidget : Drawing area widgert, in gstreamer style for playing video - location : where the image are stored - framerate : the video framerate - nbImages : Number of images to play - start_buf : index of the first image to play - on_eos_cb : callback for EOS signal """ LG.lcl_gstreamer.__init__(self,video_widget =videowidget, pipe_name = 'Play pipe', cb_on_eos = on_eos_cb ) ElementList = [] self._location = location self._nbImages = nbImages self._framerate = framerate self._start_buf = start_buf # image load self.MyImageSrc = LG.element_factory_make('multifilesrc') self.MyImageSrc.set_property('location', self._location) self.MyImageSrc.set_property('num-buffers', self._nbImages) self.MyImageSrc.set_property('index', self._start_buf) ElementList.append(self.MyImageSrc) # filter self.ImageFilter = LG.element_factory_make("capsfilter") caps_string = self._filter_caps_string % self._framerate caps = LG.gst.Caps(caps_string) self.ImageFilter.set_property("caps", caps) ElementList.append(self.ImageFilter) # decodebin self.dec = LG.element_factory_make('decodebin') # Connect handler for 'new-decoded-pad' signal self.dec.connect('new-decoded-pad', self.on_new_decoded_pad) ElementList.append(self.dec) # ffmpegclorspace self.Myffmpeg = LG.element_factory_make('ffmpegcolorspace') # Reference used in self.on_new_decoded_pad() self.vpad = self.Myffmpeg.get_pad('sink') ElementList.append(self.Myffmpeg) # Image sink MyImageSink = LG.element_factory_make('xvimagesink') ElementList.append(MyImageSink) # # Add elements to pipeline # for elem in ElementList : self.pipe.add(elem) # link all elements LG.element_link_many(self.MyImageSrc, self.ImageFilter) self.ImageFilter.link(self.dec) LG.element_link_many(self.Myffmpeg, MyImageSink) LG.lcl_gstreamer.connect_bus(self)
def __init__(self): """ Build display bin """ super(DisplayBin, self).__init__() ImageBinElems = [] Myffmpeg = LG.element_factory_make( 'ffmpegcolorspace') # ffmpegcolorspace for display ImageBinElems.append(Myffmpeg) # scale image Myvideoscale = LG.element_factory_make('videoscale', 'DisplayVideoScale') ImageBinElems.append(Myvideoscale) MyImageSink = LG.element_factory_make('autovideosink') ImageBinElems.append(MyImageSink) for elem in ImageBinElems: self.add(elem) LG.element_link_many(Myffmpeg, Myvideoscale, MyImageSink) # only a sink (input) pad self.add_pad(LG.GhostPad('sink', Myffmpeg.get_pad('sink')))
def __init__(self): """build Dv cam input bin Description of pipeline : | dv1394src --> dvdemux --> dvdec --> ffmpegcolorspace --> | src_pad """ super(DvInputBin, self).__init__() ImageBinElems = [] MyVideoSrc = LG.element_factory_make('dv1394src') ImageBinElems.append(MyVideoSrc) #set demuxer ( separation image/sound) MyDemux = LG.element_factory_make("dvdemux", "demuxer") ImageBinElems.append(MyDemux) MyDemux.connect("pad-added", self.MyDemux_callback) self.MyVideodecoder = LG.element_factory_make("dvdec", "video-decoder") ImageBinElems.append(self.MyVideodecoder) # ffmpeg needed for pipe ; without the next elements dont understand the stream flow MyffmpegInput = LG.element_factory_make('ffmpegcolorspace') ImageBinElems.append(MyffmpegInput) for elem in ImageBinElems: self.add(elem) LG.element_link_many(MyVideoSrc, MyDemux) LG.element_link_many(self.MyVideodecoder, MyffmpegInput) #this bin has only a src ghostPad self.add_pad(LG.GhostPad('src', MyffmpegInput.get_pad('src')))
def __init__(self, width=640, height=480, framerate=(2, 25), source_input='v4l2src', device='/dev/video0'): """build webcam cam input bin Description of pipeline : | v4lsrc or v4l2src --> capsfilter --> ffmpegcolorspace --> ScaleBin | src pad params : width : The webcam width. Integer value height : The webcam width. Integer value framerate : The webcam framerate. A tuple for fraction representation (denom,num) source_input : The type of driver input. A string device : Path to webcam device. A string """ super(WebcamInputBin, self).__init__() ImageBinElems = [] MyVideoSrc = LG.element_factory_make(source_input) MyVideoSrc.set_property("device", device) ImageBinElems.append(MyVideoSrc) MyVideoSrcFilter = LG.element_factory_make("capsfilter", "MyVideoSrc") # create caps string according, width, height and framerate caps = LG.Caps( "video/x-raw-yuv, width=%s,height=%s , framerate=%s/%s " % (width, height, framerate[0], framerate[1])) self.logger.debug(" Webcam cap : %s" % caps.to_string()) MyVideoSrcFilter.set_property("caps", caps) ImageBinElems.append(MyVideoSrcFilter) MyyuvInput = LG.element_factory_make('ffmpegcolorspace') ImageBinElems.append(MyyuvInput) # scale Webcam Display to DV SCALE MyScaleBin = ScaleBin(width, height) ImageBinElems.append(MyScaleBin) for elem in ImageBinElems: self.add(elem) LG.element_link_many(MyVideoSrc, MyVideoSrcFilter, MyyuvInput, MyScaleBin) #this bin has only a src ghostPad self.add_pad(LG.GhostPad('src', MyScaleBin.get_pad('src')))
def __init__(self, _cb_capture_done): """ Description of pipeline : sink pad | videorate --> csp --> capsfilter --> fakesink | Jpeg conversion is done on demand, when a capture is requested, on the caalback. Jpeg conversion is done only when necessary from a pixbuf. """ super(PhotoSaveBin, self).__init__() self._cb_capture_done = _cb_capture_done self.capture_handler_id = 0 ImageBinElems = [] Myvideorate = LG.element_factory_make( 'videorate', 'ImageRate') # rate transformation ImageBinElems.append(Myvideorate) # csp transformation csp = LG.element_factory_make('ffmpegcolorspace', 'ImageCsp') ImageBinElems.append(csp) MyJpegFilter = LG.element_factory_make("capsfilter", "JpegFilter") # create caps string according, width, height and framerate caps = LG.Caps(self.JPEG_CAPS_FILTER) self.logger.debug(" Webcam cap : %s" % caps.to_string()) MyJpegFilter.set_property("caps", caps) ImageBinElems.append(MyJpegFilter) #MyJpegenc = LG.element_factory_make("jpegenc","MyJpegenc") # jpeg encoding #ImageBinElems.append(MyJpegenc) self.photosink = LG.element_factory_make("fakesink", "PhotoSink") self.photosink.set_property("signal-handoffs", 'true') ImageBinElems.append(self.photosink) for elem in ImageBinElems: self.add(elem) LG.element_link_many(Myvideorate, csp, MyJpegFilter, self.photosink) self.add_pad(LG.GhostPad('sink', Myvideorate.get_pad('sink')))
def __init__(self, width=640, height=480): """ Description of pipeline : sink pad | --> videoscale --> capsfilter --> videobox --> | src pad """ super(ScaleBin, self).__init__() ImageBinElems = [] # compute the image size if neeeded image_size_d = self.calc_video_size(float(width), float(height), MCONST.VIDEO_PAL_RES[0], MCONST.VIDEO_PAL_RES[1]) Myvideoscale = LG.element_factory_make('videoscale') # scale image ImageBinElems.append(Myvideoscale) MyVideoFilter = LG.element_factory_make("capsfilter") caps = LG.Caps("video/x-raw-yuv,width=%s,height=%s" % (image_size_d['width'], image_size_d['height'])) # scale image with caps MyVideoFilter.set_property("caps", caps) ImageBinElems.append(MyVideoFilter) MyVideoBox = LG.element_factory_make( 'videobox', "MyVideoBox") # videoBox where input video stream is displayed MyVideoBox.set_property('fill', 0) # fill with black # borders are negative values for videobox . postive value used dor crop MyVideoBox.set_property('top', -1 * image_size_d['top']) MyVideoBox.set_property('bottom', -1 * image_size_d['bottom']) MyVideoBox.set_property('left', -1 * image_size_d['left']) MyVideoBox.set_property('right', -1 * image_size_d['right']) ImageBinElems.append(MyVideoBox) # add bins for elem in ImageBinElems: self.add(elem) # link bins LG.element_link_many(Myvideoscale, MyVideoFilter, MyVideoBox) # this module has a sink pad and a src pad self.add_pad(LG.GhostPad('sink', Myvideoscale.get_pad('sink'))) self.add_pad(LG.GhostPad('src', MyVideoBox.get_pad('src')))
class Lcl_gst_sound(LG.lcl_gstreamer) : """ gstreamer : play a sound """ def __init__(self,soundfile,cb_error = None) : """ soundfile : The soundfile to play cb_error : callback arror function """ LG.lcl_gstreamer.__init__(self,video_widget = None, pipe_name = 'Sound pipe', cb_on_error = cb_error ) self._soundfile = soundfile # # Creation of gstreamer pipeline # # Create elements self.src = LG.element_factory_make('filesrc') self.src.set_property('location', self._soundfile) self.dec = LG.element_factory_make('decodebin') # Connect handler for 'new-decoded-pad' signal self.dec.connect('new-decoded-pad', self.on_new_decoded_pad) self.conv = LG.element_factory_make('audioconvert') self.rsmpl = LG.element_factory_make('audioresample') self.sink = LG.element_factory_make('alsasink') # # Add elements to pipeline # self.pipe.add(self.src, self.dec, self.conv, self.rsmpl, self.sink) # Linkelements self.src.link(self.dec) LG.element_link_many(self.conv, self.rsmpl, self.sink) # Reference used in self.on_new_decoded_pad() self.apad = self.conv.get_pad('sink') self._on_error = False
def __init__(self, alphaValueStream, image, alphaValueImage): """ Description of pipeline : sink pad | --> queue --> videorate --> videoscale --> capsfilter --> videobox --> videoMixer | src pad """ super(MixStreamAndImage, self).__init__() self.__image2Mix = image self.__alphaValueImage = alphaValueImage ImageBinElems = [] queueB2 = LG.element_factory_make("queue", "queueB2") # queue of branch 2 ImageBinElems.append(queueB2) Myvideorate = LG.element_factory_make( 'videorate') # rate transformation ImageBinElems.append(Myvideorate) Myvideoscale = LG.element_factory_make('videoscale') # scale image ImageBinElems.append(Myvideoscale) VideoFilter = LG.element_factory_make("capsfilter") caps = LG.Caps( "video/x-raw-yuv, framerate=(fraction)10/1, width=720,height=576" ) # scale image with caps VideoFilter.set_property("caps", caps) ImageBinElems.append(VideoFilter) MyVideoBox = LG.element_factory_make( 'videobox', "MyVideoBox") # videoBox where input video stream is displayed MyVideoBox.set_property('border-alpha', 0) MyVideoBox.set_property('alpha', alphaValueStream) ImageBinElems.append(MyVideoBox) # Video mixer : mix input in videobox with image MyVideomixer = LG.element_factory_make('videomixer', "MyVideomixer") # video mixer ImageBinElems.append(MyVideomixer) # input image to mix # create Bin for input Image self.ImageBin = InputImageBin(self.__image2Mix, alphaValueImage) ImageBinElems.append(self.ImageBin) for elem in ImageBinElems: self.add(elem) #input stream LG.element_link_many(queueB2, Myvideorate, Myvideoscale, VideoFilter, MyVideoBox, MyVideomixer) # mix with image self.ImageBin.link(MyVideomixer) # this module has a sink pad and a src pad self.add_pad(LG.GhostPad('sink', queueB2.get_pad('sink'))) self.add_pad(LG.GhostPad('src', MyVideomixer.get_pad('src')))
def __init__(self, image, alphaValue, framerate=1): """ Description of pipeline : | multifilesrc --> capsfilter --> jpegdec --> videoscale --> capsfilter --> alpha --> | src pad """ super(InputImageBin, self).__init__() self.__image2Mix = image self.__framerate = framerate self.__alphaValueImage = alphaValue ImageBinElems = [] # load input image self.InputImage = LG.element_factory_make('multifilesrc') self.InputImage.set_property('location', self.__image2Mix) ImageBinElems.append(self.InputImage) # filter to set frame rate self.ImageFilter = LG.element_factory_make("capsfilter") self._filter_caps_string = "image/jpeg, framerate=(fraction)%s/1 ,width=%s,height=%s " caps_string = self._filter_caps_string % ( self.__framerate, MCONST.VIDEO_PAL_RES[0], MCONST.VIDEO_PAL_RES[1]) caps = LG.Caps(caps_string) self.ImageFilter.set_property("caps", caps) ImageBinElems.append(self.ImageFilter) # dec jpeg as stream MyJpecdec = LG.element_factory_make('jpegdec') ImageBinElems.append(MyJpecdec) # scale image Myvideoscale = LG.element_factory_make('videoscale') ImageBinElems.append(Myvideoscale) # needed again for setting aspect ratio InputImageFilter = LG.element_factory_make( 'capsfilter', "InputImageFilter") # set filter on scale caps2 = LG.Caps("video/x-raw-yuv, width=%s,height=%s" % (MCONST.VIDEO_PAL_RES[0], MCONST.VIDEO_PAL_RES[1])) InputImageFilter.set_property("caps", caps2) ImageBinElems.append(InputImageFilter) self.MyAlpha = LG.element_factory_make("alpha") # set alpha of image self.MyAlpha.set_property("alpha", self.__alphaValueImage) ImageBinElems.append(self.MyAlpha) for elem in ImageBinElems: self.add(elem) LG.element_link_many(self.InputImage, self.ImageFilter, MyJpecdec, Myvideoscale, InputImageFilter, self.MyAlpha) self.add_pad(LG.GhostPad('src', self.MyAlpha.get_pad('src')))
def reset_pipe(self): """ Gstreamer pipe configuration : Build the elements according acquisition input, availablity of mixer, and set output to videop display and file. """ ElementList = [] self.pipe = LG.Pipeline(self.pipe_name) if (self.__inputType == MCONST.WEBCAM): InputBin = WebcamInputBin( width=self.__webcam_data['width'], height=self.__webcam_data['height'], framerate=self.__webcam_data['framerate_selected'], source_input=self.__webcam_data['source_input'], device=self.__webcam_data['device']) elif (self.__inputType == MCONST.DVCAM): InputBin = DvInputBin() else: InputBin = FakeInputBin() ElementList.append(InputBin) #create tee ( One for file sink, the other for video sink) MyTee = LG.element_factory_make("tee", "MyTee") ElementList.append(MyTee) # both "branch" of the tee are queued # # File queue # queueFile = LG.element_factory_make("queue", "queueFile") ElementList.append(queueFile) #fileSink = SaveCapturedImageBin(self.__CaptureImagePath) self.fileSink = PhotoSaveBin(self._cb_process_frame) ElementList.append(self.fileSink) # # Display queue # queueDisplay = LG.element_factory_make("queue", "queueDisplay") ElementList.append(queueDisplay) if (self.__mix == self.MIX): self.MixBin = MixStreamAndImage(self.__alphaStream, self.__image2Mix, self.__alphaImage) ElementList.append(self.MixBin) DisplaySink = DisplayBin() ElementList.append(DisplaySink) # # Add elements to pipeline # for elem in ElementList: self.pipe.add(elem) # # link pipeline elements # #link input LG.element_link_many(InputBin, MyTee) # link tee File branch LG.element_link_many(MyTee, queueFile, self.fileSink) #link tee display Branch LG.element_link_many(MyTee, queueDisplay) if (self.__mix == self.MIX): LG.element_link_many(queueDisplay, self.MixBin, DisplaySink) else: LG.element_link_many(queueDisplay, DisplaySink) self.on_eos = False # usage tbd # connect bus LG.lcl_gstreamer.connect_bus(self)