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

Cannot output stereo audio to ALSA rear: #3045

Closed
James-E-A opened this issue Apr 14, 2016 · 10 comments
Closed

Cannot output stereo audio to ALSA rear: #3045

James-E-A opened this issue Apr 14, 2016 · 10 comments

Comments

@James-E-A
Copy link

When playing audio with audio-device=alsa/rear:CARD=Live (the intent clearly being to send the sound's stereo channels to the rear stereo output of the "Live" card), MPV chokes on the fact that these are technically "rear speakers" and refuses to output the audio file's "front" stereo audio to them.

Regardless of the arguability of this behavior and whether or not ALSA should be displaying the channel map as "rear speakers" or not, MPV currently downmixes the audio to mono in this scenario.

It should be possible to send audio out the rear speakers of a computer without having to fiddle around with ALSA's arcane configuration or use PulseAudio as a stream remapper (which I am currently forced to do to get stereo sound from MPV out this card's good port.)

[cplayer] Command line options: '04 - Goodbye Yellow Brick Road.flac' '-v' '--audio-device=alsa/rear:CARD=Live' '-end' '00:00:00.001' '--no-ytdl'
[cplayer] mpv git-da34893 (C) 2000-2016 mpv/MPlayer/mplayer2 projects
[cplayer]  built on Wed Apr  6 03:01:01 UTC 2016
[cplayer] ffmpeg library versions:
[cplayer]    libavutil       55.20.100
[cplayer]    libavcodec      57.33.100
[cplayer]    libavformat     57.29.101
[cplayer]    libswscale      4.1.100
[cplayer]    libavfilter     6.40.102
[cplayer]    libswresample   2.0.101
[cplayer] ffmpeg version: N-79246-ga07934d
[cplayer] 
[cplayer] Configuration: ./waf configure --enable-pdf-build --enable-encoding --prefix=/usr --confdir=/etc/mpv
[cplayer] List of enabled features: alsa any-gl asm atomic-builtins atomics audio-input av-avpacket-int64-duration av-new-pixdesc av-pix-fmt-mmal av-subtitle-nopict av-version-info avcodec-chroma-pos-api avcodec-profile-name avframe-metadata avframe-skip-samples build-date cdda cplayer debug-build dlopen drm dvbin dvdnav dvdread encoding fchmod gl gl-x11 glibc-thread-name glob iconv jack jpeg lcms2 libass libass-osd libav libavdevice libavfilter libbluray libdl libguess libm librt libsmbclient libswresample libv4l2 linux-fstatfs lua nanosleep optimize oss-audio oss-audio-native posix posix-or-mingw posix-spawn pthreads pulse resampler rubberband shm sse4-intrinsics standard-gl subprocess termios tv tv-v4l2 uchardet vaapi vaapi-glx vaapi-hwaccel vaapi-x11 vdpau vdpau-gl-x11 vdpau-hwaccel videodev vt.h x11 xext xinerama xrandr xss xv zlib
[global] config path: '' -> '/home/james/.config/mpv'
[global] config path: 'mpv.conf' -> '/home/james/.config/mpv/mpv.conf'
[global] config path: 'config' -/-> '/home/james/.config/mpv/config'
[global] config path: 'mpv.conf' -/-> '/home/james/.mpv/mpv.conf'
[global] config path: 'config' -/-> '/home/james/.mpv/config'
[global] config path: 'mpv.conf' -/-> '/etc/mpv/mpv.conf'
[global] config path: 'config' -/-> '/etc/mpv/config'
[cplayer] Reading config file /home/james/.config/mpv/mpv.conf
[cplayer] Setting option 'vo' = 'opengl-hq:dscale=mitchell:icc-profile=/usr/share/color/icc/colord/sRGB.icc,vdpau' (flags = 4)
[cplayer] Setting option 'framedrop' = 'decoder+vo' (flags = 4)
[cplayer] Setting option 'hwdec' = 'vdpau' (flags = 4)
[cplayer] Setting option 'vf' = 'vdpaupp' (flags = 4)
[cplayer] Setting option 'use-filedir-conf' = '' (flags = 4)
[cplayer] Setting option 'screenshot-format' = 'png' (flags = 4)
[cplayer] Setting option 'screenshot-template' = '~/Pictures/mpvshot-%tY-%tm-%td-%P' (flags = 4)
[cplayer] Setting option 'alang' = 'ja,jpn,en,eng' (flags = 4)
[cplayer] Setting option 'ao-defaults' = 'alsa:resample=yes' (flags = 4)
[cplayer] Setting option 'osd-fractions' = '' (flags = 4)
[cplayer] Setting option 'slang' = 'en,eng' (flags = 4)
[cplayer] Setting option 'v' = '' (flags = 8)
[cplayer] Setting option 'audio-device' = 'alsa/rear:CARD=Live' (flags = 8)
[cplayer] Setting option 'end' = '00:00:00.001' (flags = 8)
[cplayer] Setting option 'no-ytdl' = '' (flags = 8)
[global] config path: 'input.conf' -> '/home/james/.config/mpv/input.conf'
[global] config path: 'input.conf' -/-> '/home/james/.mpv/input.conf'
[global] config path: 'input.conf' -/-> '/etc/mpv/input.conf'
[global] user path: '/home/james/.config/mpv/input.conf' -> '/home/james/.config/mpv/input.conf'
[ifo] Opening /home/james/.config/mpv/input.conf
[ifo/dvdnav] Opening /home/james/.config/mpv/input.conf
[bdmv/bluray] Opening /home/james/.config/mpv/input.conf
[file] Opening /home/james/.config/mpv/input.conf
[file] Stream opened successfully.
[input] Parsing input config file /home/james/.config/mpv/input.conf
[input] Input config file /home/james/.config/mpv/input.conf parsed: 4 binds
[osc] Loading script @osc.lua...
[global] config path: 'scripts' -/-> '/home/james/.config/mpv/scripts'
[global] config path: 'scripts' -/-> '/home/james/.mpv/scripts'
[global] config path: 'scripts' -/-> '/etc/mpv/scripts'
[osc] loading mp.defaults
[osc] loading @osc.lua
[global] config path: 'lua-settings/osc.conf' -> '/home/james/.config/mpv/lua-settings/osc.conf'
[cplayer] Run command: define-section, flags=0, args=[showhide, mouse_move script-binding osc/__keybinding1
[cplayer] mouse_leave script-binding osc/__keybinding2
[cplayer] , force]
[cplayer] Run command: enable-section, flags=0, args=[showhide, allow-hide-cursor+allow-vo-dragging]
[cplayer] Run command: define-section, flags=0, args=[input, mouse_btn0 script-binding osc/__keybinding3
[cplayer] shift+mouse_btn0 script-binding osc/__keybinding4
[cplayer] mouse_btn2 script-binding osc/__keybinding5
[cplayer] mouse_btn0_dbl ignore
[cplayer] shift+mouse_btn0_dbl ignore
[cplayer] mouse_btn2_dbl ignore
[cplayer] , force]
[cplayer] Run command: enable-section, flags=0, args=[input, ]
[cplayer] Run command: define-section, flags=0, args=[input_osc, del script-binding osc/__keybinding6
[cplayer] , default]
[cplayer] Run command: enable-section, flags=0, args=[input_osc, allow-hide-cursor+allow-vo-dragging]
[cplayer] Run command: define-section, flags=0, args=[input_forced_osc, , force]
[cplayer] Run command: enable-section, flags=0, args=[input_forced_osc, allow-hide-cursor+allow-vo-dragging]
[cplayer] Done loading @osc.lua.
[global] config path: 'scripts' -/-> '/home/james/.config/mpv/scripts'
[global] config path: 'scripts' -/-> '/home/james/.mpv/scripts'
[global] config path: 'scripts' -/-> '/etc/mpv/scripts'
[global] config path: 'watch_later' -> '/home/james/.config/mpv/watch_later'
[global] config path: '04 - Goodbye Yellow Brick Road.flac.conf' -/-> '/home/james/.config/mpv/04 - Goodbye Yellow Brick Road.flac.conf'
[global] config path: '04 - Goodbye Yellow Brick Road.flac.conf' -/-> '/home/james/.mpv/04 - Goodbye Yellow Brick Road.flac.conf'
[global] config path: '04 - Goodbye Yellow Brick Road.flac.conf' -/-> '/etc/mpv/04 - Goodbye Yellow Brick Road.flac.conf'
[cplayer] Playing: 04 - Goodbye Yellow Brick Road.flac
[cplayer] Run command: disable-section, flags=0, args=[input]
[global] config path: 'fonts' -/-> '/home/james/.config/mpv/fonts'
[global] config path: 'fonts' -/-> '/home/james/.mpv/fonts'
[global] config path: 'fonts' -/-> '/etc/mpv/fonts'
[osd/libass] Shaper: FriBidi 0.19.6 (SIMPLE) HarfBuzz-ng 0.9.27 (COMPLEX)
[global] config path: 'subfont.ttf' -/-> '/home/james/.config/mpv/subfont.ttf'
[global] config path: 'subfont.ttf' -/-> '/home/james/.mpv/subfont.ttf'
[global] config path: 'subfont.ttf' -/-> '/etc/mpv/subfont.ttf'
[global] config path: 'fonts.conf' -/-> '/home/james/.config/mpv/fonts.conf'
[global] config path: 'fonts.conf' -/-> '/home/james/.mpv/fonts.conf'
[global] config path: 'fonts.conf' -/-> '/etc/mpv/fonts.conf'
[osd/libass] Setting up fonts...
[ifo] Opening 04 - Goodbye Yellow Brick Road.flac
[ifo/dvdnav] Opening 04 - Goodbye Yellow Brick Road.flac
[bdmv/bluray] Opening 04 - Goodbye Yellow Brick Road.flac
[file] Opening 04 - Goodbye Yellow Brick Road.flac
[file] Stream opened successfully.
[demux] Trying demuxers for level=normal.
[lavf] Found 'flac' at score=50 size=2048.
[lavf] avformat_find_stream_info() finished after 65536 bytes.
[demux] Detected file format: flac (libavformat)
[osd/libass] Using font provider fontconfig
[osd/libass] Done.
[find_files] Loading external files in .
[global] config path: 'sub/' -/-> '/home/james/.config/mpv/sub/'
[global] config path: 'sub/' -/-> '/home/james/.mpv/sub/'
[global] config path: 'sub/' -/-> '/etc/mpv/sub/'
[global] config path: 'audio/' -/-> '/home/james/.config/mpv/audio/'
[global] config path: 'audio/' -/-> '/home/james/.mpv/audio/'
[global] config path: 'audio/' -/-> '/etc/mpv/audio/'
[cplayer]  (+) Audio --aid=1 (flac)
[display-tags] File tags:
[display-tags]  Artist: Elton John
[display-tags]  Album: Goodbye Yellow Brick Road (SuperDisk)
[display-tags]  Comment: Sussorro
[display-tags]  Genre: Rock
[display-tags]  Title: Goodbye Yellow Brick Road
[display-tags]  Track: 04
[ad] Codec list:
[ad]     lavc:flac - FLAC (Free Lossless Audio Codec)
[ad] Opening audio decoder lavc:flac
[ad] Requesting 1 threads for decoding.
[ad] Selected audio codec: FLAC (Free Lossless Audio Codec) [lavc:flac]
[cplayer] Starting playback...
[af] Audio filter chain:
[af]   [in] 44100Hz stereo 2ch s16
[af]   [out] 44100Hz stereo 2ch s16
[af]   [ao] 44100Hz stereo 2ch s16
[ao] Trying audio driver 'alsa'
[ao] Using preferred device 'rear:CARD=Live'
[ao/alsa] Setting option 'resample' = 'yes' (flags = 0)
[ao/alsa] requested format: 44100 Hz, stereo channels, s16
[ao/alsa] using ALSA version: 1.0.27.2
[ao/alsa] opening device 'rear:CARD=Live'
[ao/alsa] trying format s16
[ao/alsa] Channel layouts:
[ao/alsa]  - mono
[ao/alsa]  - bl-br
[ao/alsa] result: mono
[ao/alsa] trying to set ALSA channel map: UNKNOWN
[ao/alsa] channel map reported by ALSA: UNKNOWN
[ao/alsa] which we understand as: mono
[ao/alsa] using the ALSA channel map.
[ao/alsa] which is what we requested.
[ao/alsa] hw pausing supported: yes
[ao/alsa] buffersize: 11025 samples
[ao/alsa] period size: 735 samples
[ao/alsa] device buffer: 11025 samples.
[ao/alsa] using soft-buffer of 11025 samples.
[cplayer] AO: [alsa] 44100Hz mono 1ch s16
[cplayer] AO: Description: ALSA audio output
[af] Adding filter lavrresample 
[lavrresample] Remix: stereo -> mono
[af] Audio filter chain:
[af]   [in] 44100Hz stereo 2ch s16
[af]   [lavrresample] 44100Hz mono 1ch s16
[af]   [out] 44100Hz mono 1ch s16
[af]   [ao] 44100Hz mono 1ch s16
[cplayer] playback restart complete
[cplayer] EOF code: 1  
[ad] Uninit audio decoder.
[af] Removing filter lavrresample 
[cplayer] finished playback, success (reason 0)
[cplayer] 
[cplayer] 
[cplayer] Exiting... (End of file)
[osc] Exiting...
[ao/alsa] draining...
@James-E-A
Copy link
Author

I could theoretically set up an audio filter within MPV to swap the front and rear audio channels, but this is an unclean solution and does not work well with my current system which has a keybind A cycle_values audio-device alsa/rear:CARD=Live alsa/front:CARD=Live auto

@James-E-A
Copy link
Author

A stop-gap fix is:

# ~/.asoundrc
pcm.live_rear {
    type plug
    slave.pcm { type hw  card Live  device 3 }
    ttable {
        0.2 1
        1.3 1

    }
}

And then you use audio-device=alsa/live_rear

@James-E-A
Copy link
Author

James-E-A commented Apr 15, 2016

Might as well be worth mentioning that even FFmpeg itself supports playing stereo audio to ALSA's rear:CARD=Live without any ado:

ffmpeg version N-79139-gde1a0d4 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
  configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab
  libavutil      55. 19.100 / 55. 19.100
  libavcodec     57. 30.100 / 57. 30.100
  libavformat    57. 29.101 / 57. 29.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 40.102 /  6. 40.102
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, flac, from '04 - Goodbye Yellow Brick Road.flac':
  Metadata:
    TITLE           : Goodbye Yellow Brick Road
    ARTIST          : Elton John
    ALBUM           : Goodbye Yellow Brick Road (SuperDisk)
    DATE            : 1973
    GENRE           : Rock
    COMMENT         : Sussorro
    track           : 04
    ALBUM ARTIST    : Elton John
  Duration: 00:03:14.61, start: 0.000000, bitrate: 748 kb/s
    Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
[graph 0 input from stream 0:0 @ 0x2779000] tb:1/44100 samplefmt:s16 samplerate:44100 chlayout:0x3
Output #0, alsa, to 'rear:CARD=Live':
  Metadata:
    TITLE           : Goodbye Yellow Brick Road
    ARTIST          : Elton John
    ALBUM           : Goodbye Yellow Brick Road (SuperDisk)
    DATE            : 1973
    GENRE           : Rock
    COMMENT         : Sussorro
    track           : 04
    ALBUM ARTIST    : Elton John
    encoder         : Lavf57.29.101
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc57.30.100 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (flac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
No more output streams to write to, finishing.
size=N/A time=00:00:00.00 bitrate=N/A speed=0.379x    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (04 - Goodbye Yellow Brick Road.flac):
  Input stream #0:0 (audio): 2 packets read (6151 bytes); 2 frames decoded (8192 samples); 
  Total: 2 packets (6151 bytes) demuxed
Output file #0 (rear:CARD=Live):
  Output stream #0:0 (audio): 1 frames encoded (22 samples); 1 packets muxed (88 bytes); 
  Total: 1 packets (88 bytes) muxed

@ghost
Copy link

ghost commented Apr 15, 2016

I don't have such a device so I can't easily test. You should be able to duplicate ffmpeg's behavior by using --ao=alsa:ignore-chmap

@James-E-A
Copy link
Author

Hmm, adding ao-defaults=alsa:ignore-chmap= to config seems to work for now.

Don't know what implications this would have on playing surround sound, though.

@ghost
Copy link

ghost commented Apr 15, 2016

Probably bad ones.

This rear-only chmap should work in theory. The problem is probably that the chmap code selects mono instead. But it's not clear whether libswresample supports this kind of remix at all.

@ghost
Copy link

ghost commented Apr 16, 2016

Actually, I looked at the log again, and you try to output stereo to bl-br. mpv actually does the right thing and uses the next close working channel layout, which happens to be mono. So what it's doing here is fully intended.

@ghost
Copy link

ghost commented May 2, 2016

Would it be reasonable to ignore channel maps completely if channel count <= 2?

@mia-0
Copy link
Member

mia-0 commented Nov 6, 2016

I suppose it’s not going to cause any problems, as most software does this. And there have been issues like #2905.

ghost pushed a commit that referenced this issue Nov 8, 2016
If the input is already mono or stereo, or if channel map selection
results in mono or stereo, then disable further use of the champ ALSA
API (or rather, stop trusting its results). Then we behave like a simple
application that only wants to output mono or stereo.

See #3045 and #2905. I couldn't actually test these cases, but this
commit is supposed to fix them.
@ghost
Copy link

ghost commented Nov 8, 2016

Please retest with git master.

@mia-0 mia-0 closed this as completed Dec 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants