Skip to content

Commit

Permalink
fix: inspect estimated per track bitrate
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjl-mux committed May 28, 2024
1 parent 9900fd7 commit cad4e8c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Sources/MuxUploadSDK/InputInspection/UploadInputInspector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ class AVFoundationUploadInputInspector: UploadInputInspector {
track.loadValuesAsynchronously(
forKeys: [
"formatDescriptions",
"nominalFrameRate"
"nominalFrameRate",
"estimatedDataRate"
]
) {
var nonStandardReasons: [UploadInputFormatInspectionResult.NonstandardInputReason] = []

guard let formatDescriptions = track.formatDescriptions as? [CMFormatDescription] else {
completionHandler(
nil,
Expand All @@ -128,8 +131,6 @@ class AVFoundationUploadInputInspector: UploadInputInspector {
return
}

var nonStandardReasons: [UploadInputFormatInspectionResult.NonstandardInputReason] = []

let videoDimensions = CMVideoFormatDescriptionGetDimensions(
formatDescription
)
Expand Down Expand Up @@ -157,6 +158,19 @@ class AVFoundationUploadInputInspector: UploadInputInspector {
nonStandardReasons.append(.videoFrameRate)
}
}

let estimatedBitrate = track.estimatedDataRate

if max(videoDimensions.width, videoDimensions.height) > 1920 {
if estimatedBitrate > 40_000_000 {
nonStandardReasons.append(.videoBitrate)
}
} else {
if estimatedBitrate > 16_000_000 {
nonStandardReasons.append(.videoBitrate)
}
}

completionHandler(
UploadInputFormatInspectionResult(
nonStandardInputReasons: nonStandardReasons,
Expand Down

0 comments on commit cad4e8c

Please sign in to comment.