From 266be726065d286414bf449edd5a895ec91e6ac7 Mon Sep 17 00:00:00 2001 From: Roman Sokolov <12689+vityevato@users.noreply.github.com> Date: Mon, 28 Apr 2025 00:04:00 +0300 Subject: [PATCH] Fixed an issue for some devices. They send screen width as not even value. (#1797) --- plugins/webrtc/package.json | 2 +- plugins/webrtc/src/ffmpeg-to-wrtc.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/webrtc/package.json b/plugins/webrtc/package.json index 4d857b454..03439b087 100644 --- a/plugins/webrtc/package.json +++ b/plugins/webrtc/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/webrtc", - "version": "0.2.77", + "version": "0.2.78", "scripts": { "scrypted-setup-project": "scrypted-setup-project", "prescrypted-setup-project": "scrypted-package-json", diff --git a/plugins/webrtc/src/ffmpeg-to-wrtc.ts b/plugins/webrtc/src/ffmpeg-to-wrtc.ts index ea2334b93..01ba416f2 100644 --- a/plugins/webrtc/src/ffmpeg-to-wrtc.ts +++ b/plugins/webrtc/src/ffmpeg-to-wrtc.ts @@ -458,7 +458,13 @@ export function parseOptions(options: RTCSignalingOptions) { if (options?.userAgent?.includes('Firefox/')) sessionSupportsH264High = true; - const transcodeWidth = Math.max(640, Math.min(options?.screen?.width || 960, 1280)); + // Some devices return a `screen width` value that is not a multiple of 2, which is not allowed for the h264 codec. + // Convert to a smaller even value. + const screenWidthForTranscodeH264 = !options?.screen?.width + ? 960 + : Math.trunc(options?.screen?.width / 2) * 2; + + const transcodeWidth = Math.max(640, Math.min(screenWidthForTranscodeH264, 1280)); const devicePixelRatio = options?.screen?.devicePixelRatio || 1; const width = (options?.screen?.width * devicePixelRatio) || undefined; const height = (options?.screen?.height * devicePixelRatio) || undefined;