2014年に使うべきビデオプレイヤー: mpv
この投稿は、今一部ギークの中で流行っている(?)mpvというビデオプレイヤーを紹介する記事である。
mpvは一部変態が好んで使うmplayer2というビデオプレイヤーをベースに日々様々な改良が加えられているビデオプレイヤーである。mplayer2との違いはdifferencesにまとまっているが、長くて読む気が失せる。そこで、丁度一年前ぐらいになるが、2012/12/22に開発者の1人であるpigoz氏(@pigoz)にIRCで尋ねたログを引用する。ちなみに、pigoz氏はちょっと休みがあると山登りに行き、まどマギが好きなイタリア人(?)である。超良い奴だ。
22:37 <henry0312> By the way, what differences between mplayer2 and mpv?
22:38 <pigoz> it has 40% the code of mplayer2
22:38 <pigoz> the idea behind it is to modernize the codebase by removing the useless stuff
22:39 <henry0312> hm
22:40 <pigoz> and to use ffmpeg as much as possible
22:40 <pigoz> :)
だそうだ(ぇ まぁ、mplayer2から不要なコードを除くことでコードを新しくしたのと、ffmpegを出来るだけ使用するようにした感じ。
Windows環境では色んな意味でより優れた再生環境を作ることが出来るので、mpvをWindows環境で使う人はあまり居ないような気がする。そういうわけでこの記事ではWindows環境を対象としていない(そもそも、現在Windows環境が無いため私自身も確認できない)。
*nix環境の人はやはりVLCを使用している人が多いだろうか? 個人的にVLCを使う1番の理由はGUIで操作できることだが、GUIが必要なのは比較的複雑なこと(例えばストリーミング配信)をしたい場合であり、普通の動画ファイルをただ開きたいだけならGUIは要らないし、それよりは軽くて高速に動いてくれる方がうれしい。
実際に使ってみるとわかるのだがmpvはかなり軽い。VLCもmpvも設定をすれば出来ることはそんなに違わないはずだが、家の環境ではどんなに頑張ってVLCをチューニングしても、mpvと同程度のパフォーマンスは引き出せなかった。
この投稿はVLCをdisるための記事でもないし、mpvの開発者を増やしたいなどの意図も無い(もちろん、日本人開発者が増えればうれしいが)。VLCはVLCで必要だし、私自身mpvのコードは少し見ただけではわからない。そうではなくて、mpvという素晴らしいビデオプレイヤーがまだあまり日本で使われていないようなので、mpvの普及目的で書いた(記事投稿時点で日本語の記事はなさそう?)。
mpvはかなりオタク向けなソフトウェアであるため、初心者向けの説明はしていないが、比較的大きなソフトウェア(例えばffmpeg)を自分でビルドした経験がある人にとっては容易に試すことができるように、しかもさらにその先の面白い事ができるように配慮したつもりだ。正月暇で興味がある人はぜひ試してみてほしい。
1 インストール
OS XとUbuntu上でビルドする。
1.1 OS X
Homebrewを使ってインストールする。mpv-player/homebrew-mpvの通りに進めればインストール出来る。
まず、Docutilsをインストールする。
$ [sudo] easy_install pip
$ pip install docutils
次にffmpegをインストールする。mpvの機能をフルで使用するためにHEADをインストールすること。
$ brew install --HEAD ffmpeg
そして、上記のリポジトリをTapに登録してmpvをインストールする
$ brew tap mpv-player/mpv
$ brew install --HEAD mpv-player/mpv/libass-ct
$ brew install mpv
これでインストール出来るが、いくつか付けておいた方がいいオプションがある。
$ brew options mpv
--with-bundle
    Create a Mac OSX Application Bundle alongside the CLI version of mpv.
--with-jackosx
    Build with jackosx support.
--with-libaacs
    Build with libaacs support
--with-libav
    Build against libav instead of ffmpeg.
--with-libbluray
    Build with libbluray support
--with-libbs2b
    Build with libbs2b support
--with-libcaca
    Build with libcaca support
--with-libdvdread
    Build with libdvdread support
--with-libquvi
    Build with libquvi support
--with-little-cms2
    Build with little-cms2 support
--with-lua
    Build with lua support
--with-official-libass
    Use official version of libass (instead of experimental CoreText based branch)
--with-x11
    Build with x11 support
--without-jpeg
    Build without jpeg support
--without-mpg123
    Build without mpg123 support
--HEAD
    install HEAD version
詳細をここで説明することの出来ないオプションもあるが、最低でも--HEADと--with-bundleは付けておいた方が幸せになれる。以降、HEADビルドのみを対象とする。
$ brew install --with-bundle --HEAD mpv
インストールが無事完了したら、mpv.appへのシンボリックリンクをアプリケーションフォルダに作っておく。
$ ln -s /usr/local/Cellar/mpv/HEAD/bin/mpv.app /Applications
# See https://github.com/Homebrew/homebrew/wiki/FAQ#my-mac-apps-dont-find-usrlocalbin-utilities
$ launchctl setenv PATH "/usr/local/bin:$PATH"
ちなみに、私はmpv-player/homebrew-mpvへのコミット権を持っているので何かあれば連絡ください。
1.2 Ubuntu
必要なライブラリを揃え、ソースコードmpv-player/mpvから地道にビルドする方法もあるが、ここではmpv-player/mpv-buildを使ったインストール方法を説明する。なお、ビルドは仮想OSとして入れたUbuntu 13.10 日本語 Remix上で行ったが、Parallels Desktop 8を使った仮想OSではopengl-hq(後ほど説明する)が使用できず、x11での再生確認しか出来なかった(これは、ParallesがOpenGL 3.xをサポートしていないため)。
まず、必要なソフトウェアやライブラリをインストールする。
$ sudo apt-get install build-essential git yasm autoconf libtool libfreetype6-dev libfribidi-dev libfontconfig1-dev
# for OpenGL
$ sudo apt-get install libgl1-mesa-glx libgl1-mesa-dev
次に、mpv-buildをcloneし、ffmpegとmpvをビルドする。
$ git clone https://github.com/mpv-player/mpv-build.git
$ cd mpv-build
$ ./rebuild -j2 # 並列ビルド
ビルドが無事完了すると、mpv-build/mpv/build/mpvにバイナリが出来ている。これをパスの通った所に置いておくと良いだろう。また、Ubuntu Tweakなどを使ってビデオファイルの関連付けを変更しておけば便利かもしれない。
mpvのビルドオプションを追加したい場合は、(mpv本体のビルドオプションを調べてから)mpv-build/scripts/mpv-configに追記すればいい。この記事を書いている時点で指定可能なオプションは以下のようになっている。多くのオプションがautodetectとなっているので必要なライブラリをインストールしておけば勝手にオプションが有効になる。
$ waf --help
waf [commands] [options]
Main commands (example: ./waf build -j4)
  build    : executes the build
  clean    : cleans the project
  configure: configures the project
  dist     : makes a tarball for redistributing the sources
  distcheck: checks if the project compiles (tarball from 'dist')
  distclean: removes the build directory
  install  : installs the targets on the system
  list     : lists the targets to execute
  step     : executes tasks in a step-by-step fashion, for debugging
  uninstall: removes the targets installed
  update   : updates the plugins from the *waflib/extras* directory
Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -j JOBS, --jobs=JOBS  amount of parallel jobs (4)
  -k, --keep            keep running happily even if errors are found
  -v, --verbose         verbosity level -v -vv or -vvv [default: 0]
  --nocache             ignore the WAFCACHE (if set)
  --zones=ZONES         debugging zones (task_gen, deps, tasks, etc)
  configure options:
    -o OUT, --out=OUT   build dir for the project
    -t TOP, --top=TOP   src dir for the project
    --prefix=PREFIX     installation prefix [default: '/usr/local/']
    --download          try to download the tools if missing
  build and install options:
    -p, --progress      -p: progress bar; -pp: ide output
    --targets=TARGETS   task generators, e.g. "target1,target2"
    --bindir=BINDIR     directory for installing binary files [${PREFIX}/bin]
    --libdir=LIBDIR     directory for installing library files [${PREFIX}/lib]
    --confdir=CONFDIR   directory for installing configuration files [${PREFIX}/etc/mpv]
    --datadir=DATADIR   directory for installing data files [${PREFIX}/share]
    --mandir=MANDIR     directory for installing man pages  [${DATADIR}/man]
    --docdir=DOCDIR     directory for installing documentation files [${DATADIR}/doc/mpv]
    --enable-static-build
                        enable static build [disable]
    --disable-build-date
                        disable whether to include binary compile time [enable]
    --disable-debug-build
                        disable whether to compile-in debugging information [enable]
    --disable-manpage-build
                        disable manpage generation [autodetect]
    --enable-pdf-build  enable pdf manual generation [disable]
    --enable-vf-dlopen-filters
                        enable compilation of default filters for vf_dlopen [disable]
    --enable-macosx-bundle
                        enable compilation of a Mac OS X Application bundle [disable]
    --disable-asm       disable inline assembly [enable]
  step options:
    --files=FILES       files to process, by regexp, e.g. "*/main.c,*/test/main.o"
  install/uninstall options:
    --destdir=DESTDIR   installation root [default: '']
    -f, --force         force file installation
    --distcheck-args=DISTCHECK_ARGS
                        arguments to pass to distcheck
  C Compiler Options:
    --check-c-compiler=CHECK_C_COMPILER
                        On this platform (darwin) the following C-Compiler will be checked by default: "gcc"
  optional feaures:
    --disable-iconv     disable iconv [autodetect]
    --disable-terminfo  disable terminfo [autodetect]
    --disable-termcap   disable termcap [autodetect]
    --disable-termios   disable termios [autodetect]
    --disable-shm       disable shm [autodetect]
    --disable-libguess  disable libguess support [autodetect]
    --disable-libsmbclient
                        disable Samba support [autodetect]
    --disable-libquvi4  disable libquvi 0.4.x support [autodetect]
    --disable-libquvi9  disable libquvi 0.9.x support [autodetect]
    --disable-libquvi   disable libquvi support [autodetect]
    --disable-libass    disable SSA/ASS support [autodetect]
    --disable-libass-osd
                        disable libass OSD support [autodetect]
    --disable-encoding  disable Encoding [autodetect]
    --enable-joystick   enable joystick [disable]
    --disable-lirc      disable lirc [autodetect]
    --disable-vcd       disable VCD support [autodetect]
    --disable-libbluray
                        disable Bluray support [autodetect]
    --disable-dvdread   disable dvdread support [autodetect]
    --disable-dvdnav    disable dvdnav support [autodetect]
    --disable-cdda      disable cdda support (libcdio) [autodetect]
    --disable-enca      disable ENCA support [autodetect]
    --disable-mpg123    disable mpg123 support [autodetect]
    --disable-ladspa    disable LADSPA plugin support [autodetect]
    --disable-libbs2b   disable libbs2b audio filter support [autodetect]
    --disable-lcms2     disable LCMS2 support [autodetect]
    --disable-libavresample
                        disable libavresample [autodetect]
    --disable-libswresample
                        disable libswresample [autodetect]
    --disable-libavfilter
                        disable libavfilter [autodetect]
    --disable-vf-lavfi  disable using libavfilter through vf_lavfi [autodetect]
    --disable-af-lavfi  disable using libavfilter through af_lavfi [autodetect]
    --disable-libavdevice
                        disable libavdevice [autodetect]
    --disable-libpostproc
                        disable libpostproc [autodetect]
  audio outputs:
    --enable-sdl2       enable SDL2 [disable]
    --enable-sdl        enable SDL (1.x) [disable]
    --disable-oss-audio
                        disable OSS audio output [autodetect]
    --disable-audio-select
                        disable audio select() [autodetect]
    --disable-rsound    disable RSound audio output [autodetect]
    --disable-sndio     disable sndio audio input/output [autodetect]
    --disable-pulse     disable PulseAudio audio output [autodetect]
    --disable-portaudio
                        disable PortAudio audio output [autodetect]
    --disable-jack      disable JACK audio output [autodetect]
    --enable-openal     enable OpenAL audio output [disable]
    --disable-alsa      disable ALSA audio output [autodetect]
    --disable-coreaudio
                        disable CoreAudio audio output [autodetect]
    --disable-dsound    disable DirectSound audio output [autodetect]
    --disable-wasapi    disable WASAPI audio output [autodetect]
  video outputs:
    --disable-cocoa     disable Cocoa [autodetect]
    --disable-wayland   disable Wayland [autodetect]
    --disable-x11       disable X11 [autodetect]
    --disable-xss       disable Xss screensaver extensions [autodetect]
    --disable-xext      disable X extensions [autodetect]
    --disable-xv        disable Xv video output [autodetect]
    --disable-xinerama  disable Xinerama [autodetect]
    --disable-xf86vm    disable Xxf86vm [autodetect]
    --disable-xf86xk    disable XF86keysym [autodetect]
    --disable-gl-cocoa  disable OpenGL Cocoa Backend [autodetect]
    --disable-gl-x11    disable OpenGL X11 Backend [autodetect]
    --disable-gl-wayland
                        disable OpenGL Wayland Backend [autodetect]
    --disable-gl-win32  disable OpenGL Win32 Backend [autodetect]
    --disable-gl        disable OpenGL video outputs [autodetect]
    --disable-corevideo
                        disable CoreVideo [autodetect]
    --disable-vdpau     disable VDPAU acceleration [autodetect]
    --disable-vdpau-gl-x11
                        disable VDPAU with OpenGL/X11 [autodetect]
    --disable-vaapi     disable VAAPI acceleration [autodetect]
    --disable-vaapi-vpp
                        disable VAAPI VPP [autodetect]
    --disable-vaapi-glx
                        disable VAAPI GLX [autodetect]
    --disable-caca      disable CACA [autodetect]
    --disable-dvb       disable DVB [autodetect]
    --disable-dvbin     disable DVB input module [autodetect]
    --disable-jpeg      disable JPEG support [autodetect]
    --disable-direct3d  disable Direct3D support [autodetect]
  hwaccels:
    --disable-vaapi-hwaccel
                        disable libavcodec VAAPI hwaccel [autodetect]
    --disable-vda-hwaccel
                        disable libavcodec VDA hwaccel [autodetect]
    --disable-vda-gl    disable VDA with OpenGL [autodetect]
    --disable-vdpau-decoder
                        disable VDPAU decoder (old) [autodetect]
    --disable-vdpau-hwaccel
                        disable libavcodec VDPAU hwaccel (new) [autodetect]
  radio/tv features:
    --enable-radio      enable Radio interface [disable]
    --disable-radio-capture
                        disable Radio capture (through PCI/line-in) [autodetect]
    --enable-radio-v4l2
                        enable Video4Linux2 radio interface [disable]
    --disable-tv        disable TV interface [autodetect]
    --disable-tv-v4l2   disable Video4Linux2 TV interface [autodetect]
    --disable-libv4l2   disable libv4l2 support [autodetect]
    --disable-pvr       disable Video4Linux2 MPEG PVR interface [autodetect]
    --disable-audio-input
                        disable audio input support [autodetect]
  scripting:
    --disable-lua       disable Lua [autodetect]
    --lua=LUA_VER       select Lua package which should be autodetected. Choices: 51 51deb 52 52deb luajit
2 アップデート
ffmpegもmpvも日々開発が行われているので、適宜アップデートすることで新しい機能を試すことができる。ここでも、OS XとUbuntu上でのアップデート方法を説明する。
2.1 OS X
ffmpegとmpvを更新する
$ brew reinstall --HEAD ffmpeg
$ brew reinstall --with-bundle --HEAD mpv
2.2 Ubuntu
rebuildを実行する。
$ cd mpv-build
$ ./rebuild -j2
3 使い方
3.1 マニュアル
- mpv/DOCS/man/en/mpv.rst at master · mpv-player/mpv
 - mpv/DOCS/man/en/options.rst at master · mpv-player/mpv
 - mpv/DOCS/man/en/af.rst at master · mpv-player/mpv
 - mpv/DOCS/man/en/ao.rst at master · mpv-player/mpv
 - mpv/DOCS/man/en/vf.rst at master · mpv-player/mpv
 - mpv/DOCS/man/en/vo.rst at master · mpv-player/mpv
 
再生だけならこの辺だけで十分なはず。これ以上のことが必要な場合は、manやmpv/DOCS/man/en at master · mpv-player/mpvを確認することになる。
3.2 設定ファイル
$HOME/.mpv/configを作成する。私はpigoz氏の設定(dotfiles/mpv at master · pigoz/dotfiles)を参考にした。
# vim: syntax=config
################################################################################
# General
################################################################################
correct-pts=yes
msgcolor=yes
cache=50000
cache-min=10
volume=100
screenshot-format=png
screenshot-template=/Users/henry/Desktop/SS/mpv-ss-%ty%tm%td-%tH%tM%tS-%wHh%wMm%wSs%wT
################################################################################
# Video Filters
################################################################################
vf=yadif
################################################################################
# Video Output
################################################################################
vo=opengl-hq
osc=no
重要なのは22行目である。ビデオ出力ドライバにopengl-hqが指定できなければ、mpvの(画質面での)魅力はほぼ失われたと言っても過言ではない。詳細はマニュアルを。
12行目はスクリーンショットを保存するときのファイル名である。各環境に合わせて変更しなければならない。
3.3 再生方法
端末から起動する場合はマニュアルに書いてある通り。[options]は3.2でconfigを作成してる場合は不要。
OS X環境で、mpv.appを作成した人はこれを指定して開くこともできる。というより、これをデフォルトのアプリケーションに設定しておくのがベストだろう。
3.4 キーボード操作
Keyboard Controlから特によく使うものをピックアップして紹介する。
例えば、多くの深夜アニメのAパートとBパートの間のCMは約60秒 or 90秒なので、Aパート終了後にキーボードのUPを1回 or UP1回+LEFT3回入力すればCMを高速にスキップすることができる。EDと次回予告の間も同様にスキップできる。
VLCでもキーボードショートカットを同じように設定すれば同様に操作可能だが、mpv並のシーク速度は(うちの環境では)実現できなかった。
LEFT and RIGHT
10秒間隔で前後にシークする。Shift+LEFT or RIGHTは1秒間隔になる
UP and DOWN
1分間隔で前後にシークする。Shift+UP or DOWNは5秒間隔になる
PGUP and PGDWN
10分間隔で前後にシークする
p / SPACE
再生を一時中止する(中止中の時は再開する)
q / ESC
再生をストップし、プログラムを終了する
/ and *
音量を下げる/上げる
9 and 0
音量を下げる/上げる
m
ミュートにする
v
字幕を表示する
s
スクリーンショットを撮る
D
デインターレースのON/OFFを切り替える(上記のconfigを使う場合、デインターレースのON/OFFは自動判定)
ざっとだが、mpvのインストール、アップデート、使い方とまとめた。ここに挙げたmpvの機能はほんの一部なので、興味がある人はマニュアルを見て色々触ってみてほしい。