Exemple #1
0
def mpv_init():
    global m

    setlocale(LC_NUMERIC, "C")

    m = mpv.Context()
    m.initialize()
Exemple #2
0
def main(args):
    if len(args) != 1:
        print('pass a single media file as argument')
        return 1

    try:
        m = mpv.Context()
    except mpv.MPVError:
        print('failed creating context')
        return 1

    m.set_option('input-default-bindings')
    m.set_option('osc')
    m.set_option('input-vo-keyboard')
    m.initialize()

    m.command('loadfile', args[0])

    while True:
        event = m.wait_event(.01)
        if event.id == mpv.Events.none:
            continue
        print(event.name)
        if event.id in [mpv.Events.end_file, mpv.Events.shutdown]:
            break
Exemple #3
0
 def __init__(self):
     self.playlist = Playlist()
     self._mpv = mpv.Context(ytdl=True)
     self._mpv.set_option('video', 'no')
     self._mpv.set_option('pause', True)
     self._mpv.initialize()
     self._mpv.set_wakeup_callback(self._event_cb)
Exemple #4
0
    def __init__(self, display):
        self.last_audio_reconfig = 0
        self.audio_reconfig_pending = False
        self.volume = 0.5
        self.song = None
        self.display = display
        self.opts = opts = util.get_opts()
        self.mpv = mpv.Context()
        self.gl = None
        self.mpv.initialize()
        if opts.mpv_msg_level:
            self.mpv.set_property("msg-level", opts.mpv_msg_level)
        self.mpv.set_property("audio-file-auto", "no")
        self.mpv.set_property("terminal", True)
        self.mpv.set_property("quiet", True)
        if opts.mpv_ao:
            self.mpv.set_property("ao", opts.mpv_ao)
        elif opts.mpv_audio_device:
            self.mpv.set_property("audio-device", opts.mpv_audio_device)
        self.mpv.set_property("fs", True)
        if opts.mpv_ao == "jack":
            self.mpv.set_property("jack-autostart", "yes")
        self.mpv.set_property(
            "af",
            '@lavfi:lavfi="pan=stereo|c0=c0|c1=c1",@rb:rubberband=pitch=speed')
        if opts.mpv_options:
            for opt in shlex.split(opts.mpv_options):
                if "=" not in opt:
                    key, val = opt, True
                else:
                    key, val = opt.split("=", 1)
                self.mpv.set_property(key, val)
        self.poll_props = {"audio-pts": None}
        for i in self.poll_props:
            self.mpv.get_property_async(i)

        if display:
            if opts.mpv_hwdec:
                self.mpv.set_property("hwdec", opts.mpv_hwdec)
            vo = opts.mpv_vo
            if vo in ("opengl-cb", "libmpv"):
                vo = "libmpv"
                self.mpv.set_property("video-sync", "display-vdrop")
                self.mpv.set_property("display-fps", display.fps or opts.fps)

                def gpa(name):
                    return display.get_proc_address(name)

                self.gl = mpv.OpenGLRenderContext(self.mpv, gpa,
                                                  **display.get_mpv_params())
            else:
                self.gl = None
            self.mpv.set_property("vo", vo)
            self.solid_renderer = graphics.get_solid_renderer()
        else:
            self.gl = None
            self.mpv.set_property("vo", "null")
            self.mpv.set_property("vid", "no")
Exemple #5
0
    def __init__(self, *args, fp=None, **kwargs):
        super().__init__(*args, **kwargs)

        self.paintTimes = deque(maxlen=32)
        self.frameTimes = deque(maxlen=32)
        self.swapTimes = deque(maxlen=32)
        self.eventTimes = deque(maxlen=32)
        self.setMouseTracking(True)
        self._updated = False
        self.event_handler_cache = weakref.WeakValueDictionary()
        self.prop_bindings = dict()
        import locale
        locale.setlocale(locale.LC_NUMERIC, 'C')
        options = self.base_options.copy()
        new_options, media = self.get_options(*args, **kwargs)
        options.update(new_options)
        options[
            'msg-level'] = 'all=status,vd=debug,hwdec=debug,vo=debug,video=v,opengl=debug'
        options['af'] = 'rubberband=channels=apart:pitch=quality'
        self.new_frame = False

        mpv = self.mpv
        self.m = mpv.Context(**options)
        m = self.m
        self.just_die.connect(m.shutdown, Q.Qt.DirectConnection)
        self.destroyed.connect(self.just_die, Q.Qt.DirectConnection)

        self.m.set_log_level('terminal-default')
        self.m.set_wakeup_callback_thread(self.onEvent)
        #        self.m.set_wakeup_callback(self.onEvent)
        self.m.request_event(self.mpv.EventType.property_change, True)
        self.m.request_event(self.mpv.EventType.video_reconfig, True)
        self.m.request_event(self.mpv.EventType.file_loaded, True)
        self.m.request_event(self.mpv.EventType.log_message, True)

        self.img_width = 64
        self.img_height = 64
        self.img_update = None

        self.tex_id = 0
        self.fbo = None
        self._width = self.img_width
        self._height = self.img_height
        if isinstance(fp, pathlib.Path):
            fp = fp.resolve().absolute().as_posix()
        elif isinstance(fp, Q.QFileInfo):
            fp = fp.canonicalFilePath()
        elif isinstance(fp, Q.QUrl):
            fp = fp.toString()
        Q.QTimer.singleShot(0, self.update)
        if fp:
            Q.QTimer.singleShot(0, (
                lambda: self.m.command('loadfile', fp, 'append', _async=True)))
Exemple #6
0
 def __init__(self, mus_dir=None, muted=False, init_vol=100):
     self.mus_dir = mus_dir
     self.muted = muted
     self.volume = init_vol
     # self.IOlock = threading.Lock()
     # self.player = None
     self.player = mpv.Context()
     self.player.initialize()
     # # # # # # # if self.muted:
     # # # # # # # 	self.player = subprocess.Popen(['mplayer','-slave','-quiet','-idle','-nosound'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.mus_dir)
     # # # # # # # else:
     # # # # # # # 	self.player = subprocess.Popen(['mplayer','-slave','-quiet','-idle'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.mus_dir)
     # self.getPaused()
     if self.muted:
         self.player.set_property('mute', True)
     self.ensureVolumeSet()
Exemple #7
0
    def __init__(self, **properties):
        super().__init__(**properties)

        self.gl_context: mpv.OpenGLRenderContext = None

        try:
            self.mpv = mpv.Context()
            self.mpv.initialize()
        except mpv.MPVError:
            raise RuntimeError('failed creating context')

        # self.mpv.set_property("gpu-context", "wayland")
        self.mpv.set_property("terminal", True)

        self.connect("realize", self.on_realize)
        self.connect("render", self.on_render)
        self.connect("unrealize", self.on_unrealize)
Exemple #8
0
    def __init__(self, display):
        self.volume = 0.5
        self.song = None
        self.display = display
        opts = util.get_opts()
        self.mpv = mpv.Context()
        self.mpv.initialize()
        self.mpv.set_property("audio-file-auto", "no")
        self.mpv.set_property("terminal", True)
        self.mpv.set_property("quiet", True)
        self.mpv.set_property("ao", opts.mpv_ao)
        self.mpv.set_property("fs", True)
        if opts.mpv_ao == "jack":
            self.mpv.set_property("jack-autostart", "yes")
        self.mpv.set_property("af", "@pan:pan=2:[1,0,0,1],@rb:rubberband")
        for optval in opts.mpv_options.split():
            opt, val = optval.split("=", 1)
            self.mpv.set_property(opt, val)
        self.poll_props = {"audio-pts": None}
        for i in self.poll_props:
            self.mpv.get_property_async(i)

        if display:
            if opts.mpv_vo == "opengl-cb":
                self.mpv.set_property("video-sync", "display-vdrop")
                self.mpv.set_property("display-fps", opts.fps)

                def gpa(name):
                    return display.get_proc_address(name)

                self.gl = self.mpv.opengl_cb_api()
                self.gl.init_gl(None, gpa)
            else:
                self.gl = None
            self.mpv.set_property("vo", opts.mpv_vo)
            self.solid_renderer = graphics.get_solid_renderer()
        else:
            self.gl = None
            self.mpv.set_property("vo", "null")
            self.mpv.set_property("vid", "no")
Exemple #9
0
    def __init__(self, playlist, display=None):
        self.playlist = []
        self.cur = None
        self.pause = True
        self.speed = 1.0

        for line in open(playlist):
            line = line.strip().split("#")[0]
            if not line:
                continue
            off, preroll, filename = line.strip().split(None, 2)
            off = float(off)
            preroll = float(preroll)
            self.playlist.append((off, preroll, filename))

        self.display = display
        self.mpv = mpv.Context()
        self.mpv.initialize()
        self.mpv.set_property("audio-file-auto", "no")
        #self.mpv.set_property("terminal", True)
        #self.mpv.set_property("quiet", True)
        self.mpv.set_property("audio", "no")
        self.mpv.set_property("keep-open", "yes")
        if IS_RPI:
            self.mpv.set_property("fs", True)
        self.mpv.set_property("input-default-bindings", True)
        self.mpv.set_property("input-vo-keyboard", True)

        if display:

            def gpa(name):
                return display.get_proc_address(name)

            self.gl = self.mpv.opengl_cb_api()
            self.gl.init_gl(None, gpa)
            self.mpv.set_property("vo", "opengl-cb")
        else:
            self.gl = None
            self.mpv.set_property("vo", "rpi" if IS_RPI else "opengl")
Exemple #10
0
    def __init__(self,
                 api: Api,
                 parent: T.Optional[QtWidgets.QWidget] = None) -> None:
        super().__init__(parent)
        self._api = api

        locale.setlocale(locale.LC_NUMERIC, "C")

        self._destroyed = False
        self._need_subs_refresh = False
        self._mpv = mpv.Context()

        self._mpv.set_log_level("error")
        for key, value in {
                "config": False,
                "quiet": False,
                "msg-level": "all=error",
                "osc": False,
                "osd-bar": False,
                "input-cursor": False,
                "input-vo-keyboard": False,
                "input-default-bindings": False,
                "ytdl": False,
                "sub-auto": False,
                "audio-file-auto": False,
                "vo": "null" if api.args.no_video else "libmpv",
                "pause": True,
                "idle": True,
                "blend-subtitles": "video",
                "video-sync": "display-vdrop",
                "keepaspect": True,
                "stop-playback-on-init-failure": False,
                "keep-open": True,
                "track-auto-selection": False,
        }.items():
            self._mpv.set_option(key, value)

        self._mpv.observe_property("time-pos")
        self._mpv.observe_property("track-list")
        self._mpv.observe_property("pause")
        self._mpv.set_wakeup_callback(self._mpv_event_handler)
        self._mpv.initialize()

        self._opengl = None

        self._timer = QtCore.QTimer(parent=None)
        self._timer.setInterval(api.cfg.opt["video"]["subs_sync_interval"])
        self._timer.timeout.connect(self._refresh_subs_if_needed)

        api.subs.meta_changed.connect(self._on_subs_change)
        api.subs.events.item_modified.connect(self._on_subs_change)
        api.subs.events.items_inserted.connect(self._on_subs_change)
        api.subs.events.items_removed.connect(self._on_subs_change)
        api.subs.events.items_moved.connect(self._on_subs_change)
        api.subs.styles.item_modified.connect(self._on_subs_change)
        api.subs.styles.items_inserted.connect(self._on_subs_change)
        api.subs.styles.items_removed.connect(self._on_subs_change)
        api.subs.styles.items_moved.connect(self._on_subs_change)

        api.video.stream_created.connect(self._on_video_state_change)
        api.video.stream_unloaded.connect(self._on_video_state_change)
        api.video.current_stream_switched.connect(self._on_video_state_change)
        api.audio.stream_created.connect(self._on_audio_state_change)
        api.audio.stream_unloaded.connect(self._on_audio_state_change)
        api.audio.current_stream_switched.connect(self._on_audio_state_change)
        api.playback.request_seek.connect(self._on_request_seek,
                                          QtCore.Qt.DirectConnection)
        api.playback.request_playback.connect(self._on_request_playback)
        api.playback.playback_speed_changed.connect(
            self._on_playback_speed_change)
        api.playback.volume_changed.connect(self._on_volume_change)
        api.playback.mute_changed.connect(self._on_mute_change)
        api.playback.pause_changed.connect(self._on_pause_change)
        api.video.view.zoom_changed.connect(self._on_video_zoom_change)
        api.video.view.pan_changed.connect(self._on_video_pan_change)
        self.frameSwapped.connect(self.swapped, QtCore.Qt.DirectConnection)
        api.gui.terminated.connect(self.shutdown)
        self._schedule_update.connect(self.update)

        self._timer.start()