def get_duration_seek_ns(self): try: return self.player.query_duration(gst.Format(gst.FORMAT_TIME), None)[0] except Exception, e: logging.warn("GET query_duration: " + str(e)) return -1
def seek_to_start(self): if not self.already_seeked: self.already_seeked = True self.wavparse.seek(1.0, gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, self.start, gst.SEEK_TYPE_SET, self.start + self.duration)
def __init__(self): self.build_pipeline() self.__av_uri = None self.time_format = gst.Format(gst.FORMAT_TIME) self.player_state = 0 loop = LoopingCall(self.poll_bus) loop.start(0.2, True)
def get_duration(filename): d = gst.parse_launch("filesrc location=" + filename + " ! decodebin2 ! fakesink") d.set_state(gst.STATE_PLAYING) d.get_state() # blocks until state transition has finished duration = d.query_duration(gst.Format(gst.FORMAT_TIME))[0] d.set_state(gst.STATE_NULL) return duration
def set_position(self, posicion): if self.duracion < posicion: return posicion = self.duracion * posicion / 100 self.player.get_state() self.player.seek_simple(gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, posicion) # * gst.MSECOND) self.player.get_state()
def seek_seconds(self, seconds): if not seconds: return logging.info("Start with seconds " + str(seconds)) seek_ns = (float(seconds) + 0.0) * self.NANO_SECONDS logging.info("SEC SEEK SEC " + str(seek_ns)) self.player.seek_simple(gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, seek_ns)
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() return self._data.query_duration( gst.Format(gst.FORMAT_TIME))[0] / 1000000000. finally: self._data.set_state(gst.STATE_NULL) self._data.set_property('volume', volume_before) else: return self._data.query_duration(gst.Format( gst.FORMAT_TIME))[0] / 1000000000. return super(SoundGstreamer, self)._get_length()
def seek(self, position): cur_pos, cur_len = self.time() if position > cur_len: #self.stop() return fmt = gst.Format(gst.FORMAT_TIME) ns = position * 10**9 # convert to nanoseconds self.player.seek_simple(fmt, gst.SEEK_FLAG_FLUSH, ns)
def get_pos(self): if self._data is not None: if self._data.get_state()[1] == gst.STATE_PLAYING: try: return self._data.query_position( gst.Format(gst.FORMAT_TIME))[0] / 1000000000. except: pass return 0
def __init__(self, filename): Thread.__init__(self) # rganalysis self.tags = {} self.start_at = None self.end_at = None filesrc = gst.element_factory_make("filesrc", None) filesrc.set_property("location", filename) audioconverter = gst.element_factory_make("audioconvert") decodebin = gst.element_factory_make("decodebin") decodebin.connect( "new-decoded-pad", partial(self.__on_dynamic_pad, audioconverter=audioconverter)) audioresample = gst.element_factory_make("audioresample") cutter = gst.element_factory_make("cutter") # cutter.set_property("leaky", 0) # cutter.set_property("pre-length", 0) # cutter.set_property("run-length", 0) # cutter.set_property("threshold", 1) cutter.set_property("threshold-dB", -40) rganalysis = gst.element_factory_make("rganalysis") fakesink = gst.element_factory_make("fakesink") self.pipe = gst.Pipeline("pipeline") self.pipe.add(filesrc, decodebin) self.pipe.add(audioconverter, audioresample, cutter, rganalysis, fakesink) gst.element_link_many(filesrc, decodebin) gst.element_link_many(audioconverter, audioresample, cutter, rganalysis, fakesink) bus = self.pipe.get_bus() bus.add_signal_watch() bus.connect("message", self.bus_message) bus.connect("message::tag", self.bus_message_tag) bus.connect("message::state-changed", self.bus_message_state_changed) bus.connect("message::eos", self.bus_message_eos) bus.connect("message::element", self.bus_message_element) self.pipe.set_state(gst.STATE_PLAYING) self.pipe.get_state() format = gst.Format(gst.FORMAT_TIME) duration = self.pipe.query_duration(format)[0] self.tags["duration"] = duration
def Seek(self, time): try: self.time_format = gst.Format(gst.FORMAT_TIME) pos_int = self._player.query_position(self.time_format, None)[0] seek_ns = pos_int + (time * 1000000000) self._player.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, seek_ns) logger.info("gst_player: seeking to position: %i" % pos_int) except Exception, e: logger.error("gst_player EXCEPTION: " + str(e))
def seek(self, percent, offset=0): if not self.bean: return None seek_ns = self.duration_sec * (percent + offset) / 100 * self.NANO_SECONDS if self.bean.start_sec > 0: seek_ns = seek_ns + float(self.bean.start_sec) * self.NANO_SECONDS self.player.seek_simple(gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, seek_ns)
def set_position(self, position): """ Set position in milliseconds. :param position: the position in milliseconds :type position: int :rtype: :class:`True` if successful, else :class:`False` """ gst_position = utils.millisecond_to_clocktime(position) return self._playbin.seek_simple( gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, gst_position)
def _seek(self, pos): if (self.__player): self.__pos_time = (0, 0, 0) state = self.__player.get_state()[1] if (state == gst.STATE_PLAYING): self.__player.seek_simple(gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, pos * 1000000000) else: self.__player.set_state(gst.STATE_PLAYING) self.__to_seek = pos
def __init__(self): base.BasePlayer.__init__(self) self.__log = logging.getLogger('panucci.backends.GStreamerPlayer') # have we preformed the initial seek? self.__initial_seek_completed = False self._player = None self._filesrc = None self._filesrc_property = None self._time_format = gst.Format(gst.FORMAT_TIME) self._current_filetype = None
def __init__(self, dbName, cmdSh): self.dbName = dbName self.cmdSh = cmdSh self.currentList = None self.currentlyPlaying = None self.player = gst.element_factory_make("playbin", "player") bus = self.player.get_bus() bus.add_signal_watch() bus.connect("message", self.on_message) self.time_format = gst.Format(gst.FORMAT_TIME) self.growl = Growl.GrowlNotifier(applicationName=self.cmdSh.appName, notifications=['Song change'], defaultNotifications=['Song change']) self.growl.register()
def seek(self, position): """Seeks to position (in seconds).""" cur_pos, cur_len = self.time() if position > cur_len: self.stop() return fmt = gst.Format(gst.FORMAT_TIME) ns = position * 10**9 # convert to nanoseconds self.player.seek_simple(fmt, gst.SEEK_FLAG_FLUSH, ns) # save new cached time self.cached_time = (position, cur_len)
def set_position(self, position): """ Set position in milliseconds. :param position: the position in milliseconds :type volume: int :rtype: :class:`True` if successful, else :class:`False` """ self._playbin.get_state() # block until state changes are done handeled = self._playbin.seek_simple(gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, position * gst.MSECOND) self._playbin.get_state() # block until seek is done return handeled
def time(self): if self.__file is not None: fmt = gst.Format(gst.FORMAT_TIME) try: pos = self.player.query_position(fmt, None)[0] / (10**9) length = self.player.query_duration(fmt, None)[0] / (10**9) self.cached_time = (pos, length) return (pos, length) except gst.QueryError: if self.playing and self.cached_time: return self.cached_time else: return (0, 0)
def set_position(self, position): """ Set position in milliseconds. :param position: the position in milliseconds :type position: int :rtype: :class:`True` if successful, else :class:`False` """ # TODO: double check seek flags in use. gst_position = utils.millisecond_to_clocktime(position) result = self._playbin.seek_simple(gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, gst_position) gst_logger.debug('Sent flushing seek: position=%s', gst_position) return result
def calcul_length(self, video): try: d = gst.parse_launch("filesrc name=source ! decodebin2 ! fakesink") source = d.get_by_name("source") source.set_property("location", video.path) d.set_state(gst.STATE_PLAYING) d.get_state() format = gst.Format(gst.FORMAT_TIME) duration = d.query_duration(format)[0] d.set_state(gst.STATE_NULL) length = datetime.timedelta(seconds=(duration / gst.SECOND)) return unicode(length) except Exception, e: return unicode('-1')
def capture_frame(self, capture_time, destination=None): self.player.seek_simple(gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, capture_time) self.player.set_state(gst.STATE_PLAYING) # Wait for frame to be captured self._capture = {"done": False} while not self._capture["done"]: time.sleep(0.1) if destination is not None: shutil.move(self._capture["file_name"], destination) else: os.remove(self._capture["file_name"]) return self._capture["capture_time"]
def __init__(self, path=None, file=None, time=0.0): Player.__init__(self, path, file, time) self.playbin = gst.element_factory_make("playbin", "player") self.clock = None self.pipeline = gst.Pipeline("mypipeline") self.audiotestsrc = gst.element_factory_make("audiotestsrc", "audio") self.pipeline.add(self.audiotestsrc) sink = gst.element_factory_make("autoaudiosink", "sink") self.pipeline.add(sink) self.audiotestsrc.link(sink) self.time_format = gst.Format(gst.FORMAT_TIME) bus = self.playbin.get_bus() bus.add_signal_watch() bus.connect("message", self.on_message) self.ended = False
def elapsed(self): if self.status == Status.idle: return None else: (change, current, pending) = self._player.get_state() if self.debug: print >> stderr, "state", change, current, pending if current != gst.STATE_NULL: elapsed, format = self._player.query_position( gst.Format(gst.FORMAT_TIME), None) return elapsed / gst.SECOND else: if self.debug: print >> stderr, "bad state", current return None
def _load(self, uri): if (uri.startswith("/")): uri = "file://" + uri uri = uri.replace("\"", "\\\"") self.__player.set_state(gst.STATE_NULL) self.__start_gst() self.__player.set_property("uri", uri) self.__player.set_state(gst.STATE_PLAYING) self.__player.seek_simple(gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, 0) self._report_aspect_ratio(16 / 9.0) if (not platforms.MAEMO5): self._set_volume(self.__volume) self._report_volume(self.__volume)
def load_file(self, file_name): self.file_name = file_name self.player.get_by_name("file-source").set_property( "location", file_name) # Initialize the player self.player.set_state(gst.STATE_PAUSED) # Since all gstreamer calls are asynchronous, video information will # not be immediately available so we retry to determine it every 0.1 # seconds until we succeed. self.info = {} while True: try: self.info["duration"] = self.player.query_duration( gst.Format(gst.FORMAT_TIME), None)[0] time.sleep(0.1) break except gst.QueryError: pass # Determine other stream information. Some of the information will get # added through gst.MESSAGE_TAG messages sent by gstreamer. video_info_conv = { "width": ("width", int), "height": ("height", int), "framerate": ("video_framerate", float), "interlaced": ("video_interlaced", bool), } audio_info_conv = { "channels": ("audio_channels", int), "rate": ("audio_rate", float), } for i in self.player.get_by_name("decoder").src_pads(): caps = i.get_caps()[0] for id in range(caps.n_fields()): name = caps.nth_field_name(id) if caps.get_name().startswith("video"): if name in video_info_conv: self.info[video_info_conv[name][0]] = \ video_info_conv[name][1](caps[name]) elif caps.get_name().startswith("audio"): if name in audio_info_conv: self.info[audio_info_conv[name][0]] = \ audio_info_conv[name][1](caps[name]) return self.info
def time(self): """Returns a tuple containing (position, length) where both values are integers in seconds. If no stream is available, returns (0, 0). """ fmt = gst.Format(gst.FORMAT_TIME) try: pos = self.player.query_position(fmt, None)[0] / (10**9) length = self.player.query_duration(fmt, None)[0] / (10**9) self.cached_time = (pos, length) return (pos, length) except gst.QueryError: # Stream not ready. For small gaps of time, for instance # after seeking, the time values are unavailable. For this # reason, we cache recent. if self.playing and self.cached_time: return self.cached_time else: return (0, 0)
def init_core(self): # Song object display text icon album art self.songs_model = gtk.ListStore(gobject.TYPE_PYOBJECT, str, str, gtk.gdk.Pixbuf) # Station object station name self.stations_model = gtk.ListStore(gobject.TYPE_PYOBJECT, str) self.player = gst.element_factory_make("playbin2", "player") self.player.props.flags |= (1 << 7) # enable progressive download (GST_PLAY_FLAG_DOWNLOAD) bus = self.player.get_bus() bus.add_signal_watch() bus.connect("message::eos", self.on_gst_eos) bus.connect("message::buffering", self.on_gst_buffering) bus.connect("message::error", self.on_gst_error) self.player.connect("notify::volume", self.on_gst_volume) self.player.connect("notify::source", self.on_gst_source) self.time_format = gst.Format(gst.FORMAT_TIME) self.stations_dlg = None self.playing = False self.current_song_index = None self.current_station = None self.current_station_id = self.preferences.get('last_station_id') self.buffer_percent = 100 self.auto_retrying_auth = False self.have_stations = False self.playcount = 0 self.gstreamer_errorcount_1 = 0 self.gstreamer_errorcount_2 = 0 self.gstreamer_error = '' self.waiting_for_playlist = False self.start_new_playlist = False self.worker = GObjectWorker() self.art_worker = GObjectWorker() aa = gtk.gdk.pixbuf_new_from_file(os.path.join(getdatapath(), 'media', 'album_default.png')) self.default_album_art = aa.scale_simple(ALBUM_ART_SIZE, ALBUM_ART_SIZE, gtk.gdk.INTERP_BILINEAR)
def __init__(self, infile, outfile): self.player = gst.parse_launch( 'filesrc name=video_in' + ' ! decodebin name=decoder' + ' matroskamux name=mux' + ' ! filesink name=video_out' + ' queue name=q_audio_in' + ' ! audioconvert' + ' ! vorbisenc' + ' ! queue name=q_audio_out' + ' ! mux.' + ' queue name=q_orig_video_in' + ' ! ffmpegcolorspace' + ' ! pngenc compression-level=1 snapshot=false' + ' ! queue name=q_orig_video_out' + ' ! appsink name=png_sink' + ' appsrc name=png_src' + # TODO: capsset image/svg+xml ! rsvgdec; for now, output is png; URGENT: set framerate, res, etc. ' ! queue name=q_new_video_in' + ' ! pngdec' + ' ! ffmpegcolorspace' + ' ! theoraenc' + ' ! queue name=q_new_video_out' + ' ! mux.') self.player.set_state(gst.STATE_NULL) self.player.get_by_name('video_in').set_property('location', infile) self.player.get_by_name('video_out').set_property('location', outfile) self.decoder = self.player.get_by_name('decoder') self.decoder.connect('new-decoded-pad', self.on_new_decoded_pad) self.png_sink = self.player.get_by_name('png_sink') self.png_sink.set_property('drop', False) self.png_sink.set_property('max_buffers', 1) self.png_src = self.player.get_by_name('png_src') player_bus = self.player.get_bus() player_bus.add_signal_watch() player_bus.connect('message', self.on_message) self.app_caps = False self.ready_lock = threading.Lock() self.ready_lock.acquire() self.time_format = gst.Format(gst.FORMAT_TIME) self.infile = infile
def OnInit(self): global boldFont12 global boldFont18 global regularFont global titleFont #setup fonts boldFont12 = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD) boldFont18 = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD) regularFont = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL) titleFont = wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.BOLD) self.window = MainWindowFrame(None) self.window.SetTitle("Matteorr JukeBox") self.window.Bind(wx.EVT_CLOSE, self.destroy) self.window.setParent(self) self.player = gst.element_factory_make("playbin", "player") fakesink = gst.element_factory_make("fakesink", "fakesink") self.player.set_property("video-sink", fakesink) bus = self.player.get_bus() bus.add_signal_watch() #bus.enable_sync_message_emission() bus.connect('message', self.on_message) #bus.connect('sync-message::element', self.on_sync_message) self.started = False self._timerAttempts = 0 self._maxTimerAttempts = 10 self.time_format = gst.Format(gst.FORMAT_TIME) #self.TIMER_ID = 100 self.timer = wx.Timer(self) #self.timer.Bind(wx.EVT_TIMER, self.on_timer) self.Bind(wx.EVT_TIMER, self.on_timer, self.timer) return True