Jump to content
Moodkiller

MPV Made Easy (Moodkiller Edition)

Recommended Posts

4 minutes ago, Zachimillius said:

How well does MPV handle bit-streaming audio to an AV to decode?

Can you give an example of what you want to do? Personally I have no experience with such, however MPV makes use of FFmpeg, so if that can support the input source, I dont foresee a problem...

Share this post


Link to post
Share on other sites

Rather than doing a software decode of audio that is in a passthrough format my receiver supports (Dolby, DTS, etc), I have my player configured to pass the audio through to the AV to decode. A player will otherwise decode the audio to PCM and output that.

Share this post


Link to post
Share on other sites
17 minutes ago, Toddler Naruto said:

Just to be clear, so I should not bother trying to use the old guide from last year?

 

https://kametsu.com/topic/58428-guide-installing-mpc-hc-with-madvr-lavfilters-xysubfilter-and-icaros/

 

Also what makes this better in layman terms? Sorry for being confused, just trying to understand.

At the moment MPC HC + madvr + LAV filters etc builds are still stable. However, MPC is no longer being supported. Its last update was almost a year ago I think. That is why Moodkiller is providing this an alternative instead.  

 

Really the benefits come down to preference and simplicity of the install at this point. madvr gives you some great control over postprocessing (changing the video to suit your preferences basically) but, most users do not use it as it is relatively advanced. MPV gives you a great range of customisation with scripts to tweak and configure the player the way you want it on the other hand. Though I am not too familiar with it. However, with MPC no longer getting updates, it is only a matter of time before it losses stability. 

Edited by Zachimillius
  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

So, thanks to @Koby for pointing it out, there seems to be an issue where the now playing script in Hexchat falls back to legacy mode 99% of the time on Windows 10 1803. I say 99% of the time because there was one instance where it didnt fall back and it printed the feature rich content. For now, either bear with it or one can change the line:

LEGACY_CMD_FMT = "me is playing: {title} in MPV"

to

LEGACY_CMD_FMT = ""

This will just stop the script from printing anything at all until it works (that 1%).

Fixes soon™

Share this post


Link to post
Share on other sites
18 minutes ago, Moodkiller said:

So, thanks to @Koby for pointing it out, there seems to be an issue where the now playing script in Hexchat falls back to legacy mode 99% of the time on Windows 10 1803. I say 99% of the time because there was one instance where it didnt fall back and it printed the feature rich content. For now, either bear with it or one can change the line:


LEGACY_CMD_FMT = "me is playing: {title} in MPV"

to


LEGACY_CMD_FMT = ""

This will just stop the script from printing anything at all until it works (that 1%).

Fixes soon™

Would be better just to do what I do and setup legacy to be almost identical so it doesn't matter.

  • Like 1

Share this post


Link to post
Share on other sites
7 minutes ago, Koby said:

Would be better just to do what I do and setup legacy to be almost identical so it doesn't matter.

Or one can do that, want to share your code?? ^_^ - iirc, you made it bold and applied colour tags?

Share this post


Link to post
Share on other sites
1 hour ago, Moodkiller said:

Or one can do that, want to share your code?? ^_^ - iirc, you made it bold and applied colour tags?

I made legacy show filename instead of "title". Among some other various modifications.

 

# requires Python 3
from abc import ABCMeta, abstractmethod
import json
import os.path
import socket
import sys
import time

import hexchat


__module_name__ = "mpv now playing"
__module_version__ = "0.4.2"
__module_description__ = "Announces info of the currently loaded 'file' in mpv"

# # Configuration # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Paths to mpv's IPC socket or named pipe.
# Set the same path in your mpv.conf `input-ipc-server` setting
# or adjust these values.
WIN_PIPE_PATH = R"\\.\pipe\mpvsocket"
UNIX_PIPE_PATH = "/tmp/mpv-socket"  # variables are expanded

# Windows only:
# The command that is being executed.
# Supports mpv's property expansion:
# https://mpv.io/manual/stable/#property-expansion
CMD_FMT = R'me is playing 12${filename} ◘ ${file-size} ◘ [${time-pos}${!duration==0: / ${duration}}] in 13${mpv-version}'

# On UNIX, the above is not supported yet
# and this Python format string is used instead.
# `{title}` will be replaced with the title.
LEGACY_CMD_FMT = "me is playing 12{title} in 13mpv"


# # The Script # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #


def _tempfile_path(*args, **kwargs):
    """Generate a sure-to-be-free tempfile path.

    It's hacky but it works.
    """
    import tempfile
    fd, tmpfile = tempfile.mkstemp()
    # close and delete; we only want the path
    os.close(fd)
    os.remove(tmpfile)
    return tmpfile


# If asynchronous IO was to be added,
# the Win32API would need to be used on Windows.
# Details:
# - https://msdn.microsoft.com/en-us/library/windows/desktop/aa365683%28v=vs.85%29.aspx
# Examples:
# - https://msdn.microsoft.com/en-us/library/windows/desktop/aa365690%28v=vs.85%29.aspx
# - https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592%28v=vs.85%29.aspx
# - https://github.com/mpv-player/mpv/blob/master/input/ipc-win.c
class MpvIpcClient(metaclass=ABCMeta):

    """Work with an open MPC instance via its JSON IPC.

    In a blocking way.
    Supports sending IPC commands,
    input commands (input.conf style)
    and arbitrary read/write_line calls.

    Classmethod `for_platform`
    will resolve to one of WinMpvIpcClient or UnixMpvIpcClient,
    depending on the current platform.
    """

    def __init__(self, path):
        self.path = path
        self._connect()

    @classmethod
    def for_platform(cls, platform=sys.platform, path=None):
        if platform == 'win32':
            return WinMpvIpcClient(path or WIN_PIPE_PATH)
        else:
            return UnixMpvIpcClient(path or UNIX_PIPE_PATH)

    @abstractmethod
    def _connect(self):
        pass

    @abstractmethod
    def _write_line(self):
        pass

    @abstractmethod
    def _read_line(self):
        pass

    @abstractmethod
    def close(self):
        pass

    def command(self, command, *params):
        data = json.dumps({"command": [command] + list(params)})
        self._write_line(data)
        while 1:
            # read until a result line is found (containing "error" key)
            result_line = self._read_line()
            result = json.loads(result_line)
            if 'error' in result:
                break
        if result['error'] != "success":
            raise RuntimeError("mpv returned an error", result['error'])

        return result['data']

    def input_command(self, cmd):
        """Send an input command."""
        self._write_line(cmd)

    def __enter__(self):
        return self

    def __exit__(self, *_):
        self.close()

    @abstractmethod
    def expand_properties(self, fmt):
        """Expand a mpv property string using its run command and platform-specific hacks.

        Pending https://github.com/mpv-player/mpv/issues/3166
        for easier implementation.
        """
        pass


class WinMpvIpcClient(MpvIpcClient):

    def _connect(self):
        self._f = open(self.path, "w+t", newline='', encoding='utf-8')

    def _write_line(self, line):
        self._f.write(line.strip())
        self._f.write("\n")
        self._f.flush()

    def _read_line(self):
        return self._f.readline()

    def close(self):
        self._f.close()

    def expand_properties(self, fmt, timeout=3):
        """Expand a mpv property string using its run command and other hacks.

        Notably, spawn a Powershell process that writes a string to some file.
        Because of this, there are restrictions on the property string
        that will most likely *not* be met,
        but are checked for anyway.

        Since this is a polling-based approach (and unsafe too),
        a timeout mechanic is implemented
        and the wait time can be specified.
        """
        if "'" in fmt or "\\n" in fmt:
            raise ValueError("unsupported format string - may not contain `\\n` or `'`")

        tmpfile = _tempfile_path()

        # backslashes in quotes need to be escaped for mpv
        self.input_command(R'''run powershell.exe -Command "'{fmt}' | Out-File '{tmpfile}'"'''
                           .format(fmt=fmt, tmpfile=tmpfile.replace("\\", "\\\\")))

        # some tests reveal an average time requirement of 0.35s
        start_time = time.time()
        end_time = start_time + timeout
        while time.time() < end_time:
            if not os.path.exists(tmpfile):
                continue
            try:
                with open(tmpfile, 'r', encoding='utf-16 le') as f:  # Powershell writes utf-16 le
                    # Because we open the file faster than powershell writes to it,
                    # wait until there is a newline in out tmpfile (which powershell writes).
                    # This means we can't support newlines in the fmt string,
                    # but who needs those anyway?
                    buffer = ''
                    while time.time() < end_time:
                        result = f.read()
                        buffer += result
                        if "\n" in result:
                            # strip BOM and next line
                            buffer = buffer.lstrip("\ufeff").splitlines()[0]
                            return buffer
                        buffer += result
            except OSError:
                continue
            else:
                break
            finally:
                os.remove(tmpfile)


class UnixMpvIpcClient(MpvIpcClient):

    buffer = b""

    def _connect(self):
        self._sock = socket.socket(socket.AF_UNIX)
        self.expanded_path = os.path.expanduser(os.path.expandvars(self.path))
        self._sock.connect(self.expanded_path)

    def _write_line(self, line):
        self._sock.sendall(line.strip().encode('utf-8'))
        self._sock.send(b"\n")

    def _read_line(self):
        while 1:
            if b"\n" in self.buffer:
                line, _, self.buffer = self.buffer.partition(b"\n")
                return line.decode('utf-8')
            self.buffer += self._sock.recv(4096)

    def close(self):
        self._sock.close()

    def expand_properties(self, fmt):
        return NotImplemented


###############################################################################


def mpv_np(caller, callee, helper):
    try:
        with MpvIpcClient.for_platform() as mpv:
            command = mpv.expand_properties(CMD_FMT)
            if command is None:
                command = NotImplemented
            if command is NotImplemented:
                title = mpv.command("get_property", "filename")
                command = LEGACY_CMD_FMT.format(title=title)
            hexchat.command(command)

    except OSError:
        # import traceback; traceback.print_exc()
        print("mpv IPC not running or bad configuration (see /help mpv)")

    return hexchat.EAT_ALL


if __name__ == '__main__':
    help_str = (
        "Usage: /mpv\n"
        "Setup: set `input-ipc-server={path}` in your mpv.conf file "
        "(or adjust the path in the script source)."
        .format(path=WIN_PIPE_PATH if sys.platform == 'win32' else UNIX_PIPE_PATH)
    )
    hexchat.hook_command("mpv", mpv_np, help=help_str)
    print(__module_name__, __module_version__, "loaded")

 

  • Thanks 2

Share this post


Link to post
Share on other sites

I was looking in replacing my current MPC-HC setup with variation of mpv, but I encountered and issue - I can't get desired tracks to be selected by default.

Is there a way to get non-forced subtitle track to be selected by default if both tracks have the same language? For LAV I can do something like this - "jpn:eng|n", but I can't find any documentation on how to do the same on mpv.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

  • Similar Content

    • By Moodkiller
      xdelta3 GUI 2.0
       
       
      Synopsis: I have forever been in search of gui for xdelta for patch making. After trying out 3 or 4 different ones, I stumbled across this one from a 3 year old github repo. Of course with it being this old, there were some features and functionality missing, not to mention it was using an outdated xdelta3 package. From this, xdelta3 GUI 2.0 was born.
       
      Status: COMPLETE (always a work in progress)
      File Host: Mega, github
      Affiliated Groups: Jordi Vemeulen (original creator), Moodkiller (modifier,updater)
      File Size: ~1MB
      File Extension: .exe
      Changelog: Changelog includes: v2.0.8
      Fixed 3.Apply Patch-Windows.bat creation to look in correct directory for xdelta3 executable.   TO ADD ----------
      • Make GUI dragable while patch making is running.
      • Create scripts to run on Apple OS.
      • Change icon in menu bar.
      • xdelta3 source wildcard (so that any new version of xdelta can be placed in the root folder).
      • drag and drop functionality.
      • Add a new option where one could specify what patch extension they would like. 
      • Fix .zip making - currently makes an empty .zip fle.
      • Use one CMD window when making patches for more than 1 file.
      • Add @pause to patch making CMD and .bat application CMD.
       
      Feedback and suggestions are welcome, otherwise I hope you all find a use for this.
       
      Credit goes to all those who helped on IRC with their respective inputs, namely @CaptainJet, @Koby, @Etzimal, @JohnFlower and @SakuraChan
       
       

      Screenshots
       
       

      File Hosts:
      Current version: 2.0.8 xdelta3 GUI 2.0 - Mega | md5sum: ffb799191d16da8d16591bb22a0e115f | VirusTotal Results
      xdelta3 GUI 2.0 - Github  
      Notes:
      • Seen as this was brought up, to solve the high RAM usage, just remove "-B 1073741824" from the arguments section. The risk is that you may end up with a larger than required .vcdiff file especially if just patching fonts or 1 audio track. 
       

       
       
       
    • By Moodkiller
      This will be a semi-on-going guide for providing and using Premium Link Generators (as many come and go, some work and some don't). For the latest, view the last few pages of this thread as there will be alternatives there. 
       
      These are ones that I have personally used with the file hosts used on Kametsu, and haven't had any problems with. If you have one that you wish you add, please let me know. I will test it first (just a precaution) and then post it here.
       
      For those who don't know what a Premium Link Generator does (or should do), it basically allows you to download from file hosts as if you had a premium membership with them. I.E. No captcha's, no wait times, no file size limits, simultaneous downloads etc etc. This is a general definition and each generator is different.
       
      Note: the below is listed newly discovered to oldest. 

      Disclaimer: Please note that I am using AdBlock and AdBlock Plus on Chrome and AVG Free antivirus - I do not click any "Skip Ad" buttons or other links except as to what is provided. I will not take responsibility for any viruses, damage etc. I will however make sure this post is maintained so that the information is current. 
       
       
      User suggestions
      Thought I would add a new section to try and keep up with what works. If you have a PLG that you would like to suggest, feel free to post it using the template below. I will add these in a condensed version with credit to the original poster.
       
      Template:
       
       
       
       
      PLG's:
       
       
       
       
      Working PLG's
       
       
       
       
    • By Pollux
      I saw @JohnFlower mention this player in channel and thought I would try it out.
      It works better than MPC in some tests I've run.
      Anyone with decent experience with it on Windows 10?
      I am trying to get the stupid Now Playing script to work with mIRC and I don't think the player is even loading the script.
      Any help is appreciated.
       
       
×