Python gi.repository.Gst.SECOND Examples

The following are 30 code examples of gi.repository.Gst.SECOND(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gst , or try the search function .
Example #1
Source File: seek.py    From gstreamer-python-player with MIT License 6 votes vote down vote up
def update_slider(self):
        if not self.is_playing:
            return False # cancel timeout
            
        else:
            success, self.duration = self.playbin.query_duration(Gst.Format.TIME)
            if not success:
                raise GenericException("Couldn't fetch song duration")
            else:
                self.slider.set_range(0, self.duration / Gst.SECOND)
            #fetching the position, in nanosecs
            success, position = self.playbin.query_position(Gst.Format.TIME)
            if not success:
                raise GenericException("Couldn't fetch current song position to update slider")

            # block seek handler so we don't seek when we set_value()
            self.slider.handler_block(self.slider_handler_id)

            self.slider.set_value(float(position) / Gst.SECOND)

            self.slider.handler_unblock(self.slider_handler_id)

        return True # continue calling every x milliseconds 
Example #2
Source File: modules.py    From gpt with GNU General Public License v3.0 6 votes vote down vote up
def on_slider_seek(self, widget):
        if self.uri.endswith(".JPG"):
            seek_intvl = ply.slider.get_value()
            files = len(os.listdir("Images_100"))
            seek_file = int((files * seek_intvl) / 100)
            self.clear_playbin()
            self.setup_player(os.path.join("Images_100",
                                           sorted(os.listdir("Images_100"))[seek_file]),
                              )
            self.pause()
        elif not self.uri.endswith(".png"):
            seek_time = ply.slider.get_value()
            self.player.seek_simple(Gst.Format.TIME,
                                    Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,
                                    seek_time * Gst.SECOND / self.mult,
                                    ) 
Example #3
Source File: player.py    From lplayer with MIT License 6 votes vote down vote up
def set_position(self, position):
        if self.player is not None:
            self.player.get_state(Gst.CLOCK_TIME_NONE)
            self.player.set_state(Gst.State.PAUSED)
            try:
                assert self.player.seek_simple(Gst.Format.TIME,
                                               Gst.SeekFlags.FLUSH,
                                               position * Gst.SECOND)
                self.player.get_state(Gst.CLOCK_TIME_NONE)
                pos = self.player.query_position(Gst.Format.TIME)[1]
                self.player.seek(self.speed, Gst.Format.TIME,
                                 Gst.SeekFlags.FLUSH, Gst.SeekType.SET, pos,
                                 Gst.SeekType.NONE, -1)
            except AssertionError as e:
                print(e)
            self.player.set_state(Gst.State.PLAYING) 
Example #4
Source File: gstreamer.py    From pyglet with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_audio_data(self, num_bytes, compensation_time=0.0):
        if self._finished.is_set():
            return None

        data = bytes()
        while len(data) < num_bytes:
            packet = self._queue.get()
            if packet == self._sentinal:
                self._finished.set()
                break
            data += packet

        if not data:
            return None

        timestamp = self._pipeline.query_position(Gst.Format.TIME).cur / Gst.SECOND
        duration = self.audio_format.bytes_per_second / len(data)

        return AudioData(data, len(data), timestamp, duration, []) 
Example #5
Source File: connection_to_mixer.py    From brave with Apache License 2.0 6 votes vote down vote up
def _create_intersrc(self, audio_or_video):
        '''
        Create the intervideosrc / interaudiosrc
        '''
        assert(audio_or_video in ['audio', 'video'])

        # Create the receiving 'inter' element to accept the AV into the main pipeline
        self._intersrc_element[audio_or_video] =\
            self._add_element_to_dest_pipeline('inter%ssrc' % audio_or_video, audio_or_video)

        # We ask the src to hold the frame for 24 hours (basically, a very long time)
        # This is optional, but prevents it from going black when it's better to show the last frame.
        if audio_or_video is 'video':
            self._intersrc_element[audio_or_video].set_property('timeout', Gst.SECOND * 60 * 60 * 24)

        return self._intersrc_element[audio_or_video] 
Example #6
Source File: gstreamer.py    From pyglet with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _notify_caps(self, pad, *args):
        """notify::caps callback"""
        self._caps = True
        info = pad.get_current_caps().get_structure(0)

        self._duration = pad.get_peer().query_duration(Gst.Format.TIME).duration / Gst.SECOND
        channels = info.get_int('channels')[1]
        sample_rate = info.get_int('rate')[1]
        sample_size = int("".join(filter(str.isdigit, info.get_string('format'))))

        self.audio_format = AudioFormat(channels=channels,
                                        sample_size=sample_size,
                                        sample_rate=sample_rate)

        # Allow __init__ to complete:
        self._is_ready.set() 
Example #7
Source File: player.py    From Audio-Cutter with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self):
        GObject.GObject.__init__(self)
        GstPbutils.pb_utils_init()
        self._discoverer = GstPbutils.Discoverer.new(10 * Gst.SECOND)

        self.is_playing = False
        self.filepath = None
        self._duration = Gst.CLOCK_TIME_NONE
        self.asset = None

        self._playbin = Gst.ElementFactory.make("playbin", "player")
        bus = self._playbin.get_bus()
        bus.add_signal_watch()
        bus.connect("message::error", self.__on_bus_error)
        bus.connect("message::eos", self.__on_bus_eos)
        bus.connect("message::element", self.__on_bus_element)
        bus.connect("message::stream-start", self._on_stream_start) 
Example #8
Source File: audio_gi.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _get_length(self):
        if self._data is not None:
            if self._data.get_state()[1] != Gst.State.PLAYING:
                volume_before = self._data.get_property('volume')
                self._data.set_property('volume', 0)
                self._data.set_state(Gst.State.PLAYING)
                try:
                    self._data.get_state()
                    ret, value = self._data.query_duration(Gst.Format.TIME)
                    if ret:
                        return value / float(Gst.SECOND)
                finally:
                    self._data.set_state(Gst.State.NULL)
                    self._data.set_property('volume', volume_before)
            else:
                ret, value = self._data.query_duration(Gst.Format.TIME)
                if ret:
                    return value / float(Gst.SECOND)
        return super(SoundGi, self)._get_length() 
Example #9
Source File: audio_gi.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _get_length(self):
        if self._data is not None:
            if self._data.get_state()[1] != Gst.State.PLAYING:
                volume_before = self._data.get_property('volume')
                self._data.set_property('volume', 0)
                self._data.set_state(Gst.State.PLAYING)
                try:
                    self._data.get_state()
                    ret, value = self._data.query_duration(Gst.Format.TIME)
                    if ret:
                        return value / float(Gst.SECOND)
                finally:
                    self._data.set_state(Gst.State.NULL)
                    self._data.set_property('volume', volume_before)
            else:
                ret, value = self._data.query_duration(Gst.Format.TIME)
                if ret:
                    return value / float(Gst.SECOND)
        return super(SoundGi, self)._get_length() 
Example #10
Source File: player.py    From pomodoro-indicator with GNU General Public License v3.0 6 votes vote down vote up
def set_position(self, position):
        if self.player is not None:
            self.player.get_state(Gst.CLOCK_TIME_NONE)
            self.player.set_state(Gst.State.PAUSED)
            try:
                assert self.player.seek_simple(Gst.Format.TIME,
                                               Gst.SeekFlags.FLUSH,
                                               position * Gst.SECOND)
                self.player.get_state(Gst.CLOCK_TIME_NONE)
                pos = self.player.query_position(Gst.Format.TIME)[1]
                self.player.seek(self.speed, Gst.Format.TIME,
                                 Gst.SeekFlags.FLUSH, Gst.SeekType.SET, pos,
                                 Gst.SeekType.NONE, -1)
            except AssertionError as e:
                print(e)
            self.player.set_state(Gst.State.PLAYING) 
Example #11
Source File: audio_gi.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def seek(self, position):
        if self._data is None:
            return
        self._data.seek_simple(
            Gst.Format.TIME, Gst.SeekFlags.SKIP, position * Gst.SECOND) 
Example #12
Source File: base.py    From AstroBox with GNU Affero General Public License v3.0 5 votes vote down vote up
def run(self):
		while not self._stopped:
			msg = self._bus.timed_pop(Gst.SECOND)
			if not self._stopped and msg:
				t = msg.type

				if t in self._listenersByEvents:
					for l in self._listenersByEvents[t]:
						self._listeners[l][1](msg) 
Example #13
Source File: audio_gi.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def get_pos(self):
        if self._data is not None:
            if self._data.get_state()[1] == Gst.State.PLAYING:
                try:
                    ret, value = self._data.query_position(Gst.Format.TIME)
                    if ret:
                        return value / float(Gst.SECOND)
                except:
                    pass
        return 0 
Example #14
Source File: video_gi.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def _get_position(self):
        try:
            ret, value = self._appsink.query_position(Gst.Format.TIME)
            if ret:
                return value / float(Gst.SECOND)
        except:
            pass
        return -1 
Example #15
Source File: video_gi.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def _get_duration(self):
        try:
            ret, value = self._playbin.query_duration(Gst.Format.TIME)
            if ret:
                return value / float(Gst.SECOND)
        except:
            pass
        return -1 
Example #16
Source File: audio_gi.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def get_pos(self):
        if self._data is not None:
            if self._data.get_state()[1] == Gst.State.PLAYING:
                try:
                    ret, value = self._data.query_position(Gst.Format.TIME)
                    if ret:
                        return value / float(Gst.SECOND)
                except:
                    pass
        return 0 
Example #17
Source File: video_gi.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def _get_position(self):
        try:
            ret, value = self._appsink.query_position(Gst.Format.TIME)
            if ret:
                return value / float(Gst.SECOND)
        except:
            pass
        return -1 
Example #18
Source File: video_gi.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def _get_duration(self):
        try:
            ret, value = self._playbin.query_duration(Gst.Format.TIME)
            if ret:
                return value / float(Gst.SECOND)
        except:
            pass
        return -1 
Example #19
Source File: audiotsmgtk.py    From audiotsm with MIT License 5 votes vote down vote up
def format_time(time):
    """Format a time as "minutes:seconds"."""
    minutes, seconds = divmod(time // Gst.SECOND, 60)
    return "{}:{:02d}".format(minutes, seconds) 
Example #20
Source File: base.py    From audiotsm with MIT License 5 votes vote down vote up
def do_transform(self, in_buffer, out_buffer):
        """Run the data of ``in_buffer`` through the
        :class:`~audiotsm.base.tsm.TSM` object and write the output to
        ``out_buffer``.

        :param in_buffer: a ``Gst.Buffer`` containing the input data.
        :param out_buffer: a ``Gst.Buffer`` where the output data will be
            written.
        """
        # There is a bug that increases the refcount of out_buffer, making it
        # non writable (https://bugzilla.gnome.org/show_bug.cgi?id=727702#c4).
        # Set the refcount to 1 to fix this.
        refcount = out_buffer.mini_object.refcount
        out_buffer.mini_object.refcount = 1

        # Set the position of the output buffer
        out_buffer.pts = self._position

        # Run the TSM procedure
        reader = ArrayReader(self._gstbuffer_to_ndarray(in_buffer))
        writer = ArrayWriter(self._channels)

        self._tsm.run(reader, writer, flush=False)

        self._ndarray_to_gstbuffer(out_buffer, writer.data)
        out_buffer.duration = (
            (out_buffer.get_size() * Gst.SECOND) //
            (self._bps * self._samplerate)
        )
        self._position += out_buffer.duration

        # Reset the refcount
        out_buffer.mini_object.refcount = refcount

        return Gst.FlowReturn.OK 
Example #21
Source File: seek.py    From gstreamer-python-player with MIT License 5 votes vote down vote up
def on_slider_seek(self, widget):
        seek_time_secs = self.slider.get_value()
        self.playbin.seek_simple(Gst.Format.TIME,  Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, seek_time_secs * Gst.SECOND) 
    
    #called periodically by the Glib timer, returns false to stop the timer 
Example #22
Source File: gstreamer.py    From pyglet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def seek(self, timestamp):
        # First clear any data in the queue:
        while not self._queue.empty():
            self._queue.get_nowait()

        self._pipeline.seek_simple(Gst.Format.TIME,
                                   Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,
                                   timestamp * Gst.SECOND)
        self._finished.clear()


#########################################
#   Decoder class:
######################################### 
Example #23
Source File: modules.py    From gpt with GNU General Public License v3.0 5 votes vote down vote up
def skip_minute(self, direction=1):
        self.player.seek_simple(Gst.Format.TIME,
                                Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,
                                self.current_position() + float(60) * Gst.SECOND * direction,
                                ) 
Example #24
Source File: util.py    From AstroBox with GNU Affero General Public License v3.0 5 votes vote down vote up
def waitToReachState(element, state, timeout= 3.0, attempts= 1):
	import logging
	while attempts:
		stateReturn, currentState, pending = element.get_state( (timeout * Gst.SECOND) if timeout != Gst.CLOCK_TIME_NONE else Gst.CLOCK_TIME_NONE)
		if currentState == state and ( stateReturn == Gst.StateChangeReturn.SUCCESS or stateReturn == Gst.StateChangeReturn.NO_PREROLL ):
			return True

		attempts -= 1
		if attempts:
			time.sleep(0.1)

	return False 
Example #25
Source File: player.py    From pomodoro-indicator with GNU General Public License v3.0 5 votes vote down vote up
def get_duration(self):
        if self.player is not None:
            self.player.get_state(Gst.CLOCK_TIME_NONE)
            duration_nanosecs = self.player.query_duration(Gst.Format.TIME)[1]
            duration = float(duration_nanosecs) / Gst.SECOND
            return duration
        return 0 
Example #26
Source File: player.py    From pomodoro-indicator with GNU General Public License v3.0 5 votes vote down vote up
def get_position(self):
        if self.player is not None:
            self.player.get_state(Gst.CLOCK_TIME_NONE)
            nanosecs = self.player.query_position(Gst.Format.TIME)[1]
            position = float(nanosecs) / Gst.SECOND
            return position
        return 0 
Example #27
Source File: audio_graph.py    From Audio-Cutter with GNU General Public License v3.0 5 votes vote down vote up
def nsToPixelAccurate(cls, duration):
        """Returns the pixel equivalent of the specified duration."""
        # Here, a long time ago (206f3a05), a pissed programmer said:
        # DIE YOU CUNTMUNCH CLOCK_TIME_NONE UBER STUPIDITY OF CRACK BINDINGS !!
        if duration == Gst.CLOCK_TIME_NONE:
            return 0
        return ((float(duration) / Gst.SECOND) * cls.zoomratio) 
Example #28
Source File: audio_graph.py    From Audio-Cutter with GNU General Public License v3.0 5 votes vote down vote up
def nsToPixel(cls, duration):
        """Returns the pixel equivalent of the specified duration"""
        # Here, a long time ago (206f3a05), a pissed programmer said:
        # DIE YOU CUNTMUNCH CLOCK_TIME_NONE UBER STUPIDITY OF CRACK BINDINGS !!
        if duration == Gst.CLOCK_TIME_NONE:
            return 0
        return int((float(duration) / Gst.SECOND) * cls.zoomratio) 
Example #29
Source File: audio_graph.py    From Audio-Cutter with GNU General Public License v3.0 5 votes vote down vote up
def pixelToNsAt(cls, pixel, ratio):
        """Returns the duration equivalent of the specified pixel."""
        return int(pixel * Gst.SECOND / ratio) 
Example #30
Source File: audio_graph.py    From Audio-Cutter with GNU General Public License v3.0 5 votes vote down vote up
def pixelToNs(cls, pixel):
        """Returns the duration equivalent of the specified pixel."""
        return int(pixel * Gst.SECOND / cls.zoomratio)