mpv-player / mpv

πŸŽ₯ Command line video player
https://mpv.io
Other
28.5k stars 2.92k forks source link

How to use hrtf with openal on osx? #3383

Closed jottr closed 8 years ago

jottr commented 8 years ago

mpv version and platform

mpv 0.18.1 (C) 2000-2016 mpv/MPlayer/mplayer2 projects
 built on Sun Jul 10 17:56:56 BST 2016
ffmpeg library versions:
   libavutil       55.28.100
   libavcodec      57.48.101
   libavformat     57.41.100
   libswscale      4.1.100
   libavfilter     6.47.100
   libswresample   2.1.100
ffmpeg version: 3.1.1
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11.6
BuildVersion:   15G31

Openal seems to not be available?

$ mpv -ao=help

Available audio outputs:
  coreaudio      : CoreAudio AudioUnit
  null           : Null audio output
  coreaudio_exclusive: CoreAudio Exclusive Mode
  pcm            : RAW PCM/WAVE file writer audio output

Or should I check the audio filters?

$ mpv -af=help

Available audio filters:
  delay          : Delay audio filter
  channels       : Insert or remove channels
  format         : Force audio format
  volume         : Volume control audio filter
  equalizer      : Equalizer audio filter
  pan            : Panning audio filter
  drc            : Dynamic range compression filter
  lavcac3enc     : runtime encode to ac3 using libavcodec
  lavrresample   : Sample frequency conversion using libavresample
  scaletempo     : Scale audio tempo while maintaining pitch
  lavfi          : libavfilter bridge

Reproduction steps

I use a video file with a 6-channel DTS audio source:

$ mediainfo video.mkv
{...snip...}
Audio
ID                                       : 2
Format                                   : DTS
Format/Info                              : Digital Theater Systems
Mode                                     : 16
Format settings, Endianness              : Big
Codec ID                                 : A_DTS
Duration                                 : 2h 0mn
Bit rate mode                            : Constant
Bit rate                                 : 754 Kbps
Channel(s)                               : 6 channels
Channel positions                        : Front: L C R, Side: L R, LFE
Sampling rate                            : 48.0 KHz
Frame rate                               : 93.750 fps (512 spf)
Bit depth                                : 24 bits
Compression mode                         : Lossy
Stream size                              : 652 MiB (15%)
Default                                  : Yes
Forced                                   : No

How can I utilize the HRTF function with openal (or without), so that I can hear multichannel surround audio source as binaural audio over headphones?

Will I need to compile mpv with openal/hrtf support? If yes, how? If not, how can I enable hrtf?

shinchiro commented 8 years ago
D:\mpv-x86_64>mpv --ao=help
Available audio outputs:
  wasapi         : Windows WASAPI audio output (event mode)
  openal         : OpenAL audio output
  null           : Null audio output
  pcm            : RAW PCM/WAVE file writer audio output

you need to compile mpv with --enable-openal flag

jottr commented 8 years ago

Thank you for trying to help. I've tried to configure the build via $./waf configure --enable-openal, which restulted in:

Checking for OpenAL audio output: no ('openal >= 1.13' not found) I installed openal-soft via homebrew, but am unsure how to link the library. The following caveats come with the homebrew formula:

==> Caveats This formula is keg-only, which means it was not symlinked into /usr/local.

OS X provides OpenAL.framework.

Generally there are no consequences of this for you. If you build your own software and it requires this formula, you'll need to add to your build variables:

LDFLAGS:  -L/usr/local/opt/openal-soft/lib
CPPFLAGS: -I/usr/local/opt/openal-soft/include

How should I proceed?

@pigoz I saw that you were the main contributor to the homebrew formula. Would it be possible to add openal to the formula itself?

pigoz commented 8 years ago

@jottr just add depends_on 'openal-soft' to the formula and --enable-openal to the configure section of the formula if you want to test.

Or to test with mpv from git: LDFLAGS=-L/usr/local/opt/openal-soft/lib CPPFLAGS=-I/usr/local/opt/openal-soft/include ./waf configure --enable-openal

jottr commented 8 years ago

Thank you @pigoz for helping! I added depends_on "openal-soft" => :optional and then installed mpv via $ brew install mpv --enable-openal --build-from-source.

$ brew info mpv
mpv: stable 0.18.1 (bottled), HEAD
Free, open source, and cross-platform media player
https://mpv.io
/usr/local/Cellar/mpv/0.18.1 (321 files, 8.5M) *
  Built from source on 2016-08-06 at 17:30:50
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mpv.rb
==> Dependencies
Build: pkg-config βœ”
Required: libass βœ”, ffmpeg βœ”
Recommended: jpeg βœ”, little-cms2 βœ”, lua βœ”, youtube-dl βœ”
Optional: libaacs ✘, libarchive βœ”, libbluray ✘, libcaca βœ”, libdvdnav ✘, libdvdread ✘, openal-soft βœ”, uchardet ✘, vapoursynth ✘
...

Openal-soft seems to be present as per brew info, but it looks like it is not available to mpv:

$ mpv -ao=help

Available audio outputs:
  coreaudio      : CoreAudio AudioUnit
  null           : Null audio output
  coreaudio_exclusive: CoreAudio Exclusive Mode
  pcm            : RAW PCM/WAVE file writer audio output

I must be missing a crucial step. Also, once installed, how would I actually employ openal/hrtf on an appropriate video/audio source, read, how would I contruct the flags to get binaural audio output - the documentation is a bit lacking here.

ghost commented 8 years ago

I don't know if the way mpv uses openal can even use its hrtf filter. mpv places each audio channel as 3D source, instead of a single multi-channel source. Also, hrtf is probably not worth using anyway.

jottr commented 8 years ago

@wmv Why would it not be worth using? Would you mind elaborating? Will the effects not be noticeable/satisfying? If not, would that be due to mpv's implementation, or due to problems with the hrtf-filter itself? Do video players or encoders even exist that are capable of properly playing/converting multichannel 3d audio into a working binaural source?
I've tried with mplayer and hrtf enabled, but the effect was not as three dimensional as expected. But this could also be due to misconfiguration on my end.

richardpl commented 8 years ago

Old mplayer hrtf filter is joke, use sofalizer with one of clubfritz files.

kevmitch commented 8 years ago

I have tested hrtf in openal to work well from an audio quality / user experience perspective. As to getting it built with homebrew, I don't have the facility to test right now.

However, once you have openal enabled in mpv, just add a line to / create the openal config file

echo "hrtf = true" >> ~/.alsoftrc 

You also need to make sure that you have the hrtf profiles installed, which probably just happens once you get openal properly installed in homebrew. On debian they're in the separate libopenal-data package though. These are a run-time dependency though , so they shouldn't have any influence on whether you can actually compile openal support.

It is kind of crappy that it requires using an entirely different (basically unmaintained) ao though. I haven't yet tried sofalizer, though it sounds promising.

ghost commented 8 years ago

So while I admit that getting back something like this isn't as simple as using the old af_hrtf, the old af_hrtf had some bad problems, so it's not coming back.

@richardpl is there any reason why af_sofalizer has no default profiles?

richardpl commented 8 years ago

One of the reasons is to not pollute FFmpeg git history with binary files.