mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
27.66k stars 2.86k forks source link

OSX coreaudio / coreaudio-exclusive option: change-physical-format #1932

Closed Nu7ron closed 9 years ago

Nu7ron commented 9 years ago

Hi everyone, I'm new here. Hope it's okay if I post an issue right away!?

I'm incredibly happy with the new core audio option for automatically changing the sample rate and bit-depth of the audio-device. This works perfectly fine with my M-DAC and compressed and uncompressed music formats. Although, when playing compressed multi channel formats (DTS and AC3) the option does not properly change the audio-device format. My guess is, that this option has been implemented for the core audio output driver alone, so when mpv is switching to the coreaudio-exclusive output driver, the option is not supported.

This brings me to the question, if it would be possible to make this option available to both osx audio output drivers? And while speaking of output drivers, why can't the exclusive mode be used for uncompressed audio?

Many thx

ghost commented 9 years ago

Hope it's okay if I post an issue right away!?

Always.

Although, when playing compressed multi channel formats (DTS and AC3) the option does not properly change the audio-device format.

It does. It changes it to a special pseudo-format, which might not be what you expect (showing 2 channels etc.), but actually passes through the compressed audio without changing it.

coreaudio-exclusive does not have such an option, because it always changes the audio format, otherwise it would not work at all. (It currently also only supports compressed passthrough. CoreAudio supports float input only, sop LPCM support doesn't seem worth the trouble.)

ghost commented 9 years ago

By the way, it appears OSX does not support DTS-MA passthrough. In this case, you actually get better quality if you don't use passthrough, but instead use a ffmpeg build with libdcadec enabled.

Nu7ron commented 9 years ago

Thanks for the fast response, I might have mixed up things. I was under the impression that coreaudio-exclusive was what is also known as coreaudio integer mode. I was aware that osx can't passthrough DTS HD and TrueHD, so using libavcodec is actually what I'm up to.

I did get the latest build from ChrisK and configured it to use the brand new DTS MA decoder. At this point I got confused, as the audio-device is always set to a 88.2 khz sample rate although the dts ma test file has a sample rate of 96 khz. To use libavcodec and the change-physical-format option I use these two commands:

ad=lavc:libdcadec ao=coreaudio:change-physical-format=yes

ghost commented 9 years ago

I was under the impression that coreaudio-exclusive was what is also known as coreaudio integer mode.

Modern OSX has no integer mode. Although there is almost no loss due to the float conversion (or maybe even actually no loss).

ad=lavc:libdcadec

You don't need this. The decoder is picked up by default.

as the audio-device is always set to a 88.2 khz sample rate although the dts ma test file has a sample rate of 96 khz.

Maybe the audio device does not support 96 khz? You can also run mpv with -v to check what output and what conversions it's doing.

Nu7ron commented 9 years ago

Modern OSX has no integer mode.

Afaik since OSX 10.9 this feature has been restored.

The decoder is picked up by default.

Very nice! :)

Maybe the audio device does not support 96 khz?

I did test that with a 5.1 multi channel 96/24 flac file and the format of the audio-device is set correctly.

Does the latest build by ChrisK include libdcadec?

ghost commented 9 years ago

Afaik since OSX 10.9 this feature has been restored.

Not to my knowledge, and all of my attempts to get it working on 10.10 failed. I could have done something wrong, but then I'd like to know what.

Does the latest build by ChrisK include libdcadec?

I don't know - check the log. If it mentions something about libdcadec, it is.

Nu7ron commented 9 years ago

Many thanks for your help!

Not to my knowledge, and all of my attempts to get it working on 10.10 failed. I could have done something wrong, but then I'd like to know what.

I did get the info about the interger mode from here: http://www.amr-audio.co.uk/large_image/MAC%20OSX%20audio%20players%20&%20Integer%20Mode.pdf

But I'm a little suspicious after taking a closer look at the coreaudio programming guide. I could not find anything about interger data handling, except that everything gets converted to 32bit float. Neither did I find AppleHAL_2. If there's something about the data formats, I'd expect it there. :confused:

In the meantime I did build mpv myself to be sure everything is up to date and set up proprerly.

[cplayer] mpv git-24f98d1 (C) 2000-2015 mpv/MPlayer/mplayer2 projects
[cplayer]  built on 2015-05-15T08:28:55
[cplayer] ffmpeg library versions:
[cplayer]    libavutil       54.20.100
[cplayer]    libavcodec      56.26.100
[cplayer]    libavformat     56.25.101
[cplayer]    libswscale      3.1.101
[cplayer]    libavfilter     5.11.102
[cplayer]    libswresample   1.1.100

I reduced the mpv.conf file to just a few parameters, including:

ao=coreaudio:change-physical-format=yes

Testing the dts ma files again resulted in mpv decoding just the core track.

[ad] Codec list:
[ad]     lavc:dca (dts) - DCA (DTS Coherent Acoustics)
[ad] Opening audio decoder lavc:dca
[ad] Requesting 1 threads for decoding.
[ad] Selected audio codec: DCA (DTS Coherent Acoustics) [lavc:dca]
[cplayer] Starting playback...
[af] Audio filter chain:
[af]   [in] 48000Hz 5.1(side) 6ch floatp
[af]   [out] 48000Hz 5.1(side) 6ch floatp
[af]   [ao] 48000Hz 5.1(side) 6ch floatp
[ao] Trying preferred audio driver 'coreaudio'
[ao/coreaudio] Setting option 'change-physical-format' = 'yes' (flags = 0)
[ao/coreaudio] requested format: 48000 Hz, 5.1(side) channels, floatp
[ao/coreaudio] selected audio output device: Built-in Output (38)
[ao/coreaudio] Looking at formats in substream 0...
[ao/coreaudio] -  96000.0Hz 24bit 'lpcm' [4][8bpp][1fbp][8bpf][2ch] int LE S (-)
[ao/coreaudio] -  88200.0Hz 24bit 'lpcm' [4][8bpp][1fbp][8bpf][2ch] int LE S (-)
[ao/coreaudio] -  48000.0Hz 24bit 'lpcm' [4][8bpp][1fbp][8bpf][2ch] int LE S (-)
[ao/coreaudio] -  44100.0Hz 24bit 'lpcm' [4][8bpp][1fbp][8bpf][2ch] int LE S (-)
[ao/coreaudio] -  96000.0Hz 16bit 'lpcm' [12][4bpp][1fbp][4bpf][2ch] int LE S packed (s16)
[ao/coreaudio] -  88200.0Hz 16bit 'lpcm' [12][4bpp][1fbp][4bpf][2ch] int LE S packed (s16)
[ao/coreaudio] -  48000.0Hz 16bit 'lpcm' [12][4bpp][1fbp][4bpf][2ch] int LE S packed (s16)
[ao/coreaudio] -  44100.0Hz 16bit 'lpcm' [12][4bpp][1fbp][4bpf][2ch] int LE S packed (s16)
[ao/coreaudio] -  96000.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] -  88200.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] -  48000.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] -  44100.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] Trying to set physical format: 48000.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] converted input channel layout:
[ao/coreaudio] layout: tag: <0>, bitmap: <0>, descriptions <2>
[ao/coreaudio]  - description 0: label <4294967295, 64>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[ao/coreaudio]  - description 1: label <4294967295, 64>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[ao/coreaudio] converted input channel layout:
[ao/coreaudio] layout: tag: <0>, bitmap: <0>, descriptions <2>
[ao/coreaudio]  - description 0: label <1, 0>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[ao/coreaudio]  - description 1: label <2, 1>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[ao/coreaudio] audiounit latency [us]: 0
[ao/coreaudio] device latency [us]: 8958
[ao/coreaudio] using soft-buffer of 9600 samples.
[cplayer] AO: [coreaudio] 48000Hz stereo 2ch float

At the moment I'm trying to get things work on my macbook using the build in speaker. But that should not prevent mpv from decoding the dts ma track, or does it?

I've tried different sample files from here:

http://files.chriswoods.co.uk/dtsma-samples/

and here:

http://www.demo-world.eu/2d-demo-trailers-hd/

I'm pretty confident, that my files do contain a dts ma track although it does not seam to be listed in the header:

[mkv] Found the head...
[mkv] + a segment...
[mkv] /---- [ parsing seek head ] ---------
[mkv] \---- [ parsing seek head ] ---------
[mkv] |+ segment information...
[mkv] | + timecode scale: 1000000
[mkv] | + duration: 21.152s
[mkv] | + segment uid ab 89 f6 a6 46 3b 79 b4 9a 44 0e 12 7c 94 e7 6a
[mkv] |+ segment tracks...
[mkv] | + a track...
[mkv] |  + Track number: 1
[mkv] |  + Track type: Video
[mkv] |  + Video track
[mkv] |   + Display width: 1920
[mkv] |   + Display height: 1080
[mkv] |   + Pixel width: 1920
[mkv] |   + Pixel height: 1080
[mkv] |  + Codec ID: V_MPEG4/ISO/AVC
[mkv] |  + CodecPrivate, length 41
[mkv] |  + Default duration: 33.367ms ( = 29.970 fps)
[mkv] | + a track...
[mkv] |  + Track number: 2
[mkv] |  + Track type: Audio
[mkv] |  + Audio track
[mkv] |   + Sampling frequency: 48000.000000
[mkv] |   + Channels: 6
[mkv] |  + Codec ID: A_DTS
[mkv] |  + Default duration: 10.667ms ( = 93.750 fps)
[mkv] |+ found cluster
[mkv] Deferring reading cues.
[mkv] All headers are parsed!

I'm running out of ideas where look further. Did I miss something? Many thanks!

ghost commented 9 years ago

Your ffmpeg doesn't include the libdcadec wrapper.

Nu7ron commented 9 years ago

brew upgrade ffmpeg tells me I'm at the latest version 2.6.2. Do I need to explicitly add libdcadec? Something like brew upgrade ffmpeg --with-libdcadec?

ghost commented 9 years ago

I don't think the 2.6 releases include the wrapper yet. You probably need ffmpeg git.

Yes, it needs to be enabled at compilation. FFmpeg needs the --enable-libdcadec flag (out of my head, not sure if 100% correct) - I don't know how this maps to brew.

pigoz commented 9 years ago

Once there's a version of ffmpeg in homebrew that supports libdcadec, the package (homebrew calls this Formula) must be updated to account for it, and a libdcadec package must be added.

Nu7ron commented 9 years ago

Okay, installing with homebrew would be very convenient. Hope a new version of ffmpeg will be available soon.

Trying to complie the latest Git snapshot of ffmpeg is not working for me:

git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg running ./configure --enable-libdcadec gives me this error ERROR: dcadec not found using pkg-config In the log file I read:

Perhaps you should add the directory containing `dcadec.pc'
to the PKG_CONFIG_PATH environment variable

Sorry for all the hustle

ghost commented 9 years ago

You need to install libdcadec in a way ffmpeg's configure script can find it.

Nu7ron commented 9 years ago

The libdcadec.c source file itself is included in the libavcodec directory of the latest snapshot ... when I run ./configure --help the option --enable-libdcadec is available? Still I can't enable it.

I'll probalby just wait a little until the homebrew formula includes the dts ma decoder.

ghost commented 9 years ago

libavcodec doesn't contain the libdcadec source, only a wrapper.

pigoz commented 9 years ago

You want to compile and install dcadec, then when you compile ffmpeg you want to change PKG_CONFIG_PATH with the correct path where the .pc file for dcadec is. Then when you compile mpv you have to point again the PKG_CONFIG_PATH with the install directory of the ffmpeg (libav*) .pc files.

Maybe @ChrisK2 could add dcadec support it to his precompiled binaries.

Nu7ron commented 9 years ago

Got it up and running! Sorry I did not get in the first place.

Now that I compliled libdcadec first and checked if the .pc file is in the pkg_config directrory, enabling libdcadec for ffmpeg worked just fine. Unistalled mpv and complied it again from the latest Git snapshot.

Now my samplefiles are decoded in hi-res!

[cplayer] Starting playback...
[af] Audio filter chain:
[af]   [in] 96000Hz 7.1 8ch s32p
[af]   [out] 96000Hz 7.1 8ch s32p
[af]   [ao] 96000Hz 7.1 8ch s32p
[ao] Trying preferred audio driver 'coreaudio'
[ao/coreaudio] Setting option 'change-physical-format' = 'yes' (flags = 0)
[ao/coreaudio] requested format: 96000 Hz, 7.1 channels, s32p
[ao/coreaudio] selected audio output device: Built-in Output (38)
[ao/coreaudio] Looking at formats in substream 0...
[ao/coreaudio] -  96000.0Hz 24bit 'lpcm' [4][8bpp][1fbp][8bpf][2ch] int LE S (-)
[ao/coreaudio] -  88200.0Hz 24bit 'lpcm' [4][8bpp][1fbp][8bpf][2ch] int LE S (-)
[ao/coreaudio] -  48000.0Hz 24bit 'lpcm' [4][8bpp][1fbp][8bpf][2ch] int LE S (-)
[ao/coreaudio] -  44100.0Hz 24bit 'lpcm' [4][8bpp][1fbp][8bpf][2ch] int LE S (-)
[ao/coreaudio] -  96000.0Hz 16bit 'lpcm' [12][4bpp][1fbp][4bpf][2ch] int LE S packed (s16)
[ao/coreaudio] -  88200.0Hz 16bit 'lpcm' [12][4bpp][1fbp][4bpf][2ch] int LE S packed (s16)
[ao/coreaudio] -  48000.0Hz 16bit 'lpcm' [12][4bpp][1fbp][4bpf][2ch] int LE S packed (s16)
[ao/coreaudio] -  44100.0Hz 16bit 'lpcm' [12][4bpp][1fbp][4bpf][2ch] int LE S packed (s16)
[ao/coreaudio] -  96000.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] -  88200.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] -  48000.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] -  44100.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] Trying to set physical format: 96000.0Hz 32bit 'lpcm' [9][8bpp][1fbp][8bpf][2ch] float LE U packed (float)
[ao/coreaudio] converted input channel layout:
[ao/coreaudio] layout: tag: <0>, bitmap: <0>, descriptions <2>
[ao/coreaudio]  - description 0: label <4294967295, 64>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[ao/coreaudio]  - description 1: label <4294967295, 64>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[ao/coreaudio] converted input channel layout:
[ao/coreaudio] layout: tag: <0>, bitmap: <0>, descriptions <2>
[ao/coreaudio]  - description 0: label <1, 0>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[ao/coreaudio]  - description 1: label <2, 1>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[ao/coreaudio] audiounit latency [us]: 0
[ao/coreaudio] device latency [us]: 8510
[ao/coreaudio] using soft-buffer of 19200 samples.
[cplayer] AO: [coreaudio] 96000Hz stereo 2ch s32
Nu7ron commented 9 years ago

Thanks again for the assistance!

pigoz commented 9 years ago

Glad you got it working! For the record the binary by ChrisK also has libdcadec support as of today.

Nu7ron commented 9 years ago

For the record the binary by ChrisK also has libdcadec support as of today.

Great! Thanks everybody

@wm4 any thoughts on that interger mode paper?

ghost commented 9 years ago

@wm4 any thoughts on that interger mode paper?

That paper doesn't contain any actual information.

Nu7ron commented 9 years ago

Well, that's all I needed to know! :joy:

Nu7ron commented 9 years ago

Hi everyone, may I ask a follow-up question?

I recently managed to build libdcadec, ffmpeg and mpv on my macbook. When playing dts ma files, they get decoded as expected.

After this first success I bundled mpv using osxbundle.py without -s so that the dependencies get included in the app bundle. Copying the mpv.app file to applications and running it from the machine I compiled does let mpv to decode dts ma sample files.

But putting the same mpv.app file on my mac mini (media center) results in dts ma file not getting decoded. I then tried @ChrisK latest build, same behavior.

How do I make a mpv app bundle, that decodes dts ma independed of the machine it runs on?

Thx very much!

ChrisK2 commented 9 years ago

Okay so, as I just realized, my builds didn't actually include libdcadec due to a mistake on my end. As of mpv_20150519212632_git-e57a44c.tar.bz2 this is fixed. I also verified that mpv uses libdcadec on computers where libdcadec itself was not installed with my builds.

Nu7ron commented 9 years ago

@ChrisK2 Thank you! Is there a simple way to make an app bundle myself that includes libdcadec and other libraries that mpv depends on?

ChrisK2 commented 9 years ago

I just use osxbundle.py, so it should work right away. Maybe you haven't been compiling your ffmpeg statically or something?