def start(self): width = CAM_RESOLUTIONS[prefs.webcam_resolution][0] height = CAM_RESOLUTIONS[prefs.webcam_resolution][1] self.video_src = Gst.ElementFactory.make("v4l2src", "video_src") self.q_video_src = Gst.ElementFactory.make("queue", "queue_video_source") self.video_src.set_property( "device", prefs.webcam_sources[prefs.webcam_source][0]) logger.debug("Webcam source: {}".format( prefs.webcam_sources[prefs.webcam_source][0])) caps_str = "video/x-raw, framerate={}/1, width={}, height={}" self.video_caps = Gst.caps_from_string( caps_str.format(int(prefs.framerate), width, height)) self.f_video_caps = Gst.ElementFactory.make("capsfilter", "vid_filter") self.f_video_caps.set_property("caps", self.video_caps) self.screen_queue = Gst.ElementFactory.make("queue", "screen_queue") self.screen_sink = Gst.ElementFactory.make("xvimagesink", "screen_sink") self.pipeline.add(self.video_src) self.pipeline.add(self.f_video_caps) self.pipeline.add(self.q_video_src) self.pipeline.add(self.screen_queue) self.pipeline.add(self.screen_sink) self.cam_window = WebcamWindow( CAM_RESOLUTIONS[prefs.webcam_resolution][0], CAM_RESOLUTIONS[prefs.webcam_resolution][1], prefs.webcam_preview_pos) self.cam_xid = self.cam_window.xid self.video_src.link(self.f_video_caps) self.f_video_caps.link(self.q_video_src) self.q_video_src.link(self.screen_queue) self.screen_queue.link(self.screen_sink) self.pipeline.set_state(Gst.State.PLAYING)
def start(self): width = CAM_RESOLUTIONS[prefs.webcam_resolution][0] height = CAM_RESOLUTIONS[prefs.webcam_resolution][1] self.pipeline = Gst.parse_launch( "v4l2src ! videoscale ! video/x-raw,framerate={}/1,width={},height={} ! autovideosink" .format(int(prefs.framerate), width, height)) self.bus = self.pipeline.get_bus() self.bus.add_signal_watch() self.bus.connect("message::eos", self.on_eos) self.bus.connect("message::error", self.on_error) self.bus.enable_sync_message_emission() self.bus.connect('sync-message::element', self.on_sync_message) self.cam_window = WebcamWindow( CAM_RESOLUTIONS[prefs.webcam_resolution][0], CAM_RESOLUTIONS[prefs.webcam_resolution][1], prefs.webcam_preview_pos) self.cam_xid = self.cam_window.xid self.pipeline.set_state(Gst.State.PLAYING)
def setup_links(self): # Connect everything together if self.mode == MODE_BROADCAST: ret = self.video_src.link(self.q_video_src) logger.debug("Link video_src -> q_video_src: {}".format(ret)) else: ret = self.video_src.link(self.f_video_caps) logger.debug("Link video_src -> f_video_caps: {}".format(ret)) ret = self.f_video_caps.link(self.q_video_src) logger.debug("Link f_video_caps -> q_video_src: {}".format(ret)) if self.mode == MODE_WEBCAM and prefs.webcam_show_preview is True: # Setup camera preview window self.cam_window = WebcamWindow( CAM_RESOLUTIONS[prefs.webcam_resolution][0], CAM_RESOLUTIONS[prefs.webcam_resolution][1], prefs.webcam_preview_pos) self.cam_xid = self.cam_window.xid # Build the pipeline self.q_video_src.link(self.tee) self.tee.link(self.video_rate) self.tee.link(self.video_flip) self.video_flip.link(self.screen_queue) self.screen_queue.link(self.screen_sink) else: if self.crop_vid and self.mode is not MODE_BROADCAST: ret = self.q_video_src.link(self.video_crop) logger.debug("Link q_video_src -> video_crop {}".format(ret)) ret = self.video_crop.link(self.video_rate) logger.debug("Link video_crop -> video_rate {}".format(ret)) if self.mode == MODE_BROADCAST: ret = self.q_video_src.link(self.video_convert) logger.debug( "Link q_video_src -> video_convert {}".format(ret)) else: ret = self.q_video_src.link(self.video_rate) logger.debug("Link q_video_src -> video_rate {}".format(ret)) ret = self.video_rate.link(self.video_convert) logger.debug( "Link video_rate -> video_convert: {}".format(ret)) if prefs.codec is CODEC_RAW and self.mode is not MODE_BROADCAST: self.video_convert.link(self.q_video_out) logger.debug("Linking RAW Video") else: logger.debug("Linking Video") if self.mode == MODE_BROADCAST: ret = self.video_convert.link(self.f_video_convert_caps) logger.debug( "Link video_convert f_video_convert_caps {}".format(ret)) ret = self.f_video_convert_caps.link(self.video_enc) logger.debug( "Link f_video_convert_caps -> video_enc {}".format(ret)) ret = self.video_enc.link(self.video_parse) logger.debug("Link video_enc -> video_parse {}".format(ret)) ret = self.video_parse.link(self.f_video_parse_caps) logger.debug( "Link video_parse -> f_video_parse_caps {}".format(ret)) ret = self.f_video_parse_caps.link(self.q_video_out) logger.debug( "Link f_video_parse_caps -> q_video_out {}".format(ret)) else: ret = self.video_convert.link(self.video_enc) logger.debug("Link video_convert -> video_enc {}".format(ret)) ret = self.video_enc.link(self.q_video_out) logger.debug("Link video_enc -> q_video_out {}".format(ret)) ret = self.q_video_out.link(self.mux) logger.debug("Link q_video_out -> mux {}".format(ret)) if self.audio_source and self.audio2_source: logger.debug("Linking Audio") ret = self.audiosrc.link(self.aud_in_queue) logger.debug(" Link audiosrc -> aud_in_queue: %s" % ret) ret = self.aud_in_queue.link(self.f_aud_caps) logger.debug(" Link aud_in_queue -> aud_caps_filter: %s" % ret) logger.debug("Linking Audio2") # Link first audio source to mixer ret = self.f_aud_caps.link(self.audiomixer) logger.debug(" Link aud_caps_filter -> audiomixer: %s" % ret) # Link second audio source to mixer ret = self.audio2src.link(self.aud2_in_queue) logger.debug(" Link audio2src -> aud2_in_queue: %s" % ret) ret = self.aud2_in_queue.link(self.f_aud2_caps) logger.debug(" Link aud2_in_queue -> aud2_caps_filter: %s" % ret) ret = self.f_aud2_caps.link(self.audiomixer) logger.debug(" Link aud2_caps_filter -> audiomixer: %s" % ret) # Link mixer to audio convert ret = self.audiomixer.link(self.audioconv) logger.debug(" Link audiomixer -> audioconv: %s" % ret) elif self.audio_source: logger.debug("Linking Audio") ret = self.audiosrc.link(self.aud_in_queue) logger.debug(" Link audiosrc -> aud_in_queue: %s" % ret) ret = self.aud_in_queue.link(self.f_aud_caps) logger.debug(" Link aud_in_queue -> aud_caps_filter: %s" % ret) # Link first audio source to audio convert ret = self.f_aud_caps.link(self.audioconv) logger.debug(" Link aud_caps_filter -> audioconv: %s" % ret) elif self.audio2_source: # Link second audio source to mixer ret = self.audio2src.link(self.aud2_in_queue) logger.debug(" Link audio2src -> aud2_in_queue: %s" % ret) ret = self.aud2_in_queue.link(self.f_aud2_caps) logger.debug(" Link aud2_in_queue -> aud2_caps_filter: %s" % ret) # Link second audio source to audio convert ret = self.f_aud2_caps.link(self.audioconv) logger.debug(" Link aud2_caps_filter -> audioconv: %s" % ret) if self.audio_source or self.audio2_source: # Link audio to muxer ret = self.audioconv.link(self.audioenc) logger.debug("Link audioconv -> audioenc: %s" % ret) ret = self.audioenc.link(self.aud_out_queue) logger.debug("Link audioenc -> aud_out_queue: %s" % ret) if self.mode == MODE_BROADCAST: ret = self.aud_out_queue.link(self.aacparse) logger.debug("Link aud_out_queue -> aacparse: {}".format(ret)) ret = self.aacparse.link(self.f_aacparse_caps) logger.debug( "Link aacparse -> f_aacparse_caps: {}".format(ret)) ret = self.f_aacparse_caps.link(self.mux) logger.debug( "Link aacparse_caps_filter -> mux: {}".format(ret)) else: ret = self.aud_out_queue.link(self.mux) logger.debug("Link aud_out_queue -> mux: %s" % ret) ret = self.mux.link(self.final_queue) logger.debug("Link mux -> file queue: %s" % ret) ret = self.final_queue.link(self.sink) if self.mode == MODE_BROADCAST: logger.debug("Link final queue -> rtmp sink: {}".format(ret)) else: logger.debug("Link final queue -> file sink: {}".format(ret))