mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-10 10:33:11 +03:00
add util for optimal detect resolution
This commit is contained in:
parent
c4a5ac0e77
commit
cd498a6cb2
@ -115,6 +115,47 @@ export type CameraAudioFeatures = {
|
|||||||
* @param requireSecureContext - If true, two-way audio requires secure context (default: true)
|
* @param requireSecureContext - If true, two-way audio requires secure context (default: true)
|
||||||
* @returns CameraAudioFeatures object with detected capabilities
|
* @returns CameraAudioFeatures object with detected capabilities
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* Calculates optimal detect dimensions from stream resolution.
|
||||||
|
*
|
||||||
|
* Scales dimensions to an efficient size for object detection while
|
||||||
|
* preserving the stream's aspect ratio. Does not upscale.
|
||||||
|
*
|
||||||
|
* @param streamWidth - Native stream width in pixels
|
||||||
|
* @param streamHeight - Native stream height in pixels
|
||||||
|
* @returns Detect dimensions with even values, or null if inputs are invalid
|
||||||
|
*/
|
||||||
|
export function calculateDetectDimensions(
|
||||||
|
streamWidth: number,
|
||||||
|
streamHeight: number,
|
||||||
|
): { width: number; height: number } | null {
|
||||||
|
if (
|
||||||
|
!Number.isFinite(streamWidth) ||
|
||||||
|
!Number.isFinite(streamHeight) ||
|
||||||
|
streamWidth <= 0 ||
|
||||||
|
streamHeight <= 0
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const smallerDim = Math.min(streamWidth, streamHeight);
|
||||||
|
const target = Math.min(720, smallerDim);
|
||||||
|
const scale = target / smallerDim;
|
||||||
|
|
||||||
|
let width = Math.round(streamWidth * scale);
|
||||||
|
let height = Math.round(streamHeight * scale);
|
||||||
|
|
||||||
|
// Round down to even numbers (required for video processing)
|
||||||
|
width = width - (width % 2);
|
||||||
|
height = height - (height % 2);
|
||||||
|
|
||||||
|
if (width < 2 || height < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { width, height };
|
||||||
|
}
|
||||||
|
|
||||||
export function detectCameraAudioFeatures(
|
export function detectCameraAudioFeatures(
|
||||||
metadata: LiveStreamMetadata | null | undefined,
|
metadata: LiveStreamMetadata | null | undefined,
|
||||||
requireSecureContext: boolean = true,
|
requireSecureContext: boolean = true,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user