Fix video resolution limit
This commit is contained in:
parent
602a81a213
commit
0b755f3b27
1 changed files with 25 additions and 10 deletions
|
@ -367,19 +367,34 @@ class PeerTubePlugin extends Plugin {
|
||||||
|
|
||||||
if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed()
|
if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed()
|
||||||
|
|
||||||
// Filter videos we can play according to our screen resolution and bandwidth
|
// Limit resolution according to player height
|
||||||
const filteredFiles = this.videoFiles.filter(f => f.resolution.id <= this.playerElement.width)
|
const playerHeight = this.playerElement.offsetHeight as number
|
||||||
.filter(f => {
|
|
||||||
const fileBitrate = (f.size / this.videoDuration)
|
|
||||||
let threshold = fileBitrate
|
|
||||||
|
|
||||||
// If this is for a higher resolution or an initial load: add a margin
|
// We take the first resolution just above the player height
|
||||||
if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) {
|
// Example: player height is 530px, we want the 720p file instead of 480p
|
||||||
threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100)
|
let maxResolution = this.videoFiles[0].resolution.id
|
||||||
|
for (let i = this.videoFiles.length - 1; i >= 0; i--) {
|
||||||
|
const resolutionId = this.videoFiles[i].resolution.id
|
||||||
|
if (resolutionId >= playerHeight) {
|
||||||
|
maxResolution = resolutionId
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return averageDownloadSpeed > threshold
|
// Filter videos we can play according to our screen resolution and bandwidth
|
||||||
})
|
const filteredFiles = this.videoFiles
|
||||||
|
.filter(f => f.resolution.id <= maxResolution)
|
||||||
|
.filter(f => {
|
||||||
|
const fileBitrate = (f.size / this.videoDuration)
|
||||||
|
let threshold = fileBitrate
|
||||||
|
|
||||||
|
// If this is for a higher resolution or an initial load: add a margin
|
||||||
|
if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) {
|
||||||
|
threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
return averageDownloadSpeed > threshold
|
||||||
|
})
|
||||||
|
|
||||||
// If the download speed is too bad, return the lowest resolution we have
|
// If the download speed is too bad, return the lowest resolution we have
|
||||||
if (filteredFiles.length === 0) return videoFileMinByResolution(this.videoFiles)
|
if (filteredFiles.length === 0) return videoFileMinByResolution(this.videoFiles)
|
||||||
|
|
Loading…
Add table
Reference in a new issue