Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio channels (L-R) swapped using coreaudio, avfoundation correct #15584

Closed
6 tasks done
low-batt opened this issue Dec 28, 2024 · 3 comments · Fixed by #15622
Closed
6 tasks done

Audio channels (L-R) swapped using coreaudio, avfoundation correct #15584

low-batt opened this issue Dec 28, 2024 · 3 comments · Fixed by #15622

Comments

@low-batt
Copy link
Contributor

mpv Information

mpv v0.39.0-535-gbafb054cfc Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
 built on Dec 27 2024 19:45:02
libplacebo version: v7.350.0 (v7.349.0-30-g056b8520)
FFmpeg version: n7.1
FFmpeg library versions:
   libavcodec      61.19.100
   libavdevice     61.3.100
   libavfilter     10.4.100
   libavformat     61.7.100
   libavutil       59.39.100
   libswresample   5.3.100
   libswscale      8.3.100

Other Information

- macOS version: macOS 15.2 (24C101)
- Source of mpv:  My own build of master using mpv-build
- Latest known working version: Unknown
- Issue started after the following happened: Audio MIDI Setup used to reverse channels

Reproduction Steps

The problem is sensitive to the type of audio device. See more discussion about that in the Actual Behavior section below.

  • Download the YouTube video Stereo Test - Left/Right Audio Test for Headphones/Speakers using yt-dlp with the option -f 137+140 to obtain a format compatible with QuickTime Player

  • Attach an Apple/LG UltraFine™ 27MD5KL-B monitor to a compatible Mac

  • Open the Audio MIDI Setup app found in /Applications/Utilities

  • Select LG UltraFind Display Audio 2 (the speakers) and click on Configure Speakers…

  • Swap the left and right channels as shown here:
    configure

  • Play the above video with QuickTime Player and VLC and note the left and right channels are reversed as expected

  • Play the video with mpv and note that the left and right channels are not swapped

  • Play the video again with mpv adding --ao=avfoundation and note that the channels are reversed as expected

When reproducing the problem I ran mpv with these options:

low-batt@urp mpv-build (master %=)$ mpv/build/mpv --no-config --gpu-debug --log-file=output.txt ~/Movies/Stereo\ Test\ -\ Left⧸Right\ Audio\ Test\ for\ Headphones⧸Speakers\ \[YwNs1Z0qRY0\].mp4 
● Video  --vid=1               (h264 1920x1080 30 fps) [default]
● Audio  --aid=1  --alang=eng  (aac 2ch 44100 Hz 128 kbps) [default]
AO: [coreaudio] 44100Hz fr-fl (stereo) 2ch floatp
VO: [gpu] 1920x1080 yuv420p
2024-12-27 19:51:41.893 mpv[77151:2993709] +[IMKClient subclass]: chose IMKClient_Modern
2024-12-27 19:51:41.893 mpv[77151:2993709] +[IMKInputSession subclass]: chose IMKInputSession_Modern
AV: 00:00:20 / 00:00:20 (99%) A-V:  0.000 
Exiting... (End of file)

Expected Behavior

The --ao=coreaudio channel layout matches the --ao=avfoundation channel layout.

Actual Behavior

The coreaudio channel layout does not reflect the configuration applied by Audio MIDI Setup.

This was reported against IINA in issue iina/iina#5322. I initially tried to reproduce it using two Braven 770 Bluetooth speakers. The stereo layout was selected and the problem did not reproduce.

Working using BRAVEN 770 speakers:
[   2.776][v][ao] Trying audio driver 'coreaudio'
[   2.776][v][ao/coreaudio] requested format: 48000 Hz, stereo channels, floatp
[   2.776][v][ao/coreaudio] selected audio output device: BRAVEN 770 (93)
[   2.777][v][ao/coreaudio] input channel layout:
[   2.777][v][ao/coreaudio] layout: tag: <0>, bitmap: <0>, descriptions <2>
[   2.777][v][ao/coreaudio]  - description 0: label <1, 0>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[   2.777][v][ao/coreaudio]  - description 1: label <2, 1>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[   2.777][v][ao/coreaudio] mp chmap: stereo
[   2.777][v][ao/coreaudio] input channel layout:
[   2.777][v][ao/coreaudio] layout: tag: <0>, bitmap: <0>, descriptions <2>
[   2.777][v][ao/coreaudio]  - description 0: label <2, 1>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[   2.777][v][ao/coreaudio]  - description 1: label <1, 0>,  flags: <0>, coords: <0.000000, 0.000000, 0.000000>
[   2.777][v][ao/coreaudio] mp chmap: fr-fl
[   2.777][v][ao/coreaudio] Channel layouts:
[   2.777][v][ao/coreaudio]  - stereo
[   2.777][v][ao/coreaudio]  - fr-fl
[   2.777][v][ao/coreaudio]  - mono
[   2.777][v][ao/coreaudio] result: stereo

With the speakers in the LG display the fr-fl layout was selected and the problem reproduced. The LG display is the one that was done in partnership with Apple, so the speakers contained in it should be fully compatible with macOS and yet one of the layouts is reported as unknown2. That doesn't seem right?

Not working using LG display speakers:
[   0.154][v][ao] Trying audio driver 'coreaudio'
[   0.154][v][ao/coreaudio] requested format: 44100 Hz, stereo channels, floatp
[   0.218][v][ao/coreaudio] selected audio output device: LG UltraFine Display Audio (114)
[   0.218][v][ao/coreaudio] input channel layout:
[   0.218][v][ao/coreaudio] audio channel layout: tag: <0>, descriptions <2>
[   0.218][v][ao/coreaudio]  - description 0: label <4294967295, 64>,  flags: <0>
[   0.218][v][ao/coreaudio]  - description 1: label <4294967295, 64>,  flags: <0>
[   0.218][v][ao/coreaudio] mp chmap: unknown2
[   0.218][v][ao/coreaudio] input channel layout:
[   0.218][v][ao/coreaudio] audio channel layout: tag: <0>, descriptions <2>
[   0.218][v][ao/coreaudio]  - description 0: label <2, 1>,  flags: <0>
[   0.218][v][ao/coreaudio]  - description 1: label <1, 0>,  flags: <0>
[   0.218][v][ao/coreaudio] mp chmap: fr-fl
[   0.218][v][ao/coreaudio] Channel layouts:
[   0.218][v][ao/coreaudio]  - fr-fl
[   0.218][v][ao/coreaudio]  - mono
[   0.218][v][ao/coreaudio] result: fr-fl

Running mpv with --ao=avfoundation the behavior is as expected and matches QuickTime Player and VLC.

This may be related to issue #11590.

Log File

coreaudio-output.txt
avfoundation-output.txt

Sample Files

I downloaded the YouTube video Stereo Test - Left/Right Audio Test for Headphones/Speakers like so:
yt-dlp -f 137+140 https://www.youtube.com/watch?v=YwNs1Z0qRY0

mediainfo:
low-batt@urp youtube-dl$ mediainfo Stereo\ Test\ -\ Left⧸Right\ Audio\ Test\ for\ Headphones⧸Speakers\ \[YwNs1Z0qRY0\].mp4 
General
Complete name                            : Stereo Test - Left⧸Right Audio Test for Headphones⧸Speakers [YwNs1Z0qRY0].mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 1.24 MiB
Duration                                 : 20 s 852 ms
Overall bit rate                         : 499 kb/s
Frame rate                               : 30.000 FPS
Writing application                      : Lavf61.7.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4
Format settings                          : CABAC / 2 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 2 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 20 s 800 ms
Bit rate                                 : 364 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 30.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.006
Stream size                              : 923 KiB (73%)
Title                                    : ISO Media file produced by Google Inc.
Writing library                          : x264 core 155 r2901 7d0ff22
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 20 s 852 ms
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 44.1 kHz
Frame rate                               : 43.066 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 326 KiB (26%)
Title                                    : ISO Media file produced by Google Inc.
Language                                 : English
Default                                  : Yes
Alternate group                          : 1

I carefully read all instruction and confirm that I did the following:

  • I tested with the latest mpv version to validate that the issue is not already fixed.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.
  • I attached the backtrace in the case of a crash.
@Akemi
Copy link
Member

Akemi commented Dec 28, 2024

@ruihe774 do you think you have time to look into this?

@ruihe774
Copy link
Contributor

@ruihe774 do you think you have time to look into this?

It's Xmas. Let me investigate this later.

@Akemi
Copy link
Member

Akemi commented Dec 28, 2024

of course, enjoy your christmas 👍.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants