예제 #1
0
 def launch_eos(self):
     if self.have_audio and self.have_video:
         if self.audio_done and self.video_done:
             self.bus.post(gst.message_new_eos(self.pipeline))
     else:
         if self.audio_done or self.video_done:
             self.bus.post(gst.message_new_eos(self.pipeline))
예제 #2
0
 def launch_eos(self):
     if self.have_audio and self.have_video:
         if self.audio_done and self.video_done:
             self.bus.post(gst.message_new_eos(self.pipeline))
     else:
         if self.audio_done or self.video_done:
             self.bus.post(gst.message_new_eos(self.pipeline))
예제 #3
0
파일: transcoder.py 프로젝트: thaolt/arista
    def get_status(self):
        """
            Get information about the status of the encoder, such as the
            percent completed and nicely formatted time remaining.
            
            Examples
            
             - 0.14, "00:15" => 14% complete, 15 seconds remaining
             - 0.0, "Uknown" => 0% complete, uknown time remaining
            
            Raises EncoderStatusException on errors.
            
            @rtype: tuple
            @return: A tuple of percent, time_rem
        """
        duration = max(self.info.videolength, self.info.audiolength)

        if not duration or duration < 0:
            return 0.0, _("Unknown")

        try:
            pos, format = self.pipe.query_position(gst.FORMAT_TIME)
        except gst.QueryError:
            raise TranscoderStatusException(_("Can't query position!"))
        except AttributeError:
            raise TranscoderStatusException(_("No pipeline to query!"))

        percent = pos / float(duration)
        if percent <= 0.0:
            return 0.0, _("Unknown")

        if self._percent_cached == percent and time.time(
        ) - self._percent_cached_time > 5:
            self.pipe.post_message(gst.message_new_eos(self.pipe))

        if self._percent_cached != percent:
            self._percent_cached = percent
            self._percent_cached_time = time.time()

        total = 1.0 / percent * (time.time() - self.start_time)
        rem = total - (time.time() - self.start_time)
        min = rem / 60
        sec = rem % 60

        try:
            time_rem = _("%(min)d:%(sec)02d") % {
                "min": min,
                "sec": sec,
            }
        except TypeError:
            raise TranscoderStatusException(_("Problem calculating time " \
                                              "remaining!"))

        return percent, time_rem
예제 #4
0
 def get_status(self):
     """
         Get information about the status of the encoder, such as the
         percent completed and nicely formatted time remaining.
         
         Examples
         
          - 0.14, "00:15" => 14% complete, 15 seconds remaining
          - 0.0, "Uknown" => 0% complete, uknown time remaining
         
         Raises EncoderStatusException on errors.
         
         @rtype: tuple
         @return: A tuple of percent, time_rem
     """
     duration = max(self.info.videolength, self.info.audiolength)
     
     if not duration or duration < 0:
         return 0.0, _("Unknown")
     
     try:
         pos, format = self.pipe.query_position(gst.FORMAT_TIME)
     except gst.QueryError:
         raise TranscoderStatusException(_("Can't query position!"))
     except AttributeError:
         raise TranscoderStatusException(_("No pipeline to query!"))
     
     percent = pos / float(duration)
     if percent <= 0.0:
         return 0.0, _("Unknown")
     
     if self._percent_cached == percent and time.time() - self._percent_cached_time > 5:
         self.pipe.post_message(gst.message_new_eos(self.pipe))
     
     if self._percent_cached != percent:
         self._percent_cached = percent
         self._percent_cached_time = time.time()
     
     total = 1.0 / percent * (time.time() - self.start_time)
     rem = total - (time.time() - self.start_time)
     min = rem / 60
     sec = rem % 60
     
     try:
         time_rem = _("%(min)d:%(sec)02d") % {
             "min": min,
             "sec": sec,
         }
     except TypeError:
         raise TranscoderStatusException(_("Problem calculating time " \
                                           "remaining!"))
     
     return percent, time_rem
예제 #5
0
 def on_play(self, button=None):
     """Start"""
     if self.queue_newpipe:
         self.queue_newpipe = False
         self.pipetext = self.textbuf.get_property("text")
         try:
             self.pipeline
         except AttributeError:
             pass
         else:
             # todo: dispose any other references
             gst.message_new_eos(self.pipeline)
             self.notebook_teardown()
             bus = self.pipeline.get_bus()
             bus.remove_signal_watch()
             for x in self.watch:
                 bus.disconnect(x)
             del self.watch
             del bus
             self.pipeline.set_state(gst.STATE_NULL)
             elements = list(self.pipeline.sorted())
             for x in elements:
                 x.set_state(gst.STATE_NULL)
                 self.pipeline.unlink(x)
             del self.pipeline
             # clear bottom area
             # self.bottom_area.forall(lambda x:x.destroy())
             for x in self.bottom_area:
                 if x != self.bottom_video:
                     x.destroy()
         # wait for GUI, so we can put video on it
         gtk.idle_add(self.new_pipe)
         # put controls into notebook
         gtk.idle_add(self.gst_notebook)
     try:
         self.pipeline.set_state(gst.STATE_PLAYING)
     except AttributeError:
         pass
     return False # Return False or this will repeat
예제 #6
0
    def _on_message(self, bus, message):
        """
            Process pipe bus messages, e.g. start new passes and emit signals
            when passes and the entire encode are complete.
            
            @type bus: object
            @param bus: The session bus
            @type message: object
            @param message: The message that was sent on the bus
        """
        t = message.type
        if t == gst.MESSAGE_EOS:
            self.state = gst.STATE_NULL
            self.emit("pass-complete")
            if self.enc_pass < self.options.pass_count - 1:
                self.enc_pass += 1
                self._setup_pass()
                self.pause()
            else:
                self.emit("complete")
        elif t == gst.MESSAGE_APPLICATION:
            msg_name = message.structure.get_name()
            if msg_name == "Prerolled":
                _log.debug("Prerolled application msg received!")

                # Do a seek
                try:
                    uridecode_elem = self.pipe.get_by_name("uridecode")
                    fake = self.pipe.get_by_name("fake")
                    if self._do_seek(self.pipe) != True:
                        _log.debug("Seek failed!")
                        # it's better to unblock pads here and emit an error
                        for pad in uridecode_elem.pads():
                            pad.set_blocked_async(False, self._cb_unblocked)
                        self.pipe.remove(fake)
                        fake.set_state(gst.STATE_NULL)
                        fake = None
                        self.emit("error", "seek failed", 0)
                        # failure to seek is an error, that should be raised

                    self.pipe.remove(fake)
                    fake.set_state(gst.STATE_NULL)
                    fake = None

                    # adding muxer sub-pipe
                    mux_subpipe = gst.parse_launch(self.mux_str)
                    mux_subpipe.set_state(gst.STATE_PAUSED)
                    self.pipe.add(mux_subpipe)

                    # adding and connecting the audio and video sub-pipes
                    video_pads = 0
                    audio_pads = 0
                    for pad in uridecode_elem.pads():
                        if "video" in pad.get_caps().to_string():
                            vpad_added = self._handle_video_pad_added(uridecode_elem, pad, video_pads)
                            if vpad_added:
                                video_pads += 1
                        elif "audio" in pad.get_caps().to_string():
                            apad_added = self._handle_audio_pad_added(uridecode_elem, pad, audio_pads)
                            if apad_added:
                                audio_pads += 1

                    # remove timeout id - error after this is error in start
                    if self._timeoutid:
                        gobject.source_remove(self._timeoutid)
                        self._timeoutid = None

                    # unblocking all pads again (no matter what type)
                    for pad in uridecode_elem.pads():
                        pad.set_blocked_async(False, self._cb_unblocked)

                    if (audio_pads + video_pads) > 0:
                        self.start()
                        self.emit("pass-setup")
                    else:
                        # Send eos - that completes pass and then next pass can be started
                        self.pipe.post_message(gst.message_new_eos(self.pipe))

                except Exception as e:
                    _log.debug(e.message)
                    for pad in uridecode_elem.pads():
                        pad.set_blocked_async(False, self._cb_unblocked)
                    self.emit("error", e.message, 0)

        elif t == gst.MESSAGE_ASYNC_DONE:
            _log.debug("ASYNC_DONE msg received!")

        self.emit("message", bus, message)