In order to try mpv.js you need to install mpv library first.
mpv-1.dll
to C:\Windows\system32
brew install mpv
apt-get install libmpv1 libavformat-dev
Simple Electron application yet capable of handling pretty much any available video thanks to mpv. Run:
git clone https://github.com/Kagami/mpv.js.git && cd mpv.js
npm install
# Only on Linux: npm run use-system-ffmpeg
npm run example
npm install mpv.js --save
Package includes prebuilt binaries for all major platforms so no need to setup compilers.
const path = require("path");
const {app} = require("electron");
const {getPluginEntry} = require("mpv.js");
// Absolute path to the plugin directory.
const pluginDir = path.join(path.dirname(require.resolve("mpv.js")), "build", "Release");
// See pitfalls section for details.
if (process.platform !== "linux") {process.chdir(pluginDir);}
// Fix for latest Electron.
app.commandLine.appendSwitch("no-sandbox");
// To support a broader number of systems.
app.commandLine.appendSwitch("ignore-gpu-blacklist");
app.commandLine.appendSwitch("register-pepper-plugins", getPluginEntry(pluginDir));
Don't forget to enable plugins
feature when creating BrowserWindow
:
const win = new BrowserWindow({
// ...
webPreferences: {plugins: true},
// ...
});
const React = require("react");
const {ReactMPV} = require("mpv.js");
class Player extends React.PureComponent {
constructor(props) {
super(props);
this.mpv = null;
this.state = {pause: true, "time-pos": 0};
}
handleMPVReady(mpv) {
this.mpv = mpv;
this.mpv.observe("pause");
this.mpv.observe("time-pos");
this.mpv.command("loadfile", "/path/to/video.mkv");
}
handlePropertyChange(name, value) {
this.setState({[name]: value});
}
togglePause() {
this.mpv.property("pause", !this.state.pause);
}
render() {
return (
<ReactMPV
className="player"
onReady={this.handleMPVReady.bind(this)}
onPropertyChange={this.handlePropertyChange.bind(this)}
onMouseDown={this.togglePause.bind(this)}
/>
);
}
}
Currently only React component is provided.
Basically all you need to ship is mpvjs.node
and mpv library. Make sure they both and also Electron/NW.js distribution have the same bitness!
You may use lachs0r builds. Copy mpv-1.dll
to the directory with mpvjs.node
and you are done.
Homebrew can compile libmpv.1.dylib
and all its dependencies. To find dylibs that need to be packaged and fix install names you may use collect-dylib-deps script.
Two options are normally acceptable:
libmpv1
with package manager or simply depend on it if you build package.libmpv.so
with e.g. mpv-build.This is unfortunate Chromium's pepper_plugin_list.cc restriction. To workaround this relative path might be used.
On Windows and Mac it can be done by changing working directory to the path where mpvjs.node
is stored. You can't change CWD of renderer process on Linux inside main process because of zygote architecture so another fix is just cd
to the plugin directory in wrapper script.
getPluginEntry
helper will give you plugin entry string with that fix applied.
On Linux plugins loaded with register-pepper-plugins
inherit symbols from electron
binary so it leads to unfortunate effect: libmpv will use Electron's libraries which is not supported.
To workaround it you need to either replace libffmpeg.so
with empty wrapper linked to libav*
:
gcc -Wl,--no-as-needed -shared -lavformat -o /path/to/libffmpeg.so
Or use libmpv with statically linked libav*
.
To build mpvjs.node
by yourself you need to setup dev environment.
See installation section.
See download page.
nacl_sdk.zip
to C:\
export NACL_SDK_ROOT=/path/to/pepper_49
to ~/.bash_profile
C:\nacl_sdk\pepper_49\tools\host_vc.mk
and replace 32_host
with 64_host
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64
cd C:\nacl_sdk\pepper_49\src
and make TOOLCHAIN=win PROJECTS="ppapi_cpp ppapi_gles2"
C:\mpv-dev
brew install mpv
apt-get install libmpv-dev
node-gyp rebuild
in project directorynode-gyp rebuild --arch=ia32
to build 32-bit version of plugin on 64-bit WindowsImportant: Electron 1.8.x ARM releases are broken so use 2.x or 1.7.x instead.
Note: instructions below have been tested on Raspberry Pi 3, see more.
sudo raspi-config
<Ok>
and then <Finish>
and raspi-config tool will ask you if you would like to reboot<Yes>
to reboot the system and apply configuration changesSee installation section.
The NaCl SDK itself is only built to run on x86, so you can't use ./naclsdk
. Instead you have to download pepper's archive directly and unpack it to some directory. Then add export NACL_SDK_ROOT=/path/to/pepper_49
to ~/.bash_profile
.
apt-get install libmpv-dev
Run cd /path/to/pepper_49/src
and make TOOLCHAIN=linux PROJECTS="ppapi_cpp ppapi_gles2" CFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0"
.
After the process is done, head back to mpv.js directory and run node-gyp rebuild
.
Feel free to PR your own.
mpv.js is licensed under CC0 itself. However if you use GPL build of libmpv (e.g. lachs0r builds) your application might violate GPL dynamic linking restrictions. LGPL build should be safe, see mpv copyright for details. (This is not a legal advice.)
Example video is part of Tears of Steel movie (CC) Blender Foundation | mango.blender.org.
Logo is by @SteveJobzniak.