RasPlex / OpenPHT

OpenPHT is a community driven fork of Plex Home Theater
Other
597 stars 110 forks source link

Audio channels are mapped incorrectly when playing back multi-channel music files #125

Open sammy2142 opened 8 years ago

sammy2142 commented 8 years ago

Playing back a multi-channel audio file (.ac3) in the music category; the channels are mapped incorrectly/differently than when playing back a video with surround sound on the same device:

The front left channel is played out of the centre speaker The centre channel is played out of the left surround speaker The right surround channel comes out of the front right speaker The left surround channel comes out of the front left speaker The base channel comes out of the right surround speaker And the front right comes out of the sub.

All speakers are correctly hooked up and are mapped correctly when watching a movie with surround sound. This issue seems to only occur with music playback.

Sample file: https://archive.org/download/5.1SurroundSoundTestFilesVariousFormatsAACAC3MP4DTSWAV/surroundTest%20-%20Copy.ac3

Running openpht embedded v1.6.2 Plex media server Version 1.0.0.2261 (windows server 2012 r2)

Using plex black skin

Alibloke commented 8 years ago

I can confirm the audio channels are all mixed up for me too. I thought I was going crazy!

g1t-dlanor commented 8 years ago

I wonder if this could be due to a simple obsolete lib error. Some ffmpeg versions incorrectly treated all multi-channel audio tracks of videos as if they had the same audio channel order regardless of the audio CODEC (AAC, AC3, etc), which caused incorrect audio playback of videos converted or played through that ffmpeg lib. That error has been corrected in later ffmpeg versions, which thus eliminated that bug from RasPlex/OpenPHT. What you describe seems like a similar lib error for the handling of these music files. Perhaps a lib used for that purpose still has the same bug, and now needs a similar fix.

bronzeblood commented 7 years ago

Im having the same problem, multichannel flacs are routed to the wrong speakers. Even if i select 5.1 in audio settings my receiver shows its getting a 7.1 signal and my rear speakers dont work. (actually i think my rear left does work), Looks like a audio routing problem. Im using odroid c2 and build v1.7.1.137-b604995c-egl. Hope this can be fixed, one of the reasons i got the odroid is to play multichannel audio.

cpmessina commented 7 years ago

Same issue here - 5.1 flacs, mixed up audio channels. Appears to be similar mappings as what sammy2142 has said. openpht-embedded 1.8.0.148–573b6d73 odroid c2

g1t-dlanor commented 7 years ago

Are these flacs newly encoded using modern apps ? And do the same files play with correct channel order using other players on the same hardware ? Otherwise the fault may lie in the original flac encoder using the old bugged libs mentioned earlier.

Current OpenPHT versions use newer libs for these things, so unless some coder for those libs has made a horrible regression we shouldn't have such problems in our code anymore. But there's of course always a risk of regressions in libs still under development by multiple coders... :(

cpmessina commented 7 years ago

Good question! Define 'modern', though :-) I can't be certain when I encoded these and whether or not it was using flac, or ffmpeg. If it was flac, it would have been v1.3.0. FFMpeg could have been v3.0.4 or v2.8.

I can tell you that I was using the same hardware using LibreElec 7.1 (Kodi 16.1) and they appeared to play correctly. Prior to that I had different hardware (standard PC, Linux based) running Kodi (want to say v16ish) and it played correctly.

A buddy of mine is using Kodi v14 on his Windows HT and it appears to play correctly, also.

Do you know any times or versions that the libs were updated with the bug fix? Are we talking just a year or so ago, or 5+? If I reencode using ffmpeg v3.0, is that current enough to use the correct format?

stevenh commented 7 years ago

I can confirm I'm seeing the same here, as mentioned in the Plex forums: https://forums.plex.tv/discussion/277342/wrong-channel-mapping-for-multi-channel-flac

I've confirmed that box Plex Media Player and VLC play the files correctly.

stevenh commented 7 years ago

The following from vlc may be interesting:

directsound debug: Opening DirectSound Audio Output
qt4 debug: IM: Setting an input
directsound debug: Windows speaker config: 7.1 and stream has 6 channels, using 6 channels
directsound debug: couldn't use hardware sound buffer
directsound debug: channel reordering needed
core debug: output 'f32l' 88200 Hz 3F2R/LFE frame=1 samples/24 bytes
core debug: looking for audio volume module matching "any": 2 candidates
core debug: using audio volume module "float_mixer"
core debug: input 's32l' 88200 Hz 3F2R/LFE frame=1 samples/24 bytes
core debug: looking for audio filter module matching "scaletempo": 14 candidates
scaletempo debug: format: 88200 rate, 6 nch, 4 bps, fl32
scaletempo debug: params: 30 stride, 0.200 overlap, 14 search
scaletempo debug: 1.000 scale, 2646.000 stride_in, 2646 stride_out, 2117 standing, 529 overlap, 1234 search, 4409 queue, fl32 mode
core debug: using audio filter module "scaletempo"
core debug: conversion: 's32l'->'f32l' 88200 Hz->88200 Hz 3F2R/LFE->3F2R/LFE
core debug: looking for audio converter module matching "any": 12 candidates
audio_format debug: s32l->f32l, bits per sample: 32->32
core debug: using audio converter module "audio_format"
core debug: conversion pipeline complete
core debug: conversion: 'f32l'->'f32l' 88200 Hz->88200 Hz 3F2R/LFE->3F2R/LFE
core debug: conversion pipeline complete
core debug: looking for audio resampler module matching "any": 3 candidates
core debug: using audio resampler module "samplerate"
core debug: End of audio preroll
core debug: Decoder wait done in 5 ms

Note the "channel reordering needed"

stevenh commented 7 years ago

Logs from OpenPHT for the same file

22:47:21 T:5400   DEBUG: CDVDDemuxFFmpeg::Open - probing detected format [flac]
22:47:21 T:5400   DEBUG: CDVDDemuxFFmpeg::Open - avformat_find_stream_info starting
22:47:21 T:5400   DEBUG: CDVDDemuxFFmpeg::Open - av_find_stream_info finished
22:47:21 T:5400    INFO: ffmpeg[1518]: Input #0, flac, from 'D:\Media\Music\DVD-Audio\Seal - Seal IV\01 - Get It Together.flac':
22:47:21 T:5400    INFO: ffmpeg[1518]:   Metadata:
22:47:21 T:5400    INFO: ffmpeg[1518]:     TITLE           : Get It Together
22:47:21 T:5400    INFO: ffmpeg[1518]:     track           : 1
22:47:21 T:5400    INFO: ffmpeg[1518]:     ARTIST          : Seal
22:47:21 T:5400    INFO: ffmpeg[1518]:     ALBUM           : Seal IV
22:47:21 T:5400    INFO: ffmpeg[1518]:     GENRE           : Pop
22:47:21 T:5400    INFO: ffmpeg[1518]:     DATE            : 2004
22:47:21 T:5400    INFO: ffmpeg[1518]:   Duration: 00:04:01.60, start: 0.000000, bitrate: 5164 kb/s
22:47:21 T:5400    INFO: ffmpeg[1518]:     Stream #0:0: Audio: flac, 88200 Hz, 5.1, s32 (24 bit)
22:47:21 T:5400   DEBUG: CDVDDemuxFFmpeg::AddStream(0, ...) -> 0
22:47:21 T:5400   DEBUG: FactoryCodec - Audio: passthrough - Opening
22:47:21 T:5400   DEBUG: FactoryCodec - Audio: passthrough - Failed
22:47:21 T:5400   DEBUG: FactoryCodec - Audio: FFmpeg - Opening
22:47:21 T:5400   DEBUG: FactoryCodec - Audio: FFmpeg - Opened
22:47:22 T:5400    INFO: AudioDecoder: File is queued
22:47:22 T:5400   DEBUG: AudioDecoder::GetReplayGain - Final Replaygain applied: 1.000000, Track/Album Gain 89.000000, Peak 0.000000
22:47:22 T:9996    INFO: CActiveAESink::OpenSink - initialize sink
22:47:22 T:9996   DEBUG: CActiveAESink::OpenSink - trying to open device WASAPI:{F84AD376-AADD-4E78-BB86-E69874722156}
22:47:22 T:9996    INFO: CAESinkWASAPI::InitializeExclusive: WASAPI Exclusive Mode Sink Initialized using: AE_FMT_S24NE4MSB, 96000, 6
22:47:22 T:9996   DEBUG: CActiveAESink::OpenSink - WASAPI Initialized:
22:47:22 T:9996   DEBUG:   Output Device : HDMI - DENON-AVRHD-8 (NVIDIA High Definition Audio)
22:47:22 T:9996   DEBUG:   Sample Rate   : 96000
22:47:22 T:9996   DEBUG:   Sample Format : AE_FMT_S24NE4MSB
22:47:22 T:9996   DEBUG:   Channel Count : 6
22:47:22 T:9996   DEBUG:   Channel Layout: FL,FR,FC,LFE,SL,SR
22:47:22 T:9996   DEBUG:   Frames        : 4800
22:47:22 T:9996   DEBUG:   Frame Samples : 28800
22:47:22 T:9996   DEBUG:   Frame Size    : 24
22:47:22 T:5260   DEBUG: CActiveAE::ClearDiscardedBuffers - buffer pool deleted
22:47:22 T:5400   DEBUG: Previous line repeats 1 times.
22:47:22 T:5400    INFO: PAPlayer::PrepareStream - Ready
22:47:22 T:5400   DEBUG: Activating window ID: 10050
22:47:22 T:9808   DEBUG: Thread PAPlayer start, auto delete: false
22:47:22 T:9808   DEBUG: PAPlayer::Process - Playback started
stevenh commented 7 years ago

Log from kodi which also plays the file correctly:

00:09:06.365 T:8748   DEBUG: CDVDDemuxFFmpeg::Open - probing detected format [flac]
00:09:06.366 T:8748   DEBUG: CDVDDemuxFFmpeg::Open - avformat_find_stream_info starting
00:09:06.366 T:8748   DEBUG: CDVDDemuxFFmpeg::Open - av_find_stream_info finished
00:09:06.366 T:8748   DEBUG: CDVDDemuxFFmpeg::AddStream ID: 0
00:09:06.366 T:8748   DEBUG: FactoryCodec - Audio: passthrough - Opening
00:09:06.366 T:8748   DEBUG: FactoryCodec - Audio: passthrough - Failed
00:09:06.366 T:8748   DEBUG: FactoryCodec - Audio: FFmpeg - Opening
00:09:06.366 T:8748   DEBUG: FactoryCodec - Audio: FFmpeg - Opened
00:09:06.369 T:8748   DEBUG: unrecognized XipComment name: WAVEFORMATEXTENSIBLE_CHANNEL_MASK
00:09:06.370 T:8748   DEBUG: CDVDDemuxFFmpeg::SeekTime - seek ended up on time 0
00:09:06.913 T:8748   DEBUG: Previous line repeats 1 times.
00:09:06.913 T:8748    INFO: AudioDecoder: File is queued
00:09:06.915 T:8748   DEBUG: AudioDecoder::GetReplayGain - Final Replaygain applied: 1.000000, Track/Album Gain 89.000000, Peak 1.000000
00:09:07.005 T:6204    INFO: CActiveAESink::OpenSink - initialize sink
00:09:07.062 T:6204   DEBUG: CActiveAESink::OpenSink - trying to open device WASAPI:{F84AD376-AADD-4E78-BB86-E69874722156}
00:09:07.086 T:6204    INFO: CAESinkWASAPI::InitializeExclusive: WASAPI Exclusive Mode Sink Initialized using: AE_FMT_S24NE4MSB, 96000, 6
00:09:07.086 T:6204   DEBUG: CActiveAESink::OpenSink - WASAPI Initialized:
00:09:07.086 T:6204   DEBUG:   Output Device : HDMI - DENON-AVRHD-8 (NVIDIA High Definition Audio)
00:09:07.086 T:6204   DEBUG:   Sample Rate   : 96000
00:09:07.086 T:6204   DEBUG:   Sample Format : AE_FMT_S24NE4MSB
00:09:07.086 T:6204   DEBUG:   Channel Count : 6
00:09:07.086 T:6204   DEBUG:   Channel Layout: FL,FR,FC,LFE,SL,SR
00:09:07.086 T:6204   DEBUG:   Frames        : 4800
00:09:07.086 T:6204   DEBUG:   Frame Size    : 24
00:09:07.117 T:10720   DEBUG: CActiveAE::ClearDiscardedBuffers - buffer pool deleted
00:09:07.184 T:8748   DEBUG: Previous line repeats 1 times.
00:09:07.184 T:8748    INFO: PAPlayer::PrepareStream - Ready
00:09:07.184 T:8748   DEBUG: CApplication::PlayFile: OpenFile succeed, play state 1
00:09:07.184 T:8748   DEBUG: Keyboard: scancode: 0x1c, sym: 0x000d, unicode: 0x0000, modifier: 0x0
00:09:07.184 T:8112   DEBUG: Thread PAPlayer start, auto delete: false
00:09:07.184 T:8112   DEBUG: PAPlayer::Process - Playback started
cpmessina commented 6 years ago

I did some testing today - found that when I play the OP's test AC3 file it plays fine with passthrough, but when I turn off passthrough in OpenPHT, the channels get mapped wonky. Same thing happens with that same exact file converted to FLAC (ffmpeg -i surround.ac3 surround.flac) - wonky channel maps, but can't test FLAC passthrough. So, it doesn't appear that it's limited to FLAC's.

Best I can tell, movies play fine with or without passthrough.

Beginning of plexhometheater.log w/sound devices:

 02:45:34 T:548381450240  NOTICE: Found 2 Lists of Devices
02:45:34 T:548381450240  NOTICE: Enumerated ALSA devices:
02:45:34 T:548381450240  NOTICE:     Device 1
02:45:34 T:548381450240  NOTICE:         m_deviceName      : default
02:45:34 T:548381450240  NOTICE:         m_displayName     : Default (AML-M8AUDIO Analog)
02:45:34 T:548381450240  NOTICE:         m_displayNameExtra:
02:45:34 T:548381450240  NOTICE:         m_deviceType      : AE_DEVTYPE_PCM
02:45:34 T:548381450240  NOTICE:         m_channels        : FL,FR,UNKNOWN1,LFE,BL,BR,FC,BC,BLOC,BROC
02:45:34 T:548381450240  NOTICE:         m_sampleRates     : 32000,44100,48000,88200,96000,176400,192000
02:45:34 T:548381450240  NOTICE:         m_dataFormats     : AE_FMT_S32NE
02:45:34 T:548381450240  NOTICE:     Device 2
02:45:34 T:548381450240  NOTICE:         m_deviceName      : hdmi:CARD=AMLM8AUDIO,DEV=0
02:45:34 T:548381450240  NOTICE:         m_displayName     : AML-M8AUDIO
02:45:34 T:548381450240  NOTICE:         m_displayNameExtra: HDMI
02:45:34 T:548381450240  NOTICE:         m_deviceType      : AE_DEVTYPE_HDMI
02:45:34 T:548381450240  NOTICE:         m_channels        : FL,FR,BL,BR,FC,LFE,SL,SR
02:45:34 T:548381450240  NOTICE:         m_sampleRates     : 32000,44100,48000,88200,96000,176400,192000
02:45:34 T:548381450240  NOTICE:         m_dataFormats     : AE_FMT_S16NE,AE_FMT_S16LE,AE_FMT_LPCM,AE_FMT_DTSHD,AE_FMT_TRUEHD,AE_FMT_EAC3,AE_FMT_DTS,AE_FMT_AC3,AE_FMT_AAC
02:45:34 T:548381450240  NOTICE: Enumerated PULSE devices:
02:45:34 T:548381450240  NOTICE:     Device 1
02:45:34 T:548381450240  NOTICE:         m_deviceName      : Default
02:45:34 T:548381450240  NOTICE:         m_displayName     : Bluetooth
02:45:34 T:548381450240  NOTICE:         m_displayNameExtra:
02:45:34 T:548381450240  NOTICE:         m_deviceType      : AE_DEVTYPE_PCM
02:45:34 T:548381450240  NOTICE:         m_channels        : FL,FR
02:45:34 T:548381450240  NOTICE:         m_sampleRates     : 5512,8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,176400,192000,384000
02:45:34 T:548381450240  NOTICE:         m_dataFormats     : AE_FMT_U8,AE_FMT_S16NE,AE_FMT_S24NE3,AE_FMT_S24NE4,AE_FMT_S32NE,AE_FMT_FLOAT

Log from where the FLAC was played (w/no passthrough):

17:58:30 T:548381450240   DEBUG: Open - probing detected format [flac]
17:58:30 T:548381450240   DEBUG: Open - avformat_find_stream_info starting
17:58:30 T:548381450240   DEBUG: Open - av_find_stream_info finished
17:58:30 T:548381450240    INFO: ffmpeg[7FAE14E000]: Input #0, flac, from 'plexserver://217ae06c505610738c489c10a669a9a9b58be44c/library/parts/29146/1505684273/file.flac':
17:58:30 T:548381450240    INFO: ffmpeg[7FAE14E000]:   Metadata:
17:58:30 T:548381450240    INFO: ffmpeg[7FAE14E000]:     ENCODER         : Lavf57.25.100
17:58:30 T:548381450240    INFO: ffmpeg[7FAE14E000]:   Duration: 00:00:08.53, start: 0.000000, bitrate: 1027 kb/s
17:58:30 T:548381450240    INFO: ffmpeg[7FAE14E000]:     Stream #0:0: Audio: flac, 44100 Hz, 5.1(side), s32 (24 bit)
17:58:30 T:548381450240   DEBUG: CDVDDemuxFFmpeg::AddStream(0, ...) -> 0
17:58:30 T:548381450240   DEBUG: FactoryCodec - Audio: passthrough - Opening
17:58:30 T:548381450240   DEBUG: FactoryCodec - Audio: passthrough - Failed
17:58:30 T:548381450240   DEBUG: FactoryCodec - Audio: FFmpeg - Opening
17:58:30 T:548381450240   DEBUG: FactoryCodec - Audio: FFmpeg - Opened
17:58:30 T:546190651712    INFO: CFileCache::Process - Hit eof.
17:58:30 T:548381450240    INFO: AudioDecoder: File is queued
17:58:30 T:548381450240   DEBUG: AudioDecoder::GetReplayGain - Final Replaygain applied: 1.000000, Track/Album Gain 89.000000, Peak 0.000000
17:58:30 T:548364661056    INFO: CActiveAESink::OpenSink - initialize sink
17:58:30 T:548364661056   DEBUG: CActiveAESink::OpenSink - trying to open device ALSA:hdmi:CARD=AMLM8AUDIO,DEV=0
17:58:30 T:548364661056    INFO: CAESinkALSA::Initialize - Attempting to open device "default"
17:58:30 T:548364661056    INFO: CAESinkALSA::Initialize - Opened device "default"
17:58:30 T:548364661056    INFO: CAESinkALSA::InitializeHW - Your hardware does not support AE_FMT_FLOAT, trying other formats
17:58:30 T:548364661056    INFO: CAESinkALSA::InitializeHW - Using data format AE_FMT_S32NE
17:58:30 T:548364661056   DEBUG: CAESinkALSA::InitializeHW - Min: periodSize 2, periods 2, bufferSize 4
17:58:30 T:548364661056   DEBUG: CAESinkALSA::InitializeHW - Max: periodSize 2048, periods 1024, bufferSize 16384
17:58:30 T:548364661056   DEBUG: CAESinkALSA::InitializeHW - Request: periodSize 1024, periods 8, bufferSize 8192
17:58:30 T:548364661056   DEBUG: CAESinkALSA::InitializeHW - Got: periodSize 1024, bufferSize 8192
17:58:30 T:548364661056   DEBUG: CAESinkALSA::InitializeHW - Setting timeout to 186 ms
17:58:30 T:548364661056   DEBUG: CAESinkALSA::GetChannelLayout - Input Channel Count: 6 Output Channel Count: 8
17:58:30 T:548364661056   DEBUG: CAESinkALSA::GetChannelLayout - Requested Layout: FL,FR,FC,LFE,SL,SR
17:58:30 T:548364661056   DEBUG: CAESinkALSA::GetChannelLayout - Got Layout: FL,FR,LFE,FC,SL,SR,UNKNOWN1,UNKNOWN1 (ALSA: FL FR LFE FC RL RR NA NA)
17:58:30 T:548364661056   DEBUG: CActiveAESink::OpenSink - ALSA Initialized:
17:58:30 T:548364661056   DEBUG:   Output Device : AML-M8AUDIO
17:58:30 T:548364661056   DEBUG:   Sample Rate   : 44100
17:58:30 T:548364661056   DEBUG:   Sample Format : AE_FMT_S32NE
17:58:30 T:548364661056   DEBUG:   Channel Count : 8
17:58:30 T:548364661056   DEBUG:   Channel Layout: FL,FR,LFE,FC,SL,SR,UNKNOWN1,UNKNOWN1
17:58:30 T:548364661056   DEBUG:   Frames        : 1024
17:58:30 T:548364661056   DEBUG:   Frame Samples : 8192
17:58:30 T:548364661056   DEBUG:   Frame Size    : 32
17:58:30 T:548373049664   DEBUG: CActiveAE::ClearDiscardedBuffers - buffer pool deleted
17:58:30 T:548381450240   DEBUG: Previous line repeats 1 times.
17:58:30 T:548381450240    INFO: PAPlayer::PrepareStream - Ready
17:58:30 T:548381450240   DEBUG: Activating window ID: 10050
17:58:30 T:545897083200   DEBUG: Thread PAPlayer start, auto delete: false
17:58:30 T:545897083200   DEBUG: PAPlayer::Process - Playback started

None of the referenced channel mappings are what come out, though.