diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-10 09:50:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-10 09:50:38 +0200 |
commit | 0b755f3b27190ea4d9c301ede0955b2736605f4c (patch) | |
tree | 13a2b7dcfa0037c4fde33c8d5bdf2eee8f097279 /client/src/assets/player | |
parent | 602a81a2137afcb5ca12341329199fbea2f08bd8 (diff) | |
download | PeerTube-0b755f3b27190ea4d9c301ede0955b2736605f4c.tar.gz PeerTube-0b755f3b27190ea4d9c301ede0955b2736605f4c.tar.zst PeerTube-0b755f3b27190ea4d9c301ede0955b2736605f4c.zip |
Fix video resolution limit
Diffstat (limited to 'client/src/assets/player')
-rw-r--r-- | client/src/assets/player/peertube-videojs-plugin.ts | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index 936fb2577..57c894ee6 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts | |||
@@ -367,19 +367,34 @@ class PeerTubePlugin extends Plugin { | |||
367 | 367 | ||
368 | if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed() | 368 | if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed() |
369 | 369 | ||
370 | // Filter videos we can play according to our screen resolution and bandwidth | 370 | // Limit resolution according to player height |
371 | const filteredFiles = this.videoFiles.filter(f => f.resolution.id <= this.playerElement.width) | 371 | const playerHeight = this.playerElement.offsetHeight as number |
372 | .filter(f => { | 372 | |
373 | const fileBitrate = (f.size / this.videoDuration) | 373 | // We take the first resolution just above the player height |
374 | let threshold = fileBitrate | 374 | // Example: player height is 530px, we want the 720p file instead of 480p |
375 | 375 | let maxResolution = this.videoFiles[0].resolution.id | |
376 | // If this is for a higher resolution or an initial load: add a margin | 376 | for (let i = this.videoFiles.length - 1; i >= 0; i--) { |
377 | if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) { | 377 | const resolutionId = this.videoFiles[i].resolution.id |
378 | threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100) | 378 | if (resolutionId >= playerHeight) { |
379 | maxResolution = resolutionId | ||
380 | break | ||
379 | } | 381 | } |
382 | } | ||
380 | 383 | ||
381 | return averageDownloadSpeed > threshold | 384 | // Filter videos we can play according to our screen resolution and bandwidth |
382 | }) | 385 | const filteredFiles = this.videoFiles |
386 | .filter(f => f.resolution.id <= maxResolution) | ||
387 | .filter(f => { | ||
388 | const fileBitrate = (f.size / this.videoDuration) | ||
389 | let threshold = fileBitrate | ||
390 | |||
391 | // If this is for a higher resolution or an initial load: add a margin | ||
392 | if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) { | ||
393 | threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100) | ||
394 | } | ||
395 | |||
396 | return averageDownloadSpeed > threshold | ||
397 | }) | ||
383 | 398 | ||
384 | // If the download speed is too bad, return the lowest resolution we have | 399 | // If the download speed is too bad, return the lowest resolution we have |
385 | if (filteredFiles.length === 0) return videoFileMinByResolution(this.videoFiles) | 400 | if (filteredFiles.length === 0) return videoFileMinByResolution(this.videoFiles) |