Experimental option to transcode surround sound audio to AC3 (#947)

## Description
Adds an experimental setting to prefer transcoding audio with more than
2 channels to AC3. Stereo audio does not transcode.

This is basically a workaround for HDMI ARC (not eARC) or optical audio
devices because instead of 2 uncompressed PCM channels, 6 AC3 channels
(ie 5.1) is possible.

An downside of enabling this is that embedded subtitles be burned in
causing a video transcode as well.

### Related issues
Fixes #255
Incorporates some code from #1410

### Testing
Just on the emulator so far to observe if the settings trigger the
transcode or not

## Screenshots
N/A

## AI or LLM usage
None

---------

Co-authored-by: darkflame91 <darkflame91@gmail.com>
This commit is contained in:
Damontecres 2026-07-09 13:15:42 -04:00 • committed by GitHub
parent f2287a85e8
commit d481aea85a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 205 additions and 54 deletions

View file

@ -54,6 +54,7 @@ import com.github.damontecres.wholphin.services.ScreensaverService
import com.github.damontecres.wholphin.services.StreamChoiceService
import com.github.damontecres.wholphin.services.UserPreferencesService
import com.github.damontecres.wholphin.ui.formatBitrate
import com.github.damontecres.wholphin.ui.gt
import com.github.damontecres.wholphin.ui.isNotNullOrBlank
import com.github.damontecres.wholphin.ui.launchDefault
import com.github.damontecres.wholphin.ui.launchIO
@ -646,7 +647,7 @@ class PlaybackViewModel
deviceProfile =
if (currentPlayer.value!!.backend == PlayerBackend.EXO_PLAYER) {
deviceProfileService.getOrCreateDeviceProfile(
preferences.appPreferences.playbackPreferences,
preferences.appPreferences,
serverRepository.currentServer?.serverVersion,
)
} else {
@ -855,9 +856,24 @@ class PlaybackViewModel
// TODO there's probably no reason why we can't add external subtitles?
Timber.v("changeStreams direct play")
// TODO Better way to handle unsupported types in general is needed
// This is a workaround for switching to a non AC3 track when the user wants audio transcoded to AC3
if (preferences.appPreferences.experimentalPreferences.preferAc3Surround && audioIndex != null) {
currentPlayback.mediaSourceInfo.mediaStreams
.orEmpty()
.firstOrNull { it.index == audioIndex }
?.let {
if (it.channels.gt(2) && it.codec != Codec.Audio.AC3) {
// User wants to transcode audio into AC3
return@withContext false
}
}
}
val source = currentPlayback.mediaSourceInfo
val externalSubtitle = source.findExternalSubtitle(subtitleIndex)
// TODO there's probably no reason why we can't add external subtitles?
if (externalSubtitle == null) {
val result =
withContext(WholphinDispatchers.Main) {

View file

@ -621,7 +621,7 @@ fun PreferencesContent(
value = value,
onNavigate = viewModel.navigationManager::navigateTo,
onValueChange = { newValue ->
val validation = pref.validate(newValue)
val validation = pref.validate(preferences, newValue)
when (validation) {
is PreferenceValidation.Invalid -> {
// TODO?

View file

@ -162,7 +162,7 @@ fun SubtitlePreferencesContent(
value = value,
onNavigate = viewModel.navigationManager::navigateTo,
onValueChange = { newValue ->
val validation = pref.validate(newValue)
val validation = pref.validate(preferences, newValue)
when (validation) {
is PreferenceValidation.Invalid -> {
// TODO?