mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 23:59:08 +00:00
fix(vlc): add audio transcoding mode to fix 7.1 TrueHD playback
This commit is contained in:
@@ -7,12 +7,23 @@ import { Platform } from "react-native";
|
||||
import MediaTypes from "../../constants/MediaTypes";
|
||||
import { getSubtitleProfiles } from "./subtitles";
|
||||
|
||||
/**
|
||||
* @typedef {"ios" | "android"} PlatformType
|
||||
* @typedef {"vlc" | "ksplayer"} PlayerType
|
||||
* @typedef {"auto" | "stereo" | "5.1" | "passthrough"} AudioTranscodeModeType
|
||||
*
|
||||
* @typedef {Object} ProfileOptions
|
||||
* @property {PlatformType} [platform] - Target platform
|
||||
* @property {PlayerType} [player] - Video player being used
|
||||
* @property {AudioTranscodeModeType} [audioMode] - Audio transcoding mode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Audio profiles for react-native-track-player based on platform capabilities.
|
||||
* iOS uses AVPlayer, Android uses ExoPlayer - each has different codec support.
|
||||
*/
|
||||
const getAudioDirectPlayProfile = () => {
|
||||
if (Platform.OS === "ios") {
|
||||
const getAudioDirectPlayProfile = (platform) => {
|
||||
if (platform === "ios") {
|
||||
// iOS AVPlayer supported formats
|
||||
return {
|
||||
Type: MediaTypes.Audio,
|
||||
@@ -29,8 +40,8 @@ const getAudioDirectPlayProfile = () => {
|
||||
};
|
||||
};
|
||||
|
||||
const getAudioCodecProfile = () => {
|
||||
if (Platform.OS === "ios") {
|
||||
const getAudioCodecProfile = (platform) => {
|
||||
if (platform === "ios") {
|
||||
// iOS AVPlayer codec constraints
|
||||
return {
|
||||
Type: MediaTypes.Audio,
|
||||
@@ -45,12 +56,99 @@ const getAudioCodecProfile = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const generateDeviceProfile = () => {
|
||||
/**
|
||||
* Gets the video audio codec configuration based on platform, player, and audio mode.
|
||||
*
|
||||
* Key insight: VLC handles AC3/EAC3/DTS downmixing fine.
|
||||
* Only TrueHD and DTS-HD MA (lossless 7.1) cause issues on mobile devices
|
||||
* because VLC's internal downmixing from 7.1 to stereo fails on some Android audio pipelines.
|
||||
*
|
||||
* @param {PlatformType} platform
|
||||
* @param {PlayerType} player
|
||||
* @param {AudioTranscodeModeType} audioMode
|
||||
* @returns {{ directPlayCodec: string, maxAudioChannels: string }}
|
||||
*/
|
||||
const getVideoAudioCodecs = (platform, player, audioMode) => {
|
||||
// Base codecs that work everywhere
|
||||
const baseCodecs = "aac,mp3,flac,opus,vorbis";
|
||||
|
||||
// Surround codecs that VLC handles well (downmixes properly)
|
||||
const surroundCodecs = "ac3,eac3,dts";
|
||||
|
||||
// Lossless HD codecs that cause issues with VLC's downmixing on mobile
|
||||
const losslessHdCodecs = "truehd";
|
||||
|
||||
// Platform-specific codecs
|
||||
const platformCodecs = platform === "ios" ? "alac,wma" : "wma";
|
||||
|
||||
// Handle explicit user settings first
|
||||
switch (audioMode) {
|
||||
case "stereo":
|
||||
// Force stereo transcoding - only allow basic codecs
|
||||
return {
|
||||
directPlayCodec: `${baseCodecs},${platformCodecs}`,
|
||||
maxAudioChannels: "2",
|
||||
};
|
||||
|
||||
case "5.1":
|
||||
// Allow up to 5.1 - include surround codecs but not lossless HD
|
||||
return {
|
||||
directPlayCodec: `${baseCodecs},${surroundCodecs},${platformCodecs}`,
|
||||
maxAudioChannels: "6",
|
||||
};
|
||||
|
||||
case "passthrough":
|
||||
// Allow all codecs - for users with external DAC/receiver
|
||||
return {
|
||||
directPlayCodec: `${baseCodecs},${surroundCodecs},${losslessHdCodecs},${platformCodecs}`,
|
||||
maxAudioChannels: "8",
|
||||
};
|
||||
default:
|
||||
// Auto mode: platform and player-specific defaults
|
||||
break;
|
||||
}
|
||||
|
||||
// Auto mode logic based on platform and player
|
||||
if (player === "ksplayer" && platform === "ios") {
|
||||
// KSPlayer on iOS handles all codecs well, including TrueHD
|
||||
return {
|
||||
directPlayCodec: `${baseCodecs},${surroundCodecs},${losslessHdCodecs},${platformCodecs}`,
|
||||
maxAudioChannels: "8",
|
||||
};
|
||||
}
|
||||
|
||||
// VLC on Android or iOS - don't include TrueHD (causes 7.1 downmix issues)
|
||||
// DTS core is fine, VLC handles it well. Only lossless 7.1 formats are problematic.
|
||||
return {
|
||||
directPlayCodec: `${baseCodecs},${surroundCodecs},${platformCodecs}`,
|
||||
maxAudioChannels: "6",
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates a device profile for Jellyfin playback.
|
||||
*
|
||||
* @param {ProfileOptions} [options] - Profile configuration options
|
||||
* @returns {Object} Jellyfin device profile
|
||||
*/
|
||||
export const generateDeviceProfile = (options = {}) => {
|
||||
const platform = options.platform || Platform.OS;
|
||||
const player = options.player || "vlc";
|
||||
const audioMode = options.audioMode || "auto";
|
||||
|
||||
const { directPlayCodec, maxAudioChannels } = getVideoAudioCodecs(
|
||||
platform,
|
||||
player,
|
||||
audioMode,
|
||||
);
|
||||
|
||||
const playerName = player === "ksplayer" ? "KSPlayer" : "VLC Player";
|
||||
|
||||
/**
|
||||
* Device profile for Native video player
|
||||
*/
|
||||
const profile = {
|
||||
Name: `1. MPV Player`,
|
||||
Name: `1. ${playerName}`,
|
||||
MaxStaticBitrate: 999_999_999,
|
||||
MaxStreamingBitrate: 999_999_999,
|
||||
CodecProfiles: [
|
||||
@@ -76,7 +174,7 @@ export const generateDeviceProfile = () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
getAudioCodecProfile(),
|
||||
getAudioCodecProfile(platform),
|
||||
],
|
||||
DirectPlayProfiles: [
|
||||
{
|
||||
@@ -84,9 +182,9 @@ export const generateDeviceProfile = () => {
|
||||
Container: "mp4,mkv,avi,mov,flv,ts,m2ts,webm,ogv,3gp,hls",
|
||||
VideoCodec:
|
||||
"h264,hevc,mpeg4,divx,xvid,wmv,vc1,vp8,vp9,av1,avi,mpeg,mpeg2video",
|
||||
AudioCodec: "aac,ac3,eac3,mp3,flac,alac,opus,vorbis,wma,dts,truehd",
|
||||
AudioCodec: directPlayCodec,
|
||||
},
|
||||
getAudioDirectPlayProfile(),
|
||||
getAudioDirectPlayProfile(platform),
|
||||
],
|
||||
TranscodingProfiles: [
|
||||
{
|
||||
@@ -96,6 +194,7 @@ export const generateDeviceProfile = () => {
|
||||
Container: "ts",
|
||||
VideoCodec: "h264, hevc",
|
||||
AudioCodec: "aac,mp3,ac3,dts",
|
||||
MaxAudioChannels: maxAudioChannels,
|
||||
},
|
||||
{
|
||||
Type: MediaTypes.Audio,
|
||||
|
||||
Reference in New Issue
Block a user