def handoff(self, element, buffer):
        self.frame_count += 1
        if (self.frame_count %
            (self.framerate * self.__RESOLUTION_CHANGE_INTERVAL) == 0):
            try:
                tmp = self.tested_resolutions[self.index].split(",")
            except IndexError:
                # no more format changes
                return True

            target_res = tmp[0]
            target_bitrate = int(tmp[1])
            target_fps = int(tmp[2])
            target_format = tmp[3]

            self.index += 1
            enc = self.pipeline.get_by_name("encoder")
            enc.props.bitrate = target_bitrate
            caps = self.pipeline.get_by_name("capsf")
            print "Previous caps: " + str(caps.get_property("caps"))

            width, height = [int(x) for x in target_res.split("x")]
            s = gst.Structure("video/x-raw-yuv")
            s["format"] = gst.Fourcc(target_format)
            s["width"] = width
            s["height"] = height
            s["framerate"] = gst.Fraction(target_fps, 1)
            caps.set_property("caps", gst.Caps(s))
            print "Switched to: " + str(caps.get_property("caps"))

        return True
示例#2
0
文件: mixer.py 项目: qlf/Pitivi
 def alphaStateChanged(self, has_alpha):
     """Updates capsfilter caps to reflect the alpha state of composition"""
     caps = gst.Caps('video/x-raw-yuv')
     if has_alpha == True:
         caps[0]["format"] = gst.Fourcc('AYUV')
     for input in self.inputs.values():
         input[2].props.caps = caps
示例#3
0
    def testVideoProperties(self):
        expected = {
            'videotype': 'video/x-raw-rgb',
            'width': 320,
            'height': 240,
            'framerate': gst.Fraction(30, 1),
            'format': None,
            'par': gst.Fraction(1, 1),
            'dar': gst.Fraction(4, 3)
        }
        stream = VideoStream(self.unfixed_caps)
        self.checkProperties(stream, expected)

        expected['videotype'] = 'video/x-raw-yuv'
        expected['format'] = gst.Fourcc('I420')
        stream = VideoStream(self.fixed_caps)
        self.checkProperties(stream, expected)

        expected['videotype'] = 'video/x-theora'
        expected['width'] = None
        expected['height'] = None
        expected['format'] = None
        expected['framerate'] = gst.Fraction(1, 1)
        stream = VideoStream(self.non_raw_caps)
        self.checkProperties(stream, expected)
示例#4
0
 def has_alpha(self):
     if self.videotype == "video/x-raw-rgb":
         return ((hasattr(self, 'bpp') and (self.bpp == 32))
                 and (hasattr(self, 'depth') and (self.depth == 32)))
     elif self.videotype == "video/x-raw-yuv":
         return (hasattr(self, 'format')
                 and self.format == gst.Fourcc('AYUV'))
     return False
示例#5
0
    def create_pipeline(self):
        p = gst.Pipeline()

        width, height = self.framesize.split("x")
        width, height = int(width), int(height)

        if self.location:
            src = gst.element_factory_make("filesrc")
            src.props.location = self.location
            if self.format == "I420":
                bpp = 1.5
            elif self.format == "UYVY":
                bpp = 2
            src.props.blocksize = int(width * height * bpp)
        else:
            src = gst.element_factory_make("videotestsrc")

        src.props.num_buffers = self.num_buffers
        bitrate = self.bitrate
        enc = gst.element_factory_make(self.element)

        if self.mode is not None:
            enc.props.mode = self.mode

        if bitrate:
            enc.props.bitrate = bitrate

        sink = gst.element_factory_make("fakesink")

        s = gst.Structure("video/x-raw-yuv")
        s["format"] = gst.Fourcc(self.format)
        s["width"] = width
        s["height"] = height
        s["framerate"] = gst.Fraction(self.framerate, 1)

        tee = gst.element_factory_make("tee")
        queue = gst.element_factory_make("multiqueue")
        ssim = gst.element_factory_make("xssim")
        dec = gst.element_factory_make("avvdec")

        p.add(tee, queue, ssim, dec)

        capf = gst.element_factory_make("capsfilter")
        capf.props.caps = gst.Caps(s)

        p.add(src, capf, enc, sink)
        gst.element_link_many(src, capf, tee)
        gst.element_link_many(tee, enc, dec, queue, ssim)

        ssim.connect("got_results", self.got_results)

        gst.element_link_many(tee, queue, ssim)
        ssim.link(sink)
        return p
示例#6
0
	def create_pipeline(self):
		p = gst.Pipeline()

		width, height = self.framesize.split("x")
		width, height = int(width), int(height)
		if self.location:
			src = gst.element_factory_make("filesrc")
			src.props.location = self.location
			if self.format == "I420":
				bpp = 1.5
			elif self.format == "UYVY":
				bpp = 2
			src.props.blocksize = int(width * height * bpp)
		else:
			src = gst.element_factory_make("videotestsrc")
		src.props.num_buffers = self.num_buffers

		self.bitrates = self.bitrateseq.split(',')
		bitrate = self.bitrate
		enc = gst.element_factory_make(self.element, "encoder")
		enc.props.bitrate = bitrate
		enc.props.max_bitrate = self.max_bitrate

		if self.mode is not None:
			enc.props.mode = self.mode

		if self.intra_refresh is not None:
			enc.props.intra_refresh = self.intra_refresh

		s = gst.Structure("video/x-raw-yuv")
		s["format"] = gst.Fourcc(self.format)
		s["width"] = width
		s["height"] = height
		s["framerate"] = gst.Fraction(self.framerate, 1)

		capf_raw = gst.element_factory_make("capsfilter")
		capf_raw.props.caps = gst.Caps(s)

		ident = gst.element_factory_make("identity")
		videorate = gst.element_factory_make("videorate")
		sink = gst.element_factory_make("fakesink")

		p.add(src, capf_raw, videorate, enc, ident, sink)
		gst.element_link_many(src, capf_raw, videorate, enc, ident, sink)

		ident.connect("handoff", self.handoff)
		ident.set_property("signal-handoffs", True)

		return p
    def create_pipeline(self):
        p = gst.Pipeline()

        width, height = self.framesize.split("x")
        width, height = int(width), int(height)

        src = gst.element_factory_make("videotestsrc")
        src.props.num_buffers = self.num_buffers
        bitrate = self.bitrate
        scaler = gst.element_factory_make("videoscale")

        enc = gst.element_factory_make(self.element, "encoder")

        if self.mode is not None:
            enc.props.mode = self.mode

        if self.intra_refresh is not None:
            enc.props.intra_refresh = self.intra_refresh

        enc.props.bitrate = bitrate
        ident = gst.element_factory_make("identity")

        sink = gst.element_factory_make("fakesink")

        s = gst.Structure("video/x-raw-yuv")
        s["format"] = gst.Fourcc(self.format)
        s["width"] = width
        s["height"] = height
        s["framerate"] = gst.Fraction(self.framerate, 1)

        caps = gst.element_factory_make("capsfilter", "capsf")
        caps.props.caps = gst.Caps(s)

        p.add(src, scaler, caps, enc, ident, sink)
        gst.element_link_many(src, scaler, caps, enc, ident, sink)

        ident.connect("handoff", self.handoff)
        ident.set_property("signal-handoffs", True)
        return p
示例#8
0
    def create_pipeline(self):
        p = gst.Pipeline()

        width, height = self.framesize.split("x")
        width, height = int(width), int(height)

        if self.location:
            src = gst.element_factory_make("filesrc")
            src.props.location = self.location
            if self.format == "I420":
                bpp = 1.5
            elif self.format == "UYVY":
                bpp = 2
            src.props.blocksize = int(width * height * bpp)
        else:
            src = gst.element_factory_make("videotestsrc")
            src.props.num_buffers = self.num_buffers

        enc = gst.element_factory_make(self.element)
        enc.props.bitrate = self.bitrate

        sink = gst.element_factory_make("filesink")
        sink.props.location = self.tmp_filename

        s = gst.Structure("video/x-raw-yuv")
        s["format"] = gst.Fourcc(self.format)
        s["width"] = width
        s["height"] = height
        s["framerate"] = gst.Fraction(self.framerate, 1)

        capf = gst.element_factory_make("capsfilter")
        capf.props.caps = gst.Caps(s)
        p.add(src, capf, enc, sink)

        if not gst.element_link_many(src, capf, enc, sink):
            print " pipeline creation error !!"

        return p