fix(player): keep 4K HEVC playback off the software encoder
Continuous Integration / build_web (push) Failing after 1s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 1s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Use an HLS fMP4 profile that copies compatible HEVC video and transcodes only the audio, so servers without hardware acceleration no longer stall on a 4K H.264 transcode. Add an auto/1080p/720p/480p quality selector and restart playback at the same position when the profile changes.
This commit is contained in:
1 parent
a390df82e9
commit
c2ec314b39
7 files changed
+491
-38
No files matched your search
+107
-4
@@ -21,14 +21,19 @@ import { secToTicks, ticksToSec } from "../date/time";
|
||||
import getSubtitle from "../methods/getSubtitles";
|
||||
import { addSegmentsFromChapters } from "../methods/mediaSegments";
|
||||
import { markLocalMediaSwitch } from "../methods/mediaSwitch";
|
||||
import playbackProfile from "../playback-profiles";
|
||||
import {
|
||||
getVideoPlaybackProfile,
|
||||
setVideoPlaybackQuality,
|
||||
} from "../playback-profiles";
|
||||
import {
|
||||
getPlayerMuted,
|
||||
getPlayerVolume,
|
||||
setPlaybackQuality,
|
||||
setPlayerMuted,
|
||||
setPlayerVolume,
|
||||
} from "../storage/player";
|
||||
import type audioPlaybackInfo from "../types/audioPlaybackInfo";
|
||||
import type { PlaybackQualityPreset } from "../types/playbackQuality";
|
||||
import type subtitlePlaybackInfo from "../types/subtitlePlaybackInfo";
|
||||
import {
|
||||
generateAudioStreamUrl,
|
||||
@@ -702,6 +707,7 @@ export const playItem = (args: {
|
||||
state.userId = args.userId;
|
||||
state.playerState.isPlayerPlaying = true;
|
||||
state.playerState.isPlayerReady = false; // Reset player ready state
|
||||
state.playerState.isBuffering = true;
|
||||
});
|
||||
|
||||
setQueue(args.queueItems, args.queueItemIndex ?? 0);
|
||||
@@ -884,6 +890,75 @@ export const initializePlayback = async (args: {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Restarts the current video with another quality preset while keeping the
|
||||
* playback position, audio and subtitle selection.
|
||||
*/
|
||||
export const changePlaybackQuality = async (
|
||||
quality: PlaybackQualityPreset,
|
||||
api: Api,
|
||||
) => {
|
||||
const state = usePlaybackStore.getState();
|
||||
const item = state.metadata.item;
|
||||
const userId = state.userId;
|
||||
if (!api || !item?.Id || !userId) return;
|
||||
|
||||
const positionTicks = state.playerState.currentTime ?? 0;
|
||||
const wasPlaying = state.playerState.isPlayerPlaying;
|
||||
|
||||
setVideoPlaybackQuality(quality);
|
||||
await setPlaybackQuality(quality);
|
||||
|
||||
const { data } = await getMediaInfoApi(api).getPostedPlaybackInfo({
|
||||
itemId: item.Id,
|
||||
userId,
|
||||
mediaSourceId: state.mediaSource.id,
|
||||
startTimeTicks: positionTicks,
|
||||
audioStreamIndex: state.mediaSource.audio.track,
|
||||
subtitleStreamIndex: state.mediaSource.subtitle.track,
|
||||
playbackInfoDto: {
|
||||
DeviceProfile: await getVideoPlaybackProfile(
|
||||
state.mediaSource.videoCodec,
|
||||
),
|
||||
},
|
||||
});
|
||||
|
||||
// The old transcode must be stopped before the new one starts, otherwise
|
||||
// both continue to consume server CPU.
|
||||
await getSessionApi(api)
|
||||
.reportPlaybackStopped({
|
||||
playbackStopInfo: {
|
||||
Failed: false,
|
||||
ItemId: item.Id,
|
||||
MediaSourceId: state.mediaSource.id,
|
||||
PlaySessionId: state.playsessionId,
|
||||
PositionTicks: positionTicks,
|
||||
},
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn("Не удалось остановить прошлую сессию", error);
|
||||
});
|
||||
|
||||
await initializePlayback({
|
||||
api,
|
||||
userId,
|
||||
item,
|
||||
mediaSource: data,
|
||||
mediaSegments: state.metadata.mediaSegments,
|
||||
queueItems: useQueue.getState().tracks ?? [],
|
||||
queueIndex: useQueue.getState().currentItemIndex,
|
||||
startPositionTicks: positionTicks,
|
||||
audioStreamIndex: state.mediaSource.audio.track,
|
||||
subtitleStreamIndex: state.mediaSource.subtitle.track,
|
||||
});
|
||||
|
||||
if (!wasPlaying) {
|
||||
usePlaybackStore.setState((next) => {
|
||||
next.playerState.isPlayerPlaying = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const playItemFromQueue = async (
|
||||
index: "next" | "previous" | number,
|
||||
userId: string | undefined,
|
||||
@@ -949,6 +1024,10 @@ export const playItemFromQueue = async (
|
||||
? prevMediaSource.subtitle.track
|
||||
: (item?.MediaSources?.[0]?.DefaultSubtitleStreamIndex ?? -1);
|
||||
|
||||
const sourceVideoCodec = item.MediaSources?.[0]?.MediaStreams?.find(
|
||||
(stream) => stream.Type === "Video",
|
||||
)?.Codec;
|
||||
|
||||
// Prepare promises for parallel execution
|
||||
const playbackInfoPromise = getMediaInfoApi(api).getPostedPlaybackInfo({
|
||||
audioStreamIndex,
|
||||
@@ -958,7 +1037,7 @@ export const playItemFromQueue = async (
|
||||
userId: userId,
|
||||
mediaSourceId: mediaSourceId,
|
||||
playbackInfoDto: {
|
||||
DeviceProfile: playbackProfile,
|
||||
DeviceProfile: await getVideoPlaybackProfile(sourceVideoCodec),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1059,16 +1138,22 @@ export const changeAudioTrack = async (trackIndex: number, api: Api) => {
|
||||
if (!prevState.metadata.item.MediaSources?.[0].Id) {
|
||||
throw new Error("Media source id is undefined in changeAudioTrack");
|
||||
}
|
||||
const positionTicks =
|
||||
prevState.playerState.currentTime ??
|
||||
prevState.metadata.item.UserData?.PlaybackPositionTicks ??
|
||||
0;
|
||||
const mediaSource = (
|
||||
await getMediaInfoApi(api).getPostedPlaybackInfo({
|
||||
audioStreamIndex: trackIndex,
|
||||
subtitleStreamIndex: prevState.mediaSource.subtitle.track,
|
||||
itemId: prevState.metadata.item.Id,
|
||||
startTimeTicks: prevState.metadata.item.UserData?.PlaybackPositionTicks,
|
||||
startTimeTicks: positionTicks,
|
||||
userId: prevState.userId,
|
||||
mediaSourceId: prevState.metadata.item.MediaSources?.[0].Id,
|
||||
playbackInfoDto: {
|
||||
DeviceProfile: playbackProfile,
|
||||
DeviceProfile: await getVideoPlaybackProfile(
|
||||
prevState.mediaSource.videoCodec,
|
||||
),
|
||||
},
|
||||
})
|
||||
).data;
|
||||
@@ -1091,12 +1176,30 @@ export const changeAudioTrack = async (trackIndex: number, api: Api) => {
|
||||
playbackUrl = `${api.basePath}${mediaSource.MediaSources[0].TranscodingUrl}`;
|
||||
}
|
||||
|
||||
await getSessionApi(api)
|
||||
.reportPlaybackStopped({
|
||||
playbackStopInfo: {
|
||||
Failed: false,
|
||||
ItemId: prevState.metadata.item.Id,
|
||||
MediaSourceId: prevState.mediaSource.id,
|
||||
PlaySessionId: prevState.playsessionId,
|
||||
PositionTicks: positionTicks,
|
||||
},
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn("Не удалось остановить прошлую сессию", error);
|
||||
});
|
||||
|
||||
usePlaybackStore.setState((state) => {
|
||||
state.mediaSource.audio.track = trackIndex;
|
||||
state.mediaSource.id = mediaSource.MediaSources?.[0].Id ?? "";
|
||||
state.mediaSource.container = mediaSource.MediaSources?.[0].Container ?? "";
|
||||
state.playbackStream = playbackUrl;
|
||||
state.playsessionId = mediaSource.PlaySessionId;
|
||||
state.metadata.userDataLastPlayedPositionTicks = positionTicks;
|
||||
state.playerState.currentTime = positionTicks;
|
||||
state.playerState.isPlayerReady = false;
|
||||
state.playerState.isBuffering = true;
|
||||
});
|
||||
// const currentItemIndex = useQueue.getState().currentItemIndex;
|
||||
// playItemFromQueue(currentItemIndex, prevState.userId, api);
|
||||
|
||||
Reference in new issue
Block a user