Skip to content

Add 'SPDIF/ARC Mode' toggle and functionality#1410

Open
darkflame91 wants to merge 1 commit into
damontecres:mainfrom
darkflame91:ac3mode
Open

Add 'SPDIF/ARC Mode' toggle and functionality#1410
darkflame91 wants to merge 1 commit into
damontecres:mainfrom
darkflame91:ac3mode

Conversation

@darkflame91
Copy link
Copy Markdown

Description

This change provides a toggle that forces all multichannel audio to be transcoded to AC3 5.1.
This change does not force video transcode, subtitle burn-in, or alter any existing video stream transcoding behavior.

Similar to the downmixStereo and ac3Supported toggles, this new toggle applies only to Exoplayer and not mpv.

This is meant for TV's/devices that support SPDIF and/or ARC, but not eARC. Therefore they are limited to 6 channels and the AC3 codec (many such devices support DTS codec as well, but not as universally as AC3).
The main issue is that such devices frequently advertise support for more channels and/or newer codecs,
but silently downmix such audio streams to stereo internally.
This change ensures that the client will receive multichannel audio that is compatible with the device, while continuing to DirectPlay stereo audio without transcoding.
Of course, it requires audio transcoding to be enabled for the Jellyfin user and library.

This change primarily:

  1. Adds a toggle to enable this mode.
  2. Manages potentially conflicting 'Downmix to Stereo' and 'AC3 Supported' toggles.
  3. For video libraries, if toggle is enabled, sets max channels to 6 and invalidates all non-AC3 codecs for multichannel audio.
  4. For music libraries, if toggle is enabled, sets max channels to 6 and requests transcode to AC3 in mka container for multichannel audio.
  5. Handles switching audio streams mid-play (taken from PR Experiment: Option to transcode surround sound audio to AC3 #947)

Related issues

#335 , #255
Similar to Experimental PR #947 - but includes (i) transcoding only if required (ii) handling multichannel music.

Testing

  1. UT's added to validate and prevent potential toggle conflicts.
  2. Manually tested on Firestick 4k (1st gen) in video+audio libraries:
Audio Format Toggle OFF Toggle ON
Any stereo audio DirectPlay DirectPlay (unchanged)
AC3 5.1 DirectPlay DirectPlay (unchanged)
Any non-AC3 5.1/7.1 (incl. AAC, DTS, DD+, Atmos, DTS:X) DirectPlay (but output as stereo) DirectStream (only audio transcoded, output in 5.1)
  1. Verified that only audio was transcoded in Jellyfin (and ffmpeg) logs.
  2. Verified that switching between stereo and multichannel audio switches between DirectPlay and DirectStream.

Screenshots

N/A

AI or LLM usage

LLM's were used for planning, initial draft and critical reviews.
All code changes were manually reviewed and vetted.

This change forces all multichannel audio to be transcoded to AC3 5.1.
This is meant for TV's/devices that support SPDIF and/or ARC, but not
eARC. Therefore they are limited to 6 channels and the AC3 codec (many
such devices support DTS codec as well, but not as universally as AC3).
However, they frequently advertise support for more channels and newer
codecs, silently downmixing such audio streams internally. This change
ensures that the client can still output multichannel audio that is
compatible with the device.
This change does not force video transcode, or alter existing video
stream transcoding behavior.

This change primarily:
1. Adds a toggle to enable this mode.
2. Manages potentially conflicting 'Downmix to Stereo' and 'AC3
Supported' toggles.
3. For video libraries, if toggle is enabled, sets max channels to 6
and invalidates all non-AC3 codecs for multichannel audio.
4. For music libraries, if toggle is enabled, sets max channels to 6
and requests transcode to AC3 in mka container for multichannel audio.

Similar to Experimental PR damontecres#947.

1. UT's added to validate and prevent potential toggle conflicts.
2. Manually tested on Firestick 4k (1st gen) in video+audio libraries:
   - Stereo audio content plays with DirectPlay
   - Multichannel AC3 content plays with DirectPlay
   - Multichannel non-AC3 content plays with DirectStream

N/A

LLM's were used for planning, initial draft and critical review.
All code changes were manually reviewed and vetted.
Copy link
Copy Markdown
Owner

@damontecres damontecres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look pretty much the same as in #947. The device profile configuration and music transcoding are probably the only significant differences.

Can you elaborate more on the changes you've made?

@darkflame91
Copy link
Copy Markdown
Author

Thanks for reviewing! Yes, the changes are similar, the intents of the PR's overlap but differ, and the device profile configuration is the key difference.

My TV supports SPDIF and ARC, but not eARC. Due to SPDIF/ARC bandwidth constraints, my audio output is limited to 6 channel AC3 codec. All other multichannel audio is downmixed internally and output as stereo. I believe that such devices falsely advertise support for technically unsupported codecs and 8 channels to allow 'at least' downmixed stereo as a fallback.
Due to this, In the Wholphin release build, all videos with multichannel audio would output in stereo, unless they included an AC3 compatibility track.

From what I understood in #947 and the related issues, the intent there is to support devices that have eARC, and which either downmix or can't decode multichannel AAC and OPUS. All other multichannel audio codecs are DirectPlayed. IIRC things like downmixing (eg. 7.1 -> 5.1) or Atmos backward compatibility with DD+ is usually smartly handled by the devices themselves.

With the #947 toggle enabled for my SPDIF usecase, I would get:

  • Any Stereo -> DirectPlay (good)
  • 5.1 AC3 -> DirectPlay (good)
  • 5.1 AAC/Opus -> 5.1 AC3 (good)
  • 7.1 AAC/Opus -> 5.1 AC3 (good) (Potentially unwanted downmix for setups with eARC and 7.1 though)
  • 5.1/7.1 EAC3 -> DirectPlay downmixed to stereo (bad)
  • 5.1/7.1 DTS/PCM/Other -> DirectPlay downmixed to stereo (bad)

So with this PR, the intent is to specifically support SPDIF/ARC devices by requesting audio transcode for ALL non-AC3 multichannel audio, rather than only AAC and OPUS. I'm doing this by setting the device profile to explicitly exclude all non-AC3 multichannel support if the toggle is enabled, so that AC3 is the only available compatible codec for multichannel. I've seen that other media players have an 'SPDIF mode' or similar for this reason - I've seen it in Kodi and Pot Player.

Other differences:

  • I made the toggle for this feature automatically disable/enable the downmixStereo and ac3Supported toggles, with the (perhaps wrong?) assumption that any advanced user enabling this toggle would intend for those changes anyway.
  • Enabled transcoding for music libraries - I have a library of multichannel music in a bunch of different formats, and this would fix playback for it. I hardcoded mka as the container for this, because it wasn't in the existing Container list and I wasn't sure if I should add it there. If container is unspecified, it defaults to mp3, and fails.
  • Included the changeStreamsDirectPlay fix from Experiment: Option to transcode surround sound audio to AC3 #947 to make this PR feature-complete irrespective of when/if it was merged.

Can I propose a change to add an 'Audio Transcoding' sub-menu instead of these toggles, where the user can explicitly specify channel count and have granular control over the DirectPlay supported codecs?

I also ran into an issue with this PR that #947 had as well - PGS subtitles. I incorrectly said that subtitle burn-in was not forced. Turns out that since I've disabled video transcoding on my server, PGS subs were simply being dropped for me (despite 'selecting' them in the UI Subtitles menu). It looks like this is due to DirectStream remuxing to TS, which doesn't support PGS (IIRC you'd mentioned the same thing in a related thread). I'm exploring a workaround for it, but either way, I guess that would be a separate change, as it is unrelated to audio transcoding.

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

Successfully merging this pull request may close these issues.

2 participants