From 92e0f42e8ce5f1ab5e4023900b8194627231a11b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 11 Dec 2019 09:51:17 +0100 Subject: Don't use the max quality file when transcoding to a new resolution --- server/models/video/video.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'server/models/video/video.ts') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 73e0d2345..af6fae0b6 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1,5 +1,5 @@ import * as Bluebird from 'bluebird' -import { maxBy } from 'lodash' +import { maxBy, minBy } from 'lodash' import { join } from 'path' import { CountOptions, @@ -1802,9 +1802,9 @@ export class VideoModel extends Model { this.VideoChannel.Account.isBlocked() } - getMaxQualityFile (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo { + getQualityFileBy (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) { if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) { - const file = maxBy(this.VideoFiles, file => file.resolution) + const file = fun(this.VideoFiles, file => file.resolution) return Object.assign(file, { Video: this }) } @@ -1813,13 +1813,21 @@ export class VideoModel extends Model { if (Array.isArray(this.VideoStreamingPlaylists) && this.VideoStreamingPlaylists.length !== 0) { const streamingPlaylistWithVideo = Object.assign(this.VideoStreamingPlaylists[0], { Video: this }) - const file = maxBy(streamingPlaylistWithVideo.VideoFiles, file => file.resolution) + const file = fun(streamingPlaylistWithVideo.VideoFiles, file => file.resolution) return Object.assign(file, { VideoStreamingPlaylist: streamingPlaylistWithVideo }) } return undefined } + getMaxQualityFile (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo { + return this.getQualityFileBy(maxBy) + } + + getMinQualityFile (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo { + return this.getQualityFileBy(minBy) + } + getWebTorrentFile (this: T, resolution: number): MVideoFileVideo { if (Array.isArray(this.VideoFiles) === false) return undefined -- cgit v1.2.3