Пример #1
0
    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')))
Пример #2
0
    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')))
Пример #3
0
    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')))
Пример #4
0
    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')))
Пример #5
0
    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')))
Пример #6
0
    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')))
Пример #7
0
    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')))
Пример #8
0
    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')))