MPV: Difference between revisions

From NixOS Wiki
NobbZ (talk | contribs)
No edit summary
Layer-09 (talk | contribs)
Reviewed and included several improvements to the MPV page.
Line 1: Line 1:
There are 2 packages that provide an {{ic|mpv}} executable:
== Description ==
MPV is an open-source media player known for its high performance, versatility, and minimalist design. It supports a wide range of video and audio formats, ensuring extensive compatibility. MPV features advanced video rendering capabilities, including high-quality scaling algorithms, color management, and HDR support, which contribute to superior video playback quality. It utilizes hardware-accelerated video decoding through APIs such as VA-API, VDPAU, and DXVA2, enhancing performance and reducing CPU usage. The player’s design emphasizes minimalism and efficiency, offering a streamlined user interface with extensive configurability via command-line options and scripting interfaces.


* <code>mpv</code>
== Installation ==
* <code>mpv-unwrapped</code>


{{ic|mpv}} is a wrapper for the {{ic|mpv}} binary which adds {{ic|--script<nowiki>=</nowiki>}} arguments according to the scripts the wrapper was built with.
=== Using <code>nix-env</code> ===
To install mpv using <code>nix-env</code>, execute the following command:<syntaxhighlight lang="nix">
nix-env -iA nixos.mpv
</syntaxhighlight>


If you'd like to add scripts to your {{ic|mpv}} wrapper, you'll need to create an overlay in {{ic|~/.config/nixpkgs/config.nix}} or {{ic|/etc/nixos/configuration.nix}} (if you are using NixOS):
=== Using <code>nix-shell</code> ===
To use MPV in a temporary environment with <code>nix-shell</code>, run:<syntaxhighlight lang="nix">
nix-shell -p mpv
</syntaxhighlight>


<syntaxhighlight lang="nix">
=== System-Wide Installation on NixOS ===
nixpkgs.overlays = [
To install MPV system-wide, add it to your system configuration. Edit your <code>/etc/nixos/configuration.nix</code> and include MPV in the <code>environment.systemPackages</code> list:<syntaxhighlight lang="nix">
   (self: super: {
environment.systemPackages = [  
    mpv = super.mpv.override {
   pkgs.mpv  
      scripts = [ self.mpvScripts.<your choice> ];
    };
  })
];
];
</syntaxhighlight>After modifying your configuration, apply the changes by running:<syntaxhighlight lang="nix">
sudo nixos-rebuild switch
</syntaxhighlight>
</syntaxhighlight>


All of the scripts for MPV can be found under the {{ic|mpvScripts}} attribute. You can search for them by running {{ic|nix search nixpkgs mpvScripts}}. The scripts are defined in the following Nixpkgs directory:
=== User-Specific Installation with Home Manager ===
 
If you use Home Manager, you can add MPV to your home configuration. Edit your Home Manager configuration file (usually <code>~/.config/nixpkgs/home.nix</code>) and include MPV in the <code>home.packages</code> list:<syntaxhighlight lang="nix">
[https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/video/mpv/scripts {{ic|pkgs/applications/video/mpv/scripts}}]
home.packages = [
  pkgs.mpv  
];
</syntaxhighlight>After updating your configuration, apply the changes by running:<syntaxhighlight lang="nix">
home-manager switch
</syntaxhighlight>


So for example, for adding the MPRIS MPV script, use the following in your {{ic|~/.config/nixpkgs/config.nix}}:
== Configuration ==
The recommended way to enable and configure MPV on NixOS is through the <code>programs</code> attribute in your NixOS home configuration.<syntaxhighlight lang="nix">
programs.mpv = {
    enable = true;
};
</syntaxhighlight>A more comprehensive configuration of MPV would look like this.<syntaxhighlight lang="nix">
programs.mpv = {
  enable = true;


<syntaxhighlight lang="nix">
  # Custom package configuration for MPV
{
   package =
   nixpkgs.overlays = [
     (pkgs.mpv-unwrapped.wrapper {
     (self: super: {
       mpv = pkgs.mpv-unwrapped.override {
       mpv = super.mpv.override {
         waylandSupport = true;
         scripts = [ self.mpvScripts.mpris ];
        x11Support = false;
        cddaSupport = false;
        vulkanSupport = false;
        drmSupport = false;
        archiveSupport = false;
        bluraySupport = true;
        bs2bSupport = false;
        cacaSupport = false;
        cmsSupport = false;
        dvdnavSupport = false;
        dvbinSupport = false;
        jackaudioSupport = false;
        javascriptSupport = false;
        libpngSupport = false;
        openalSupport = false;
        pulseSupport = false;
        pipewireSupport = true;
        rubberbandSupport = false;
        screenSaverSupport = false;
        sdl2Support = true;
        sixelSupport = false;
        speexSupport = false;
        swiftSupport = false;
        theoraSupport = false;
        vaapiSupport = true;
        vapoursynthSupport = false;
        vdpauSupport = true;
        xineramaSupport = false;
        xvSupport = false;
        zimgSupport = false;
       };
       };
     })
     })
   ];
    .override {
}
      scripts = with pkgs.mpvScripts; [
        uosc
        sponsorblock
      ];
    };
 
   # MPV configuration options
  config = {
    profile = "high-quality";
    ytdl-format = "bestvideo+bestaudio";
    cache-default = 4000000;
  };
};
</syntaxhighlight>
</syntaxhighlight>


<h2>Error, unknown format</h2>
=== Finding MPV Scripts ===
You can find additional scripts for MPV under the <code>mpvScripts</code> attribute. To search for available scripts, use the following command:<syntaxhighlight lang="nix">
nix search nixpkgs mpvScripts
 
</syntaxhighlight>The scripts are defined in the following Nixpkgs directory:<syntaxhighlight lang="nix">
pkgs/applications/video/mpv/scripts
 
</syntaxhighlight><h2>Error, unknown format</h2>


If you get the following sort of error, note that mpv currently uses the small ffmpeg version (ffmpeg_5) instead of the full version (ffmpeg_5-full).  
If you get the following sort of error, note that mpv currently uses the small ffmpeg version (ffmpeg_5) instead of the full version (ffmpeg_5-full).  
Line 48: Line 113:
</syntaxhighlight>
</syntaxhighlight>


To address this problem, you can use the following overlay in your <code>nixpkgs.overlays</code>:
To address this problem, you can use the following package configuration for ffmpeg.


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
   nixpkgs.overlays = with pkgs; [
programs.mpv = {
     (self: super: {
   enable = true;
       mpv-unwrapped = super.mpv-unwrapped.override {
 
         ffmpeg_5 = ffmpeg_5-full;
  package =
     (pkgs.mpv-unwrapped.wrapper {
       mpv = pkgs.mpv-unwrapped.override {
         ffmpeg = pkgs.ffmpeg-full;
       };
       };
     })
     });
  ];
};
</syntaxhighlight>
</syntaxhighlight>
== References ==
# https://github.com/mpv-player/mpv/wiki
# https://en.wikipedia.org/wiki/Mpv_(media_player)
# https://mynixos.com/search?q=mpv


[[Category:Applications]]
[[Category:Applications]]
[[Category:Video]]
[[Category:Audio]]

Revision as of 18:29, 16 June 2024

Description

MPV is an open-source media player known for its high performance, versatility, and minimalist design. It supports a wide range of video and audio formats, ensuring extensive compatibility. MPV features advanced video rendering capabilities, including high-quality scaling algorithms, color management, and HDR support, which contribute to superior video playback quality. It utilizes hardware-accelerated video decoding through APIs such as VA-API, VDPAU, and DXVA2, enhancing performance and reducing CPU usage. The player’s design emphasizes minimalism and efficiency, offering a streamlined user interface with extensive configurability via command-line options and scripting interfaces.

Installation

Using nix-env

To install mpv using nix-env, execute the following command:

nix-env -iA nixos.mpv

Using nix-shell

To use MPV in a temporary environment with nix-shell, run:

nix-shell -p mpv

System-Wide Installation on NixOS

To install MPV system-wide, add it to your system configuration. Edit your /etc/nixos/configuration.nix and include MPV in the environment.systemPackages list:

environment.systemPackages = [ 
  pkgs.mpv 
];

After modifying your configuration, apply the changes by running:

sudo nixos-rebuild switch

User-Specific Installation with Home Manager

If you use Home Manager, you can add MPV to your home configuration. Edit your Home Manager configuration file (usually ~/.config/nixpkgs/home.nix) and include MPV in the home.packages list:

home.packages = [ 
  pkgs.mpv 
];

After updating your configuration, apply the changes by running:

home-manager switch

Configuration

The recommended way to enable and configure MPV on NixOS is through the programs attribute in your NixOS home configuration.

programs.mpv = {
    enable = true;
};

A more comprehensive configuration of MPV would look like this.

programs.mpv = {
  enable = true;

  # Custom package configuration for MPV
  package =
    (pkgs.mpv-unwrapped.wrapper {
      mpv = pkgs.mpv-unwrapped.override {
        waylandSupport = true;
        x11Support = false;
        cddaSupport = false;
        vulkanSupport = false;
        drmSupport = false;
        archiveSupport = false;
        bluraySupport = true;
        bs2bSupport = false;
        cacaSupport = false;
        cmsSupport = false;
        dvdnavSupport = false;
        dvbinSupport = false;
        jackaudioSupport = false;
        javascriptSupport = false;
        libpngSupport = false;
        openalSupport = false;
        pulseSupport = false;
        pipewireSupport = true;
        rubberbandSupport = false;
        screenSaverSupport = false;
        sdl2Support = true;
        sixelSupport = false;
        speexSupport = false;
        swiftSupport = false;
        theoraSupport = false;
        vaapiSupport = true;
        vapoursynthSupport = false;
        vdpauSupport = true;
        xineramaSupport = false;
        xvSupport = false;
        zimgSupport = false;
      };
    })
    .override {
      scripts = with pkgs.mpvScripts; [
        uosc
        sponsorblock
      ];
    };

  # MPV configuration options
  config = {
    profile = "high-quality";
    ytdl-format = "bestvideo+bestaudio";
    cache-default = 4000000;
  };
};

Finding MPV Scripts

You can find additional scripts for MPV under the mpvScripts attribute. To search for available scripts, use the following command:

nix search nixpkgs mpvScripts

The scripts are defined in the following Nixpkgs directory:

pkgs/applications/video/mpv/scripts

Error, unknown format

If you get the following sort of error, note that mpv currently uses the small ffmpeg version (ffmpeg_5) instead of the full version (ffmpeg_5-full).

$ mpv --log-file=foo.log av://v4l2:/dev/video5
[lavf] Unknown lavf format v4l2
Failed to recognize file format.

Exiting... (Errors when loading file)

To address this problem, you can use the following package configuration for ffmpeg.

programs.mpv = {
  enable = true;

  package =
    (pkgs.mpv-unwrapped.wrapper {
      mpv = pkgs.mpv-unwrapped.override {
        ffmpeg = pkgs.ffmpeg-full;
      };
    });
};

References

  1. https://github.com/mpv-player/mpv/wiki
  2. https://en.wikipedia.org/wiki/Mpv_(media_player)
  3. https://mynixos.com/search?q=mpv