Skip to content

Commit

Permalink
fix: further delineate between selected and default audio streams for…
Browse files Browse the repository at this point in the history
… plex
  • Loading branch information
chrisbenincasa committed Dec 27, 2024
1 parent 1a8afb6 commit 43f9ffc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
9 changes: 3 additions & 6 deletions server/src/ffmpeg/FfmpegStreamFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,10 @@ export class FfmpegStreamFactory extends IFFMPEG {

let audioInput: AudioInputSource;
if (isDefined(streamDetails.audioDetails)) {
// Just pick the first one for now..
const defaultAudioStream = find(
streamDetails.audioDetails,
(stream) => !!stream.default,
);
const audioStream =
defaultAudioStream ?? first(streamDetails.audioDetails);
find(streamDetails.audioDetails, { selected: true }) ??
find(streamDetails.audioDetails, { default: true }) ??
first(streamDetails.audioDetails);
const audioStreamIndex = isNonEmptyString(audioStream.index)
? parseInt(audioStream.index)
: 1;
Expand Down
15 changes: 13 additions & 2 deletions server/src/ffmpeg/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ import { FfmpegSettings, Resolution, Watermark } from '@tunarr/types';
import { NvidiaHardwareCapabilitiesFactory } from '@/ffmpeg/builder/capabilities/NvidiaHardwareCapabilitiesFactory.ts';
import dayjs from 'dayjs';
import { Duration } from 'dayjs/plugin/duration.js';
import { first, isEmpty, isNil, isUndefined, merge, round } from 'lodash-es';
import {
find,
first,
isEmpty,
isNil,
isUndefined,
merge,
round,
} from 'lodash-es';
import path from 'path';
import { DeepReadonly, DeepRequired } from 'ts-essentials';
import {
Expand Down Expand Up @@ -437,7 +445,10 @@ export class FFMPEG implements IFFMPEG {
];

const videoStream = first(streamStats?.videoDetails);
const audioStream = first(streamStats?.audioDetails);
const audioStream =
find(streamStats?.audioDetails, { selected: true }) ??
find(streamStats?.audioDetails, { default: true }) ??
first(streamStats?.audioDetails);

// Initialize like this because we're not checking whether or not
// the input is hardware decodeable, yet.
Expand Down
19 changes: 16 additions & 3 deletions server/src/stream/plex/PlexStreamDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,27 @@ export class PlexStreamDetails {
streamIndex: videoStream.index?.toString() ?? '0',
} satisfies VideoStreamDetails;
}

console.log(
sortBy(
filter(mediaStreams, (stream): stream is PlexMediaAudioStream => {
return stream.streamType === 2;
}),
(stream) => [
stream.selected ? -1 : 0,
stream.default ? 0 : 1,
stream.index,
],
),
);
const audioStreamDetails = map(
sortBy(
filter(mediaStreams, (stream): stream is PlexMediaAudioStream => {
return stream.streamType === 2;
}),
(stream) => [
stream.selected ? -1 : 0,
stream.default ? 0 : 1,
stream.index,
!(stream.selected ?? stream.default ?? false),
],
),
(audioStream) => {
Expand All @@ -325,7 +337,8 @@ export class PlexStreamDetails {
// this stream over others, even if it is not the default
// This is temporary until we have language preferences within Tunarr
// to pick these streams.
default: audioStream.selected ?? audioStream.default,
selected: audioStream.selected,
default: audioStream.default,
language: audioStream.languageCode,
title: audioStream.displayTitle,
} satisfies AudioStreamDetails;
Expand Down
1 change: 1 addition & 0 deletions server/src/stream/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type AudioStreamDetails = {
bitrate?: number;
profile?: string;
default?: boolean;
selected?: boolean;
title?: string;
language?: string;
forced?: boolean;
Expand Down

0 comments on commit 43f9ffc

Please sign in to comment.