Пример #1
0
    def create_elements(self):
        pipeline_string = 'audiotestsrc is-live=true name=audiotestsrc volume=0.2 ! ' + \
            config.default_audio_caps() + self.default_audio_pipeline_string_end()

        self.create_pipeline_from_string(pipeline_string)

        self.final_audio_tee = self.pipeline.get_by_name('final_audio_tee')
        self.audiotestsrc = self.pipeline.get_by_name('audiotestsrc')
Пример #2
0
Файл: tcp.py Проект: ottes/brave
    def create_elements(self):
        '''
        Create the elements needed whether this is audio, video, or both
        '''
        mux_type = 'oggmux' if self.container == 'ogg' else 'mpegtsmux'
        video_encoder_type = 'theoraenc' if self.container == 'ogg' else 'x264enc'
        audio_encoder_type = 'vorbisenc' if self.container == 'ogg' else 'avenc_ac3'

        pipeline_string = 'queue name=queue ! tcpserversink name=sink'

        # We only want a mux if there's video:
        has_mux = config.enable_video
        if has_mux:
            pipeline_string = f'{mux_type} name=mux ! {pipeline_string}'

        if config.enable_video():
            pipeline_string += ' ' + self._video_pipeline_start(
            ) + video_encoder_type + ' name=encoder ! queue ! mux.'

        if config.enable_audio():
            audio_bitrate = self.audio_bitrate

            # Having default_audio_caps() in the pipeline stops them from changing and interrupting the encoder.
            audio_pipeline_string = ('interaudiosrc name=interaudiosrc ! ' + config.default_audio_caps() +
                                     ' ! audioconvert ! audioresample ! %s name=audio_encoder bitrate=%d') % \
                (audio_encoder_type, audio_bitrate)
            if has_mux:
                audio_pipeline_string += f' ! queue ! mux.'
            else:
                audio_pipeline_string += ' ! queue.'

            pipeline_string = pipeline_string + ' ' + audio_pipeline_string

        self.create_pipeline_from_string(pipeline_string)

        if config.enable_video():
            # pass
            if self.container == 'mpeg':
                # Testing has shown 60 (i.e. once every 2s at 30 fps) works best
                self.pipeline.get_by_name('encoder').set_property(
                    'key-int-max', 60)

            # tune=zerolatency reduces the delay of TCP output
            # self.pipeline.get_by_name('encoder').set_property('tune', 'zerolatency')

        if not hasattr(self, 'host'):
            self.host = socket.gethostbyname(socket.gethostname())
        if not hasattr(self, 'port'):
            self.port = self._get_next_available_port()

        sink = self.pipeline.get_by_name('sink')
        sink.set_property('port', int(self.port))
        sink.set_property('host', self.host)
        sink.set_property('recover-policy', 'keyframe')
        sink.set_property('sync', False)

        self.logger.info('TCP output created at tcp://%s:%s' %
                         (self.host, self.port))
Пример #3
0
    def create_elements(self):
        '''
        Creates the pipeline with elements needed to accept a TCP connection.
        '''

        # We support ogg and mpeg containers; the right demuxer must be used:
        demux_element = 'oggdemux' if self.container == 'ogg' else 'tsdemux'

        # We start with tcpclientsrc, and immediately demux it into audio and video.
        pipeline_string = 'tcpclientsrc name=tcpclientsrc ! %s name=demux ' % demux_element

        if self.has_video():
            # We need to decode the video:
            pipeline_string += (
                ' queue2 max-size-time=3000000000 name=demux_to_video_queue ! '
                'decodebin name=video_decodebin ')
            # This then can be connected to the common bit of the pipeline:
            pipeline_string += self.default_video_pipeline_string_end()

        if self.has_audio():
            # The audio part also needs a decodebin:
            pipeline_string += (
                ' queue2 max-size-time=3000000000 name=demux_to_audio_queue'
                ' ! decodebin name=audio_decodebin')

            # We will then connect this decodebin to aan audio convert/resample
            pipeline_string += ' audioconvert name=audioconvert ! audioresample ! ' + \
                config.default_audio_caps() + \
                self.default_audio_pipeline_string_end()

        self.create_pipeline_from_string(pipeline_string)
        tcpclientsrc = self.pipeline.get_by_name('tcpclientsrc')
        tcpclientsrc.set_property('host', self.host)
        tcpclientsrc.set_property('port', self.port)

        if self.has_video():
            self.final_video_tee = self.pipeline.get_by_name('final_video_tee')
            self.demux_to_video_queue = self.pipeline.get_by_name(
                'demux_to_video_queue')
            self.video_element_after_demux = self.pipeline.get_by_name(
                'video_output_queue')
            video_decodebin = self.pipeline.get_by_name('video_decodebin')
            video_decodebin.connect('pad-added', self._on_decodebin_pad_added)

        if self.has_audio():
            self.final_audio_tee = self.pipeline.get_by_name('final_audio_tee')
            self.demux_to_audio_queue = self.pipeline.get_by_name(
                'demux_to_audio_queue')
            self.audio_element_after_demux = self.pipeline.get_by_name(
                'audioconvert')
            audio_decodebin = self.pipeline.get_by_name('audio_decodebin')
            audio_decodebin.connect('pad-added', self._on_decodebin_pad_added)

        demux = self.pipeline.get_by_name('demux')
        demux.connect('pad-added', self._on_demux_pad_added)
Пример #4
0
    def create_elements(self):
        pipeline_string = 'audiotestsrc is-live=true name=audiotestsrc volume=0.2 ! ' + \
            config.default_audio_caps() + ' ! interaudiosink name=interaudiosink'

        if not self.create_pipeline_from_string(pipeline_string):
            return False

        self.interaudiosink = self.pipeline.get_by_name('interaudiosink')
        self.audiotestsrc = self.pipeline.get_by_name('audiotestsrc')
        self.create_interaudiosrc_and_connections()
        self.handle_updated_props()