ActivityPub-federated video streaming platform using P2P directly in your web browser
Generate more video thumbnail sizes
Chocobozzz34dfb2aff47e
diff --git a/client/src/app/+videos-publish-manage/shared-manage/video-manage-container.component.ts b/client/src/app/+videos-publish-manage/shared-manage/video-manage-container.component.tsindex 94a51c9a61..42fde21bc0 100644--- a/client/src/app/+videos-publish-manage/shared-manage/video-manage-container.component.ts+++ b/client/src/app/+videos-publish-manage/shared-manage/video-manage-container.component.ts@@ -4,7 +4,6 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'import { RouterModule } from '@angular/router'import { Notifier, ScreenService } from '@app/core'import { HeaderService } from '@app/header/header.service'-import { AlertComponent } from '@app/shared/shared-main/common/alert.component'import { Video } from '@app/shared/shared-main/video/video.model'import { VideoStateMessageService } from '@app/shared/shared-video/video-state-message.service'import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'@@ -27,8 +26,7 @@ import { VideoManageMenuComponent } from './video-manage-menu.component'ManageErrorsComponent,NgbTooltipModule,UploadProgressComponent,- VideoManageMenuComponent,- AlertComponent+ VideoManageMenuComponent]})export class VideoManageContainerComponent implements OnInit, OnDestroy {diff --git a/client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts b/client/src/app/shared/shared-thumbnail/video-thumbnail.component.tsindex e13d48decc..6b2aa3fcd6 100644--- a/client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts+++ b/client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts@@ -3,7 +3,7 @@ import { booleanAttribute, Component, ElementRef, inject, input, numberAttributeimport { RouterLink } from '@angular/router'import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap'import { Video as VideoServerModel, VideoState } from '@peertube/peertube-models'-import { findAppropriateImageFileUrl } from '@root-helpers/images'+import { findAppropriateThumbnailFileUrl } from '@root-helpers/images'import { logger } from '@root-helpers/logger'import { GlobalIconComponent } from '../shared-icons/global-icon.component'import { FromNowPipe } from '../shared-main/date/from-now.pipe'@@ -119,7 +119,7 @@ export class VideoThumbnailComponent implements OnChanges {width = +widthStr}- return findAppropriateImageFileUrl(video.thumbnails, width)+ return findAppropriateThumbnailFileUrl(video.thumbnails, width, '16:9')}getProgressPercent () {diff --git a/client/src/app/shared/shared-video-playlist/video-playlist.model.ts b/client/src/app/shared/shared-video-playlist/video-playlist.model.tsindex 005b65a01d..5710056205 100644--- a/client/src/app/shared/shared-video-playlist/video-playlist.model.ts+++ b/client/src/app/shared/shared-video-playlist/video-playlist.model.ts@@ -10,7 +10,7 @@ import {VideoPlaylistType,VideoPlaylistType_Type} from '@peertube/peertube-models'-import { findAppropriateImageFileUrl } from '@root-helpers/images'+import { findAppropriateThumbnailFileUrl } from '@root-helpers/images'import { Actor } from '../shared-main/account/actor.model'export class VideoPlaylist implements ServerVideoPlaylist {@@ -99,6 +99,6 @@ export class VideoPlaylist implements ServerVideoPlaylist {getThumbnailUrl (width: number) {const defaultUrl = getAPIUrl() + '/client/assets/images/default-playlist.jpg'- return findAppropriateImageFileUrl(this.thumbnails, width) || defaultUrl+ return findAppropriateThumbnailFileUrl(this.thumbnails, width, '16:9') || defaultUrl}}diff --git a/client/src/root-helpers/images.ts b/client/src/root-helpers/images.tsindex adf378483a..1bd3a7664c 100644--- a/client/src/root-helpers/images.ts+++ b/client/src/root-helpers/images.ts@@ -1,4 +1,5 @@-import { findAppropriateImage } from '@peertube/peertube-core-utils'+import { findAppropriateImage, findAppropriateThumbnail } from '@peertube/peertube-core-utils'+import { ThumbnailAspectRatio } from '@peertube/peertube-models'import { logger } from './logger'export function imageToDataURL (input: File | Blob) {@@ -11,6 +12,17 @@ export function imageToDataURL (input: File | Blob) {})}-export function findAppropriateImageFileUrl<T extends { width: number, fileUrl: string }> (images: T[], width: number) {+export function findAppropriateThumbnailFileUrl<T extends { width: number, fileUrl: string, aspectRatio: ThumbnailAspectRatio }> (+ images: T[],+ width: number,+ ratio: ThumbnailAspectRatio+) {+ return findAppropriateThumbnail(images, width, ratio)?.fileUrl || ''+}++export function findAppropriateImageFileUrl<T extends { width: number, fileUrl: string }> (+ images: T[],+ width: number+) {return findAppropriateImage(images, width)?.fileUrl || ''}diff --git a/client/src/standalone/player/src/peertube-player.ts b/client/src/standalone/player/src/peertube-player.tsindex f947262eb4..036dc2afaa 100644--- a/client/src/standalone/player/src/peertube-player.ts+++ b/client/src/standalone/player/src/peertube-player.ts@@ -1,4 +1,4 @@-import { buildVideoLink, decorateVideoLink, findAppropriateImage, isDefaultLocale, pick } from '@peertube/peertube-core-utils'+import { buildVideoLink, decorateVideoLink, findAppropriateThumbnail, isDefaultLocale, pick } from '@peertube/peertube-core-utils'import { Thumbnail } from '@peertube/peertube-models'import { logger } from '@root-helpers/logger'import { PluginsManager } from '@root-helpers/plugins-manager'@@ -150,13 +150,17 @@ export class PeerTubePlayer {if (!this.player) {const playerEl = this.options.playerElement()- this.options.playerElement().poster = findAppropriateImage(thumbnails, playerEl.clientWidth || window.innerWidth)?.fileUrl || ''+ const width = playerEl.clientWidth || window.innerWidth++ this.options.playerElement().poster = findAppropriateThumbnail(thumbnails, width, '16:9')?.fileUrl || ''return}// Prefer using player poster APIif (this.player) {- this.player.poster(findAppropriateImage(thumbnails, this.player.el().clientWidth || window.innerWidth)?.fileUrl || '')+ const width = this.player.el().clientWidth || window.innerWidth++ this.player.poster(findAppropriateThumbnail(thumbnails, width, '16:9')?.fileUrl || '')}this.options.playerElement().poster = ''@@ -393,7 +397,7 @@ export class PeerTubePlayer {private getVideojsOptions (): VideojsPlayerOptions {const posterWidth = this.options.playerElement().clientWidth || window.innerWidth- const poster = findAppropriateImage(this.currentLoadOptions.thumbnails, posterWidth)?.fileUrl || ''+ const poster = findAppropriateThumbnail(this.currentLoadOptions.thumbnails, posterWidth, '16:9')?.fileUrl || ''const html5 = {preloadTextTracks: false,diff --git a/client/src/standalone/player/src/shared/playlist/playlist-menu-item.ts b/client/src/standalone/player/src/shared/playlist/playlist-menu-item.tsindex c32d75c558..d0a25426fb 100644--- a/client/src/standalone/player/src/shared/playlist/playlist-menu-item.ts+++ b/client/src/standalone/player/src/shared/playlist/playlist-menu-item.ts@@ -1,4 +1,4 @@-import { findAppropriateImage, secondsToTime } from '@peertube/peertube-core-utils'+import { findAppropriateThumbnail, secondsToTime } from '@peertube/peertube-core-utils'import { VideoPlaylistElement } from '@peertube/peertube-models'import videojs from 'video.js'import { PlaylistItemOptions, VideojsComponent, VideojsComponentOptions, VideojsPlayer } from '../../types'@@ -84,7 +84,7 @@ class PlaylistMenuItem extends Component {const thumbnail = super.createEl('img', {src: videoElement.video.thumbnails.length !== 0- ? window.location.origin + findAppropriateImage(videoElement.video.thumbnails, 80).fileUrl // Keep 80 in sync with CSS+ ? window.location.origin + findAppropriateThumbnail(videoElement.video.thumbnails, 80, '16:9').fileUrl // Keep 80 in sync with CSS: ''})diff --git a/config/default.yaml b/config/default.yamlindex 054aa65ab3..52864ce046 100644--- a/config/default.yaml+++ b/config/default.yaml@@ -502,10 +502,28 @@ thumbnails:-width: 280height: 157+ aspect_ratio: '16:9'-width: 850height: 480+ aspect_ratio: '16:9'++ -+ width: 1280+ height: 720+ aspect_ratio: '16:9'++ -+ width: 1920+ height: 1080+ aspect_ratio: '16:9'++ # For podcast applications+ -+ width: 1400+ height: 1400+ aspect_ratio: '1:1'stats:# Display registration requests stats (average response time, total requests...)diff --git a/packages/core-utils/src/common/image.ts b/packages/core-utils/src/common/image.tsindex 2eb9192cfe..dbf8233b43 100644--- a/packages/core-utils/src/common/image.ts+++ b/packages/core-utils/src/common/image.ts@@ -1,5 +1,17 @@+import { ThumbnailAspectRatio } from '@peertube/peertube-models'import { maxBy } from './array.js'+export function findAppropriateThumbnail<T extends { width: number, aspectRatio: ThumbnailAspectRatio }> (+ images: T[],+ wantedWidth: number,+ ratio: ThumbnailAspectRatio+) {+ return findAppropriateImage(+ images.filter(img => img.aspectRatio === ratio),+ wantedWidth+ )+}+export function findAppropriateImage<T extends { width: number }> (images: T[], wantedWidth: number) {if (!wantedWidth) throw new Error('Invalid width to find appropriate image')if (!images || images.length === 0) return undefined@@ -14,3 +26,14 @@ export function findAppropriateImage<T extends { width: number }> (images: T[],return candidate || maxBy(images, 'width')}++export function guessAspectRatio (width: number, height: number): ThumbnailAspectRatio {+ const ratio = width / height++ if (ratio >= 1.77) return '16:9'+ if (ratio >= 1.6) return '16:10'+ if (ratio >= 1.33) return '4:3'+ if (ratio >= 1.25) return '5:4'++ return '1:1'+}diff --git a/packages/models/src/videos/thumbnail/thumbnail.model.ts b/packages/models/src/videos/thumbnail/thumbnail.model.tsindex ac3d25cdd5..d3fdee4ba9 100644--- a/packages/models/src/videos/thumbnail/thumbnail.model.ts+++ b/packages/models/src/videos/thumbnail/thumbnail.model.ts@@ -1,6 +1,9 @@export interface Thumbnail {height: numberwidth: number+ aspectRatio: ThumbnailAspectRatiofileUrl: string}++export type ThumbnailAspectRatio = '16:9' | '16:10' | '4:3' | '5:4' | '1:1'diff --git a/packages/tests/fixtures/custom-thumbnail-1920x1080.jpg b/packages/tests/fixtures/custom-thumbnail-1920x1080.jpgnew file mode 100644index 0000000000..7132a7ad77Binary files /dev/null and b/packages/tests/fixtures/custom-thumbnail-1920x1080.jpg differdiff --git a/packages/tests/fixtures/custom-thumbnail-280x157.jpg b/packages/tests/fixtures/custom-thumbnail-280x157.jpgindex 50b3edb69a..639be3fed5 100644Binary files a/packages/tests/fixtures/custom-thumbnail-280x157.jpg and b/packages/tests/fixtures/custom-thumbnail-280x157.jpg differdiff --git a/packages/tests/fixtures/custom-thumbnail-850x480.jpg b/packages/tests/fixtures/custom-thumbnail-850x480.jpgindex a070c2bc50..d013f4947c 100644Binary files a/packages/tests/fixtures/custom-thumbnail-850x480.jpg and b/packages/tests/fixtures/custom-thumbnail-850x480.jpg differdiff --git a/packages/tests/fixtures/custom-thumbnail-input.jpg b/packages/tests/fixtures/custom-thumbnail-input.jpgnew file mode 100644index 0000000000..d013f4947cBinary files /dev/null and b/packages/tests/fixtures/custom-thumbnail-input.jpg differdiff --git a/packages/tests/fixtures/custom-thumbnail-user-import-280x157.jpg b/packages/tests/fixtures/custom-thumbnail-user-import-280x157.jpgnew file mode 100644index 0000000000..639be3fed5Binary files /dev/null and b/packages/tests/fixtures/custom-thumbnail-user-import-280x157.jpg differdiff --git a/packages/tests/fixtures/custom-thumbnail-user-import-850x480.jpg b/packages/tests/fixtures/custom-thumbnail-user-import-850x480.jpgnew file mode 100644index 0000000000..6d73587428Binary files /dev/null and b/packages/tests/fixtures/custom-thumbnail-user-import-850x480.jpg differdiff --git a/packages/tests/fixtures/thumbnail-playlist-280x157.jpg b/packages/tests/fixtures/thumbnail-playlist-280x157.jpgindex 7b3b5e521e..85e1d7aa22 100644Binary files a/packages/tests/fixtures/thumbnail-playlist-280x157.jpg and b/packages/tests/fixtures/thumbnail-playlist-280x157.jpg differdiff --git a/packages/tests/fixtures/video_short.mp4.jpg b/packages/tests/fixtures/video_short.mp4.jpgindex d0cc1d691e..b3176b6c2b 100644Binary files a/packages/tests/fixtures/video_short.mp4.jpg and b/packages/tests/fixtures/video_short.mp4.jpg differdiff --git a/packages/tests/fixtures/video_short.ogv.jpg b/packages/tests/fixtures/video_short.ogv.jpgindex ccee9e3632..e7eaa37e14 100644Binary files a/packages/tests/fixtures/video_short.ogv.jpg and b/packages/tests/fixtures/video_short.ogv.jpg differdiff --git a/packages/tests/fixtures/video_short.webm.jpg b/packages/tests/fixtures/video_short.webm.jpgindex 63b0a844ab..85e1d7aa22 100644Binary files a/packages/tests/fixtures/video_short.webm.jpg and b/packages/tests/fixtures/video_short.webm.jpg differdiff --git a/packages/tests/fixtures/video_short1.webm-thumbnail-1920x1080.jpg b/packages/tests/fixtures/video_short1.webm-thumbnail-1920x1080.jpgnew file mode 100644index 0000000000..8004760a61Binary files /dev/null and b/packages/tests/fixtures/video_short1.webm-thumbnail-1920x1080.jpg differdiff --git a/packages/tests/fixtures/video_short1.webm.jpg b/packages/tests/fixtures/video_short1.webm.jpgindex 88d950b3d6..f25a957f26 100644Binary files a/packages/tests/fixtures/video_short1.webm.jpg and b/packages/tests/fixtures/video_short1.webm.jpg differdiff --git a/packages/tests/fixtures/video_short2.webm.jpg b/packages/tests/fixtures/video_short2.webm.jpgindex 1016f63549..7682905fa9 100644Binary files a/packages/tests/fixtures/video_short2.webm.jpg and b/packages/tests/fixtures/video_short2.webm.jpg differdiff --git a/packages/tests/fixtures/video_short3.webm.jpg b/packages/tests/fixtures/video_short3.webm.jpgindex 5d20c64b55..d95466e9ea 100644Binary files a/packages/tests/fixtures/video_short3.webm.jpg and b/packages/tests/fixtures/video_short3.webm.jpg differdiff --git a/packages/tests/src/api/live/live-save-replay.ts b/packages/tests/src/api/live/live-save-replay.tsindex 84c3c59297..212ab9ee01 100644--- a/packages/tests/src/api/live/live-save-replay.ts+++ b/packages/tests/src/api/live/live-save-replay.ts@@ -152,7 +152,7 @@ describe('Save replay setting', function () {for (const server of servers) {const video = await server.videos.get({ id: videoId })- await _checkVideoThumbnails({ video, server, thumbnails, strict: true })+ await _checkVideoThumbnails({ video, server, thumbnails })}}@@ -365,7 +365,7 @@ describe('Save replay setting', function () {attributes: {name: 'video updated',privacy: VideoPrivacy.PUBLIC,- thumbnailfile: 'custom-thumbnail-850x480.jpg'+ thumbnailfile: 'custom-thumbnail-input.jpg'}})await waitJobs(servers)@@ -433,7 +433,7 @@ describe('Save replay setting', function () {permanent: true,replay: true,replaySettings: { privacy: VideoPrivacy.UNLISTED },- thumbnailfile: 'custom-thumbnail-850x480.jpg'+ thumbnailfile: 'custom-thumbnail-input.jpg'})await waitJobs(servers)@@ -677,7 +677,7 @@ describe('Save replay setting', function () {it('Should update the live replay thumbnail', async function () {await servers[0].videos.update({id: lastReplayUUID,- attributes: { thumbnailfile: 'custom-thumbnail-850x480.jpg' }+ attributes: { thumbnailfile: 'custom-thumbnail-input.jpg' }})await waitJobs(servers)diff --git a/packages/tests/src/api/live/live.ts b/packages/tests/src/api/live/live.tsindex cd26029fea..01d7926361 100644--- a/packages/tests/src/api/live/live.ts+++ b/packages/tests/src/api/live/live.ts@@ -95,7 +95,7 @@ describe('Test live', function () {replaySettings: { privacy: VideoPrivacy.PUBLIC },latencyMode: LiveVideoLatencyMode.SMALL_LATENCY,privacy: VideoPrivacy.PUBLIC,- thumbnailfile: 'video_short1.webm-thumbnail-850x480.jpg'+ thumbnailfile: 'custom-thumbnail-input.jpg'}})liveVideoUUID = live.uuid@@ -128,7 +128,7 @@ describe('Test live', function () {await checkThumbnails({server,video,- thumbnails: [ 'video_short1.webm-thumbnail-850x480.jpg', 'video_short1.webm.jpg' ]+ thumbnails: [ 'custom-thumbnail-850x480.jpg', 'custom-thumbnail-280x157.jpg' ]})const live = await server.live.get({ videoId: liveVideoUUID })diff --git a/packages/tests/src/api/server/lazy-static.ts b/packages/tests/src/api/server/lazy-static.tsindex c47f327707..c785a4bad2 100644--- a/packages/tests/src/api/server/lazy-static.ts+++ b/packages/tests/src/api/server/lazy-static.ts@@ -54,7 +54,7 @@ describe('Test lazy static endpoints', function () {async function checkCachedFiles (options: { populated: boolean }) {if (options.populated) {- expect(await servers[1].servers.countFiles(join('cache', 'thumbnails'))).to.equal(2)+ expect(await servers[1].servers.countFiles(join('cache', 'thumbnails'))).to.equal(5)expect(await servers[1].servers.countFiles(join('cache', 'avatars'))).to.equal(2 * 4)expect(await servers[1].servers.countFiles(join('cache', 'storyboards'))).to.equal(1)expect(await servers[1].servers.countFiles(join('cache', 'video-captions'))).to.equal(1)diff --git a/packages/tests/src/api/server/services.ts b/packages/tests/src/api/server/services.tsindex a934627e10..cc7acfb80f 100644--- a/packages/tests/src/api/server/services.ts+++ b/packages/tests/src/api/server/services.ts@@ -1,6 +1,5 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */-import { maxBy } from '@peertube/peertube-core-utils'import { HttpStatusCode, Video, VideoPlaylistPrivacy } from '@peertube/peertube-models'import {cleanupTests,@@ -86,7 +85,7 @@ describe('Test services', function () {`title="${video.name}" src="http://${servers[0].host}/videos/embed/${video.shortUUID}${suffix.output}" ` +'style="border: none" allow="fullscreen"></iframe>'- const thumbnail = maxBy(video.thumbnails, 'width')+ const thumbnail = video.thumbnails.find(t => t.width === 1280 && t.height === 720)expect(res.body.html).to.equal(expectedHtml)expect(res.body.title).to.equal(video.name)@@ -94,8 +93,8 @@ describe('Test services', function () {expect(res.body.width).to.equal(560)expect(res.body.height).to.equal(315)expect(res.body.thumbnail_url).to.equal(thumbnail.fileUrl)- expect(res.body.thumbnail_width).to.equal(850)- expect(res.body.thumbnail_height).to.equal(480)+ expect(res.body.thumbnail_width).to.equal(1280)+ expect(res.body.thumbnail_height).to.equal(720)}}})diff --git a/packages/tests/src/api/users/user-import.ts b/packages/tests/src/api/users/user-import.tsindex 29de3f6c24..82569bf5e0 100644--- a/packages/tests/src/api/users/user-import.ts+++ b/packages/tests/src/api/users/user-import.ts@@ -441,14 +441,14 @@ function runTest (withObjectStorage: boolean) {attributes: {name: 'noah public video second channel',- privacy: (VideoPrivacy.PUBLIC),- category: (12),+ privacy: VideoPrivacy.PUBLIC,+ category: 12,tags: [ 'tag1', 'tag2' ],commentsPolicy: VideoCommentPolicy.DISABLED,downloadEnabled: false,nsfw: false,- description: ('video description'),- support: ('video support'),+ description: 'video description',+ support: 'video support',language: 'fr',licence: 1,originallyPublishedAt: new Date(0).toISOString(),@@ -479,7 +479,7 @@ function runTest (withObjectStorage: boolean) {size: 23000}],- thumbnails: [ 'custom-thumbnail-280x157.jpg', 'custom-thumbnail-850x480.jpg' ]+ thumbnails: [ 'custom-thumbnail-user-import-280x157.jpg', 'custom-thumbnail-user-import-850x480.jpg' ]}})}diff --git a/packages/tests/src/api/users/user-videos.ts b/packages/tests/src/api/users/user-videos.tsindex 413cd94f02..371c821474 100644--- a/packages/tests/src/api/users/user-videos.ts+++ b/packages/tests/src/api/users/user-videos.ts@@ -138,7 +138,7 @@ describe('Test user videos', function () {const video = data[0]expect(video.name).to.equal('super user video')- expect(video.thumbnails).to.have.lengthOf(2)+ expect(video.thumbnails).to.have.lengthOf(5)})it('Should be able to filter by a specific channel in my videos', async function () {@@ -153,7 +153,7 @@ describe('Test user videos', function () {const video = data[0]expect(video.name).to.equal('super user video')- expect(video.thumbnails).to.have.lengthOf(2)+ expect(video.thumbnails).to.have.lengthOf(4)}{diff --git a/packages/tests/src/api/videos/multiple-servers.ts b/packages/tests/src/api/videos/multiple-servers.tsindex f0f9320017..97f8850595 100644--- a/packages/tests/src/api/videos/multiple-servers.ts+++ b/packages/tests/src/api/videos/multiple-servers.ts@@ -167,7 +167,7 @@ describe('Test multiple servers', function () {support: 'my super support text for server 2',tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],fixture: 'video_short2.webm',- thumbnailfile: 'custom-thumbnail-850x480.jpg'+ thumbnailfile: 'custom-thumbnail-input.jpg'}await servers[1].videos.upload({ token: userAccessToken, attributes, mode: 'resumable' })@@ -225,7 +225,7 @@ describe('Test multiple servers', function () {size: 750000}],- thumbnails: [ 'custom-thumbnail-280x157.jpg', 'custom-thumbnail-850x480.jpg' ]+ thumbnails: [ 'custom-thumbnail-280x157.jpg', 'custom-thumbnail-850x480.jpg', 'custom-thumbnail-1920x1080.jpg' ]}const { data } = await server.videos.list()@@ -626,7 +626,7 @@ describe('Test multiple servers', function () {description: 'my super description updated',support: 'my super support text updated',tags: [ 'tag_up_1', 'tag_up_2' ],- thumbnailfile: 'custom-thumbnail-850x480.jpg',+ thumbnailfile: 'custom-thumbnail-input.jpg',originallyPublishedAt: '2019-02-11T13:38:14.449Z'}@@ -784,7 +784,10 @@ describe('Test multiple servers', function () {for (const server of servers) {const video = await server.videos.get({ id: videoUUID })- await testImageGeneratedByFFmpeg({ name: 'video_short1.webm-thumbnail-850x480.jpg', url: maxBy(video.thumbnails, 'width').fileUrl })+ await testImageGeneratedByFFmpeg({+ name: 'video_short1.webm-thumbnail-1920x1080.jpg',+ url: maxBy(video.thumbnails, 'width').fileUrl+ })}})})diff --git a/packages/tests/src/api/videos/single-server.ts b/packages/tests/src/api/videos/single-server.tsindex fe5634eee0..c152f25518 100644--- a/packages/tests/src/api/videos/single-server.ts+++ b/packages/tests/src/api/videos/single-server.ts@@ -265,7 +265,7 @@ describe('Test a single server', function () {videosListBase = datafor (const video of data) {- await checkThumbnails({ video, server, thumbnails: [ video.name.replace(' name', '') + '.jpg' ], strict: false })+ await checkThumbnails({ video, server, thumbnails: [ video.name.replace(' name', '') + '.jpg' ] })}})diff --git a/packages/tests/src/api/videos/video-imports.ts b/packages/tests/src/api/videos/video-imports.tsindex fa268dfd96..bc03303269 100644--- a/packages/tests/src/api/videos/video-imports.ts+++ b/packages/tests/src/api/videos/video-imports.ts@@ -339,7 +339,7 @@ describe('Test video imports', function () {name: 'my super name',description: 'my super description',tags: [ 'supertag1', 'supertag2' ],- thumbnailfile: 'custom-thumbnail-850x480.jpg'+ thumbnailfile: 'custom-thumbnail-input.jpg'}})expect(video.name).to.equal('my super name')diff --git a/packages/tests/src/api/videos/video-playlist-thumbnails.ts b/packages/tests/src/api/videos/video-playlist-thumbnails.tsindex ea55f961f8..84a7e3def1 100644--- a/packages/tests/src/api/videos/video-playlist-thumbnails.ts+++ b/packages/tests/src/api/videos/video-playlist-thumbnails.ts@@ -96,7 +96,7 @@ describe('Playlist thumbnail', function () {displayName: 'playlist with thumbnail',privacy: VideoPlaylistPrivacy.PUBLIC,videoChannelId: servers[1].store.channel.id,- thumbnailfile: 'custom-thumbnail-850x480.jpg'+ thumbnailfile: 'custom-thumbnail-input.jpg'}})playlistWithThumbnailId = created.iddiff --git a/packages/tests/src/api/videos/video-source.ts b/packages/tests/src/api/videos/video-source.tsindex bbd157e4a9..31c214768f 100644--- a/packages/tests/src/api/videos/video-source.ts+++ b/packages/tests/src/api/videos/video-source.ts@@ -373,7 +373,7 @@ describe('Test video source management', function () {const { uuid } = await servers[0].videos.upload({attributes: {name: 'custom miniatures',- thumbnailfile: 'custom-thumbnail-850x480.jpg'+ thumbnailfile: 'custom-thumbnail-input.jpg'}})diff --git a/packages/tests/src/cli/prune-storage.ts b/packages/tests/src/cli/prune-storage.tsindex ace9d80272..2a48e61256 100644--- a/packages/tests/src/cli/prune-storage.ts+++ b/packages/tests/src/cli/prune-storage.ts@@ -94,9 +94,9 @@ describe('Test prune storage CLI', function () {expect(torrentsCount).to.equal(12)const thumbnailsCount = await server.servers.countFiles('thumbnails')- // 6 of 3 local videos (2 sizes for each)+ // 15 of 3 local videos (5 sizes for each)// 1 local playlist- expect(thumbnailsCount).to.equal(7)+ expect(thumbnailsCount).to.equal(16)const avatarsCount = await server.servers.countFiles('avatars')expect(avatarsCount).to.equal(4)@@ -130,7 +130,7 @@ describe('Test prune storage CLI', function () {async function checkCacheFilesCountAfterLazyLoad () {expect(await servers[0].servers.countFiles(join('cache', 'avatars'))).to.equal(4)expect(await servers[0].servers.countFiles(join('cache', 'storyboards'))).to.equal(2)- expect(await servers[0].servers.countFiles(join('cache', 'thumbnails'))).to.equal(4)+ expect(await servers[0].servers.countFiles(join('cache', 'thumbnails'))).to.equal(10)expect(await servers[0].servers.countFiles(join('cache', 'video-captions'))).to.equal(1)}diff --git a/packages/tests/src/cli/regenerate-thumbnails.ts b/packages/tests/src/cli/regenerate-thumbnails.tsindex 895ee1154f..e73f273129 100644--- a/packages/tests/src/cli/regenerate-thumbnails.ts+++ b/packages/tests/src/cli/regenerate-thumbnails.ts@@ -138,7 +138,7 @@ describe('Test regenerate thumbnails CLI', function () {})it('Should have the appropriate thumbnails count', async function () {- expect(await servers[0].servers.countFiles('thumbnails')).to.equal(4)+ expect(await servers[0].servers.countFiles('thumbnails')).to.equal(10)expect(await servers[0].servers.countFiles('cache/thumbnails')).to.equal(0)})@@ -149,8 +149,8 @@ describe('Test regenerate thumbnails CLI', function () {await makeRawRequest({ url: thumbnail.fileUrl, expectedStatus: HttpStatusCode.OK_200 })}- expect(await servers[0].servers.countFiles('thumbnails')).to.equal(4)- expect(await servers[0].servers.countFiles('cache/thumbnails')).to.equal(2)+ expect(await servers[0].servers.countFiles('thumbnails')).to.equal(10)+ expect(await servers[0].servers.countFiles('cache/thumbnails')).to.equal(5)})after(async function () {diff --git a/packages/tests/src/client/jsonld.ts b/packages/tests/src/client/jsonld.tsindex 9733779522..66b5ef71ff 100644--- a/packages/tests/src/client/jsonld.ts+++ b/packages/tests/src/client/jsonld.ts@@ -183,7 +183,7 @@ describe('Test JSONLD HTML tags', function () {expect(jsonld.contentRating).to.equal('Mature')- expect(jsonld.caption).to.deep.equal([+ expect(jsonld.caption).to.have.deep.members([{'@type': 'MediaObject','contentUrl': captions.find(c => c.language.id === 'en').fileUrl,diff --git a/packages/tests/src/shared/import-export.ts b/packages/tests/src/shared/import-export.tsindex 8305b68376..202fb9c786 100644--- a/packages/tests/src/shared/import-export.ts+++ b/packages/tests/src/shared/import-export.ts@@ -241,7 +241,7 @@ export async function prepareImportExportTests (options: {waitTranscoding: true,channelId: noahSecondChannelId,privacy: VideoPrivacy.PUBLIC,- thumbnailfile: 'custom-thumbnail-850x480.jpg'+ thumbnailfile: 'custom-thumbnail-input.jpg'}})diff --git a/packages/tests/src/shared/videos.ts b/packages/tests/src/shared/videos.tsindex 020c27f7d9..5f50e0cc3a 100644--- a/packages/tests/src/shared/videos.ts+++ b/packages/tests/src/shared/videos.ts@@ -1,6 +1,6 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */-import { maxBy, minBy, uuidRegex } from '@peertube/peertube-core-utils'+import { uuidRegex } from '@peertube/peertube-core-utils'import { ffprobePromise } from '@peertube/peertube-ffmpeg'import {FileStorage,@@ -273,7 +273,7 @@ export async function completeVideoCheck (options: {if (attributes.thumbnails) {await checkThumbnails({ video, thumbnails: attributes.thumbnails, server })} else {- await checkThumbnails({ video, thumbnails: [ attributes.fixture + '.jpg' ], strict: false, server })+ await checkThumbnails({ video, thumbnails: [ attributes.fixture + '.jpg' ], server })}if (attributes.files) {@@ -449,9 +449,8 @@ export async function checkThumbnails (options: {video?: Videoplaylist?: VideoPlaylistthumbnails: string[]- strict?: boolean // default true}) {- const { server, video, playlist, strict = true } = options+ const { server, video, playlist } = optionsconst thumbnails = options.thumbnails.map(t => {const matched = t.match(/-(\d+)x(\d+)/)@@ -469,13 +468,32 @@ export async function checkThumbnails (options: {const entity = video || playlist- if (strict) {- expect(entity.thumbnails).to.have.lengthOf(thumbnails.length)+ const toCheck = entity.thumbnails.map(t => ({+ width: t.width,+ height: t.height,+ aspectRatio: t.aspectRatio+ }))++ if (video) {+ expect(toCheck).to.deep.include.members([+ { width: 1400, height: 1400, aspectRatio: '1:1' },+ { width: 280, height: 157, aspectRatio: '16:9' },+ { width: 850, height: 480, aspectRatio: '16:9' },+ { width: 1280, height: 720, aspectRatio: '16:9' },+ { width: 1920, height: 1080, aspectRatio: '16:9' }+ ])++ expect(toCheck).to.have.lengthOf(5)+ } else if (playlist) {+ expect(toCheck).to.deep.include.members([+ { width: 280, height: 157, aspectRatio: '16:9' }+ ])++ expect(toCheck).to.have.lengthOf(1)}for (const thumbnail of thumbnails) {const videoThumbnail = entity.thumbnails.find(t => t.width === thumbnail.width && t.height === thumbnail.height)- expect(videoThumbnail).to.existexpectStartWith(videoThumbnail.fileUrl, server.url)@@ -483,10 +501,18 @@ export async function checkThumbnails (options: {}// eslint-disable-next-line @typescript-eslint/no-deprecated- await testImageGeneratedByFFmpeg({ name: minBy(thumbnails, 'width').filename, url: server.url + entity.thumbnailPath })+ await testImageGeneratedByFFmpeg({+ name: thumbnails.find(t => t.width === 280 && t.height === 157).filename,+ url: server.url + entity.thumbnailPath+ })++ const preview = thumbnails.find(t => t.width === 1920 && t.height === 1080)- if (video && thumbnails.length > 1) {+ if (video && preview) {// eslint-disable-next-line @typescript-eslint/no-deprecated- await testImageGeneratedByFFmpeg({ name: maxBy(thumbnails, 'width').filename, url: server.url + video.previewPath })+ await testImageGeneratedByFFmpeg({+ name: preview.filename,+ url: server.url + video.previewPath+ })}}diff --git a/server/core/controllers/api/runners/jobs-files.ts b/server/core/controllers/api/runners/jobs-files.tsindex c59a5ebfa7..c849f762f8 100644--- a/server/core/controllers/api/runners/jobs-files.ts+++ b/server/core/controllers/api/runners/jobs-files.ts@@ -140,7 +140,7 @@ function getMaxQualityVideoThumbnail (req: express.Request, res: express.ResponslTags(runner.name, runnerJob.id, runnerJob.type))- const file = video.getBestThumbnail()+ const file = video.getBestThumbnail('16:9')return res.sendFile(file.getFSPath())}diff --git a/server/core/controllers/services.ts b/server/core/controllers/services.tsindex 22f213ef75..dc1e46f822 100644--- a/server/core/controllers/services.ts+++ b/server/core/controllers/services.ts@@ -14,7 +14,13 @@ import { accountHandleGetValidatorFactory } from '../middlewares/validators/indeconst servicesRouter = express.Router()-servicesRouter.use('/oembed', cors(), apiRateLimiter, asyncMiddleware(oembedValidator), generateOEmbed)+servicesRouter.use(+ '/oembed',+ cors(),+ apiRateLimiter,+ asyncMiddleware(oembedValidator),+ generateOEmbed+)// TODO: deprecated, remove in PeerTube 8.1servicesRouter.use(@@ -65,7 +71,7 @@ function generateVideoOEmbed (req: express.Request, res: express.Response) {channel: video.VideoChannel,title: video.name,embedPath: video.getEmbedStaticPath() + buildPlayerURLQuery(req.query.url),- thumbnail: video.getBestThumbnail(),+ thumbnail: video.getBestThumbnail('16:9', 1280),req})diff --git a/server/core/controllers/sitemap.ts b/server/core/controllers/sitemap.tsindex 77d811acb9..303fb4397f 100644--- a/server/core/controllers/sitemap.ts+++ b/server/core/controllers/sitemap.ts@@ -112,7 +112,7 @@ async function getSitemapLocalVideoUrls () {// Sitemap description should be < 2000 characters'description': truncate(v.description || v.name, { length: 2000, omission: '...' }),'player_loc': WEBSERVER.URL + v.getEmbedStaticPath(),- 'thumbnail_loc': WEBSERVER.URL + v.getSmallestThumbnailStaticPath(),+ 'thumbnail_loc': WEBSERVER.URL + v.getSmallestThumbnailStaticPath('16:9'),'content_loc': contentLoc,'duration': v.duration,'view_count': v.views,diff --git a/server/core/initializers/checker-after-init.ts b/server/core/initializers/checker-after-init.tsindex 97e169f990..68e22be6f4 100644--- a/server/core/initializers/checker-after-init.ts+++ b/server/core/initializers/checker-after-init.ts@@ -383,8 +383,8 @@ function checkThumbnailsConfig () {throw new Error('thumbnails.generation_from_video.frames_to_analyze must be a number greater than 1')}- if (!isArray(CONFIG.THUMBNAILS.SIZES) || CONFIG.THUMBNAILS.SIZES.length !== 2) {- throw new Error('thumbnails.sizes must be an array of 2 sizes')+ if (!isArray(CONFIG.THUMBNAILS.SIZES) || CONFIG.THUMBNAILS.SIZES.length === 0) {+ throw new Error('thumbnails.sizes must not be empty')}}diff --git a/server/core/initializers/config.ts b/server/core/initializers/config.tsindex 330c74e7fc..5e59609f7c 100644--- a/server/core/initializers/config.ts+++ b/server/core/initializers/config.ts@@ -1,8 +1,9 @@-import { sortBy } from '@peertube/peertube-core-utils'+import { guessAspectRatio, sortBy } from '@peertube/peertube-core-utils'import {BroadcastMessageLevel,NSFWPolicyType,PlayerTheme,+ ThumbnailAspectRatio,VideoCommentPolicyType,VideoPrivacyType,VideoRedundancyConfigFilter,@@ -522,7 +523,12 @@ const CONFIG = {GENERATION_FROM_VIDEO: {FRAMES_TO_ANALYZE: config.get<number>('thumbnails.generation_from_video.frames_to_analyze')},- SIZES: sortBy(config.get<{ width: number, height: number }[]>('thumbnails.sizes'), 'width')+ SIZES: sortBy(config.get<{ width: number, height: number, aspect_ratio?: ThumbnailAspectRatio }[]>('thumbnails.sizes'), 'width')+ .map(size => ({+ width: size.width,+ height: size.height,+ aspectRatio: size.aspect_ratio || guessAspectRatio(size.width, size.height)+ }))},STATS: {REGISTRATION_REQUESTS: {diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.tsindex 285f5c65db..fdacf0bc70 100644--- a/server/core/initializers/constants.ts+++ b/server/core/initializers/constants.ts@@ -58,7 +58,7 @@ import { CONFIG, registerConfigChangedHandler } from './config.js'// ----------------------------------------------------------------------------export const LAST_MIGRATION_VERSION = 990+export const LAST_MIGRATION_VERSION = 995// ---------------------------------------------------------------------------diff --git a/server/core/initializers/migrations/0995-thumbnail-aspect-ratio.ts b/server/core/initializers/migrations/0995-thumbnail-aspect-ratio.tsnew file mode 100644index 0000000000..8da236d713--- /dev/null+++ b/server/core/initializers/migrations/0995-thumbnail-aspect-ratio.ts@@ -0,0 +1,34 @@+import * as Sequelize from 'sequelize'++async function up (utils: {+ transaction: Sequelize.Transaction+ queryInterface: Sequelize.QueryInterface+ sequelize: Sequelize.Sequelize+}): Promise<void> {+ const { transaction } = utils++ {+ await utils.queryInterface.addColumn('thumbnail', 'aspectRatio', {+ type: Sequelize.STRING,+ allowNull: false,+ defaultValue: '16:9'+ }, { transaction })+ }++ {+ await utils.queryInterface.changeColumn('thumbnail', 'aspectRatio', {+ type: Sequelize.STRING,+ allowNull: false,+ defaultValue: null+ }, { transaction })+ }+}++function down (options) {+ throw new Error('Not implemented.')+}++export {+ down,+ up+}diff --git a/server/core/lib/activitypub/videos/shared/abstract-builder.ts b/server/core/lib/activitypub/videos/shared/abstract-builder.tsindex 8b4ae9a941..9eeac2ead0 100644--- a/server/core/lib/activitypub/videos/shared/abstract-builder.ts+++ b/server/core/lib/activitypub/videos/shared/abstract-builder.ts@@ -1,3 +1,4 @@+import { guessAspectRatio } from '@peertube/peertube-core-utils'import { ActivityTagObject, VideoChaptersObject, VideoObject, VideoStreamingPlaylistType_Type } from '@peertube/peertube-models'import { isVideoChaptersObjectValid } from '@server/helpers/custom-validators/activitypub/video-chapters.js'import { deleteAllModels, filterNonExistingModels, retryTransactionWrapper } from '@server/helpers/database-utils.js'@@ -62,7 +63,13 @@ export abstract class APVideoAbstractBuilder {return undefined}- const thumbnails = icons.map(icon => updateRemoteVideoThumbnail({ fileUrl: icon.url, video, size: icon }))+ const thumbnails = icons.map(icon => {+ return updateRemoteVideoThumbnail({+ fileUrl: icon.url,+ video,+ size: { ...icon, aspectRatio: guessAspectRatio(icon.width, icon.height) }+ })+ })await video.replaceAndSaveThumbnails(thumbnails, t)}diff --git a/server/core/lib/html/shared/video-html.ts b/server/core/lib/html/shared/video-html.tsindex 4dc817d4df..115d954d9a 100644--- a/server/core/lib/html/shared/video-html.ts+++ b/server/core/lib/html/shared/video-html.ts@@ -98,7 +98,7 @@ export class VideoHtml {let customHTML = TagsHtml.addTitleTag(html, video.name)customHTML = TagsHtml.addDescriptionTag(customHTML, escapedTruncatedDescription)- const thumbnail = video.getBestThumbnail()+ const thumbnail = video.getBestThumbnail('16:9')return TagsHtml.addTags(customHTML, {url: WEBSERVER.URL + video.getWatchStaticPath(),diff --git a/server/core/lib/job-queue/handlers/video-live-ending.ts b/server/core/lib/job-queue/handlers/video-live-ending.tsindex 992d86ae87..c4fb8b6237 100644--- a/server/core/lib/job-queue/handlers/video-live-ending.ts+++ b/server/core/lib/job-queue/handlers/video-live-ending.ts@@ -207,7 +207,7 @@ async function copyOrRegenerateThumbnails (options: {let thumbnails: MThumbnail[] = []- const bestThumbnail = liveVideo.getBestThumbnail()+ const bestThumbnail = liveVideo.getBestThumbnail('16:9')if (bestThumbnail.automaticallyGenerated === false) {thumbnails = await createLocalVideoThumbnailsFromImage({diff --git a/server/core/lib/thumbnail.ts b/server/core/lib/thumbnail.tsindex 523da2a8b8..dabd688710 100644--- a/server/core/lib/thumbnail.ts+++ b/server/core/lib/thumbnail.ts@@ -1,5 +1,5 @@import { sortBy } from '@peertube/peertube-core-utils'-import { VideoFileStream } from '@peertube/peertube-models'+import { ThumbnailAspectRatio, VideoFileStream } from '@peertube/peertube-models'import { generateThumbnailFromVideo } from '@server/helpers/ffmpeg/ffmpeg-image.js'import { logger, loggerTagsFactory } from '@server/helpers/logger.js'import Bluebird from 'bluebird'@@ -18,7 +18,7 @@ import { downloadImageFromWorker } from './worker/parent-process.js'const lTags = loggerTagsFactory('thumbnail')-type ImageSize = { height: number, width: number }+type ImageSize = { height: number, width: number, aspectRatio: ThumbnailAspectRatio }export function createLocalPlaylistThumbnailFromImage (options: {inputPath: string@@ -29,7 +29,7 @@ export function createLocalPlaylistThumbnailFromImage (options: {const { inputPath, playlist, automaticallyGenerated, keepOriginal = false } = optionsconst size = CONFIG.THUMBNAILS.SIZES[0] // Minimum size- const { filename, outputPath, height, width } = buildMetadataFromPlaylist({+ const { filename, outputPath, height, width, aspectRatio } = buildMetadataFromPlaylist({playlist,size,extension: getImageExtension(inputPath)@@ -44,6 +44,7 @@ export function createLocalPlaylistThumbnailFromImage (options: {filename,height,width,+ aspectRatio,automaticallyGenerated,cached: false})@@ -57,7 +58,11 @@ export function updateRemotePlaylistThumbnailFromUrl (options: {const size = CONFIG.THUMBNAILS.SIZES[0] // Minimum sizeconst extension = getImageExtension(fileUrl)- const { filename: generatedFilename, height, width, existingThumbnail } = buildMetadataFromPlaylist({ playlist, size, extension })+ const { filename: generatedFilename, height, width, aspectRatio, existingThumbnail } = buildMetadataFromPlaylist({+ playlist,+ size,+ extension+ })// Only change thumbnail filename if the file changedif (hasThumbnailUrlChanged({ existingThumbnail, fileUrl, extension })) {@@ -74,6 +79,7 @@ export function updateRemotePlaylistThumbnailFromUrl (options: {thumbnail.filename = generatedFilenamethumbnail.height = heightthumbnail.width = width+ thumbnail.aspectRatio = aspectRatiothumbnail.fileUrl = fileUrlthumbnail.cached = false@@ -82,13 +88,14 @@ export function updateRemotePlaylistThumbnailFromUrl (options: {existingThumbnail.height = heightexistingThumbnail.width = width+ existingThumbnail.aspectRatio = aspectRatioreturn existingThumbnail}// ----------------------------------------------------------------------------export function createLocalVideoThumbnailsFromImage (options: {+export async function createLocalVideoThumbnailsFromImage (options: {inputPath: stringvideo: MVideoThumbnailautomaticallyGenerated: boolean@@ -96,11 +103,22 @@ export function createLocalVideoThumbnailsFromImage (options: {}) {const { inputPath, automaticallyGenerated, video, keepOriginal = false } = options- return Promise.all(+ const thumbnails = await Promise.all(CONFIG.THUMBNAILS.SIZES.map(size =>- _createLocalVideoThumbnailFromImage({ inputPath, video, automaticallyGenerated, size, keepOriginal })+ // We'll delete origin file ourselves after all thumbnails are generated, to avoid deleting it before generating all thumbnails+ _createLocalVideoThumbnailFromImage({ inputPath, video, automaticallyGenerated, size, keepOriginal: true })))++ if (!keepOriginal) {+ try {+ await remove(inputPath)+ } catch (err) {+ logger.error('Cannot remove original image after thumbnail generation.', { err, ...lTags() })+ }+ }++ return thumbnails}function _createLocalVideoThumbnailFromImage (options: {@@ -108,11 +126,11 @@ function _createLocalVideoThumbnailFromImage (options: {video: MVideoThumbnailautomaticallyGenerated: booleansize: ImageSize- keepOriginal?: boolean // default to false+ keepOriginal: boolean}) {- const { inputPath, video, automaticallyGenerated, size, keepOriginal = false } = options+ const { inputPath, video, automaticallyGenerated, size, keepOriginal } = options- const { filename, outputPath, height, width } = buildMetadataFromVideo({+ const { filename, outputPath, height, width, aspectRatio } = buildMetadataFromVideo({video,size,extension: getImageExtension(inputPath)@@ -127,6 +145,7 @@ function _createLocalVideoThumbnailFromImage (options: {filename,height,width,+ aspectRatio,automaticallyGenerated,cached: false})@@ -148,8 +167,8 @@ export function createLocalVideoThumbnailsFromVideo (options: {let biggestImagePath: string// Get bigger images to generate first- return Bluebird.mapSeries(sortBy(metadata, 'height').reverse(), metadata => {- const { filename, basePath, height, width, outputPath } = metadata+ return Bluebird.mapSeries(sortBy(metadata, 'width').reverse(), metadata => {+ const { filename, basePath, height, width, aspectRatio, outputPath } = metadatalet thumbnailCreator: () => Promise<any>@@ -180,13 +199,16 @@ export function createLocalVideoThumbnailsFromVideo (options: {})}- if (!biggestImagePath) biggestImagePath = outputPath+ if (!biggestImagePath && aspectRatio === '16:9') {+ biggestImagePath = outputPath+ }return createThumbnailFromFunction({thumbnailCreator,filename,height,width,+ aspectRatio,automaticallyGenerated: true,cached: false})@@ -215,13 +237,13 @@ function _createLocalVideoThumbnailFromUrl (options: {const { downloadUrl, video, size } = optionsconst extension = getImageExtension(downloadUrl)- const { filename, basePath, height, width } = buildMetadataFromVideo({ video, size, extension })+ const { filename, basePath, height, width, aspectRatio } = buildMetadataFromVideo({ video, size, extension })const thumbnailCreator = () => {return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } })}- return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, cached: false })+ return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, aspectRatio, cached: false })}// ---------------------------------------------------------------------------@@ -234,7 +256,7 @@ export function updateRemoteVideoThumbnail (options: {const { fileUrl, video, size } = optionsconst extension = getImageExtension(fileUrl)- const { filename: generatedFilename, height, width, existingThumbnail } = buildMetadataFromVideo({ video, size, extension })+ const { filename: generatedFilename, height, width, aspectRatio, existingThumbnail } = buildMetadataFromVideo({ video, size, extension })if (hasThumbnailUrlChanged({ existingThumbnail, fileUrl, video, extension })) {if (existingThumbnail) {@@ -249,6 +271,7 @@ export function updateRemoteVideoThumbnail (options: {thumbnail.filename = generatedFilenamethumbnail.height = heightthumbnail.width = width+ thumbnail.aspectRatio = aspectRatiothumbnail.fileUrl = fileUrlthumbnail.cached = false@@ -258,6 +281,7 @@ export function updateRemoteVideoThumbnail (options: {// Update sizes, that PeerTube did not federate in previous versionsexistingThumbnail.height = heightexistingThumbnail.width = width+ existingThumbnail.aspectRatio = aspectRatioreturn existingThumbnail}@@ -320,7 +344,8 @@ function buildMetadataFromPlaylist (options: {existingThumbnail: playlist.Thumbnail,outputPath: join(CONFIG.STORAGE.THUMBNAILS_DIR, filename),height: size.height,- width: size.width+ width: size.width,+ aspectRatio: size.aspectRatio}}@@ -343,7 +368,8 @@ function buildMetadataFromVideo (options: {existingThumbnail,outputPath: join(CONFIG.STORAGE.THUMBNAILS_DIR, filename),height: size.height,- width: size.width+ width: size.width,+ aspectRatio: size.aspectRatio}}@@ -352,6 +378,7 @@ async function createThumbnailFromFunction (parameters: {filename: stringheight: numberwidth: number+ aspectRatio: ThumbnailAspectRatiocached: booleanautomaticallyGenerated?: booleanfileUrl?: string@@ -361,6 +388,7 @@ async function createThumbnailFromFunction (parameters: {filename,width,height,+ aspectRatio,cached,automaticallyGenerated = null,fileUrl = null@@ -374,6 +402,7 @@ async function createThumbnailFromFunction (parameters: {thumbnail.fileUrl = fileUrlthumbnail.automaticallyGenerated = automaticallyGeneratedthumbnail.cached = cached+ thumbnail.aspectRatio = aspectRatioawait thumbnailCreator()diff --git a/server/core/lib/transcoding/web-transcoding.ts b/server/core/lib/transcoding/web-transcoding.tsindex 044df27bef..7500264448 100644--- a/server/core/lib/transcoding/web-transcoding.ts+++ b/server/core/lib/transcoding/web-transcoding.ts@@ -143,7 +143,7 @@ export async function mergeAudioVideofile (options: {const videoOutputPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname)// If the user updates the video thumbnails during transcoding- const thumbnailPath = video.getBestThumbnail().getFSPath()+ const thumbnailPath = video.getBestThumbnail('16:9').getFSPath()const tmpThumbnailPath = join(CONFIG.STORAGE.TMP_DIR, basename(thumbnailPath))await copyFile(thumbnailPath, tmpThumbnailPath)diff --git a/server/core/lib/user-import-export/exporters/videos-exporter.ts b/server/core/lib/user-import-export/exporters/videos-exporter.tsindex 9e9a496b05..43fe902298 100644--- a/server/core/lib/user-import-export/exporters/videos-exporter.ts+++ b/server/core/lib/user-import-export/exporters/videos-exporter.ts@@ -164,8 +164,8 @@ export class VideosExporter extends AbstractUserExporter<VideoExportJSON> {url: video.url,- thumbnailUrl: video.getBestThumbnail()?.getLocalFileUrl() || null,- previewUrl: video.getBestThumbnail()?.getLocalFileUrl() || null,+ thumbnailUrl: video.getBestThumbnail('16:9')?.getLocalFileUrl() || null,+ previewUrl: video.getBestThumbnail('16:9')?.getLocalFileUrl() || null,thumbnails: video.Thumbnails.map(t => ({width: t.width,height: t.height,@@ -297,7 +297,7 @@ export class VideosExporter extends AbstractUserExporter<VideoExportJSON> {chapters: MVideoChapter[],exportedVideoFileOrSource: MVideoFile | MVideoSource): Promise<ActivityCreate<VideoObject>> {- const icon = video.getBestThumbnail()+ const icon = video.getBestThumbnail('16:9')const audience = getVideoAudience({account: video.VideoChannel.Account,@@ -405,7 +405,7 @@ export class VideosExporter extends AbstractUserExporter<VideoExportJSON> {relativePathsFromJSON.captions[caption.language] = join(this.relativeStaticDirPath, this.getArchiveCaptionFilePath(video, caption))}- const thumbnail = video.getBestThumbnail()+ const thumbnail = video.getBestThumbnail('16:9')if (thumbnail) {staticFiles.push({archivePath: this.getArchiveThumbnailFilePath(video, thumbnail),diff --git a/server/core/lib/video-download.ts b/server/core/lib/video-download.tsindex fab717a9ad..594d27c234 100644--- a/server/core/lib/video-download.ts+++ b/server/core/lib/video-download.ts@@ -217,7 +217,7 @@ export class VideoDownload {// ---------------------------------------------------------------------------private async buildCoverInput () {- const thumbnail = this.video.getBestThumbnail()+ const thumbnail = this.video.getBestThumbnail('16:9')if (this.video.isLocal()) return { coverPath: thumbnail?.getFSPath() }diff --git a/server/core/lib/video-playlist.ts b/server/core/lib/video-playlist.tsindex d7268ede03..17d2aac8c5 100644--- a/server/core/lib/video-playlist.ts+++ b/server/core/lib/video-playlist.ts@@ -35,7 +35,7 @@ export async function createWatchLaterPlaylist (account: MAccount, t: Transactioexport async function generateThumbnailForPlaylist (videoPlaylist: MVideoPlaylistThumbnail, video: MVideoThumbnail) {logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url)- const videoThumbnail = video.getBestThumbnail()+ const videoThumbnail = video.getBestThumbnail('16:9')if (!videoThumbnail) {logger.info('Cannot generate thumbnail for playlist %s because video %s does not have any.', videoPlaylist.url, video.url)returndiff --git a/server/core/models/abuse/abuse.ts b/server/core/models/abuse/abuse.tsindex 354b563b20..339d4f6d8e 100644--- a/server/core/models/abuse/abuse.ts+++ b/server/core/models/abuse/abuse.ts@@ -42,7 +42,7 @@ import {} from '../../types/models/index.js'import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account.js'import { SequelizeModel, getSort, parseAggregateResult, throwIfNotValid } from '../shared/index.js'-import { ThumbnailModel } from '../video/thumbnail.js'+import { ThumbnailModel, thumbnailAPIAttributes } from '../video/thumbnail.js'import { VideoBlacklistModel } from '../video/video-blacklist.js'import { SummaryOptions as ChannelSummaryOptions, VideoChannelModel, ScopeNames as VideoChannelScopeNames } from '../video/video-channel.js'import { ScopeNames as CommentScopeNames, VideoCommentModel } from '../video/video-comment.js'@@ -159,7 +159,7 @@ export enum ScopeNames {model: VideoModel.unscoped(),include: [{- attributes: [ 'filename', 'fileUrl', 'width', 'height' ],+ attributes: thumbnailAPIAttributes,model: ThumbnailModel},{@@ -517,7 +517,7 @@ export class AbuseModel extends SequelizeModel<AbuseModel> {deleted: !video,blacklisted: video?.isBlacklisted() || false,- thumbnailPath: video?.getSmallestThumbnailStaticPath(),+ thumbnailPath: video?.getSmallestThumbnailStaticPath('16:9'),thumbnails: video?.Thumbnails.map(t => t.toFormattedJSON()) || [],channel: video?.VideoChannel.toFormattedJSON() || abuseModel.deletedVideo?.channel@@ -579,8 +579,8 @@ export class AbuseModel extends SequelizeModel<AbuseModel> {? this.ReporterAccount.toFormattedJSON(): null,- countReportsForReporter: (countReportsForReporter || 0),- countReportsForReportee: (countReportsForReportee || 0)+ countReportsForReporter: countReportsForReporter || 0,+ countReportsForReportee: countReportsForReportee || 0})}diff --git a/server/core/models/video/formatter/video-api-format.ts b/server/core/models/video/formatter/video-api-format.tsindex e92b445ea7..abf77dabda 100644--- a/server/core/models/video/formatter/video-api-format.ts+++ b/server/core/models/video/formatter/video-api-format.ts@@ -115,8 +115,8 @@ export function videoModelToFormattedJSON (video: MVideoFormattable, options: Vilikes: video.likes,dislikes: video.dislikes,- thumbnailPath: video.getSmallestThumbnailStaticPath(),- previewPath: video.getBestThumbnailStaticPath(),+ thumbnailPath: video.getSmallestThumbnailStaticPath('16:9'),+ previewPath: video.getBestThumbnailStaticPath('16:9'),thumbnails: (video.Thumbnails || []).map(t => t.toFormattedJSON()),diff --git a/server/core/models/video/sql/video/shared/video-table-attributes.ts b/server/core/models/video/sql/video/shared/video-table-attributes.tsindex 806e677686..4909a95c29 100644--- a/server/core/models/video/sql/video/shared/video-table-attributes.ts+++ b/server/core/models/video/sql/video/shared/video-table-attributes.ts@@ -1,3 +1,5 @@+import { thumbnailAPIAttributes } from '@server/models/video/thumbnail.js'+/*** Class to build video attributes/join names we want to fetch from the database*/@@ -48,13 +50,11 @@ export class VideoTableAttributes {}getThumbnailAttributes () {- let attributeKeys = [ 'id', 'filename', 'height', 'width', 'fileUrl' ]+ // We need the id to efficiently build the model+ let attributeKeys = [ 'id', ...thumbnailAPIAttributes ] as string[]if (this.mode === 'get') {attributeKeys = attributeKeys.concat([- 'height',- 'width',- 'fileUrl','cached','automaticallyGenerated','videoId',diff --git a/server/core/models/video/thumbnail.ts b/server/core/models/video/thumbnail.tsindex eeb5fd3b90..a62e495bb1 100644--- a/server/core/models/video/thumbnail.ts+++ b/server/core/models/video/thumbnail.ts@@ -1,4 +1,5 @@-import { ActivityIconObject } from '@peertube/peertube-models'+import { ActivityIconObject, Thumbnail, type ThumbnailAspectRatio } from '@peertube/peertube-models'+import { AttributesOnly } from '@peertube/peertube-typescript-utils'import { CONFIG } from '@server/initializers/config.js'import { MThumbnail } from '@server/types/models/index.js'import { remove } from 'fs-extra/esm'@@ -23,6 +24,14 @@ import { buildSQLAttributes } from '../shared/table.js'import { VideoPlaylistModel } from './video-playlist.js'import { VideoModel } from './video.js'+export const thumbnailAPIAttributes = [+ 'filename',+ 'fileUrl',+ 'width',+ 'height',+ 'aspectRatio'+] as const satisfies (keyof AttributesOnly<ThumbnailModel>)[]+@Table({tableName: 'thumbnail',indexes: [@@ -54,6 +63,11 @@ export class ThumbnailModel extends SequelizeModel<ThumbnailModel> {@Columndeclare width: number+ @AllowNull(false)+ @Default(null)+ @Column+ declare aspectRatio: ThumbnailAspectRatio+@AllowNull(true)@Column(DataType.STRING(CONSTRAINTS_FIELDS.COMMONS.URL.max))declare fileUrl: string@@ -169,10 +183,11 @@ export class ThumbnailModel extends SequelizeModel<ThumbnailModel> {// ---------------------------------------------------------------------------- toFormattedJSON () {+ toFormattedJSON (): Thumbnail {return {height: this.height,width: this.width,+ aspectRatio: this.aspectRatio,fileUrl: this.getLocalFileUrl()}}diff --git a/server/core/models/video/video-blacklist.ts b/server/core/models/video/video-blacklist.tsindex 01c893cf8f..4e7eb38760 100644--- a/server/core/models/video/video-blacklist.ts+++ b/server/core/models/video/video-blacklist.ts@@ -4,8 +4,8 @@ import { FindOptions } from 'sequelize'import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Table, UpdatedAt } from 'sequelize-typescript'import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist.js'import { CONSTRAINTS_FIELDS } from '../../initializers/constants.js'-import { SequelizeModel, getBlacklistSort, searchAttribute, throwIfNotValid } from '../shared/index.js'-import { ThumbnailModel } from './thumbnail.js'+import { getBlacklistSort, searchAttribute, SequelizeModel, throwIfNotValid } from '../shared/index.js'+import { thumbnailAPIAttributes, ThumbnailModel } from './thumbnail.js'import { SummaryOptions, VideoChannelModel, ScopeNames as VideoChannelScopeNames } from './video-channel.js'import { VideoModel } from './video.js'@@ -84,7 +84,7 @@ export class VideoBlacklistModel extends SequelizeModel<VideoBlacklistModel> {},{model: ThumbnailModel,- attributes: [ 'width', 'height', 'filename' ],+ attributes: thumbnailAPIAttributes,required: false}]diff --git a/server/core/models/video/video.ts b/server/core/models/video/video.tsindex fb4fa479f9..41109cf20f 100644--- a/server/core/models/video/video.ts+++ b/server/core/models/video/video.ts@@ -2,6 +2,7 @@ import { buildVideoEmbedPath, buildVideoWatchPath, maxBy, minBy, pick, wait } frimport {FileStorage,ResultList,+ ThumbnailAspectRatio,UserRight,Video,VideoDetails,@@ -153,7 +154,7 @@ import {} from './sql/video/index.js'import { StoryboardModel } from './storyboard.js'import { TagModel } from './tag.js'-import { ThumbnailModel } from './thumbnail.js'+import { ThumbnailModel, thumbnailAPIAttributes } from './thumbnail.js'import { VideoBlacklistModel } from './video-blacklist.js'import { VideoCaptionModel } from './video-caption.js'import { SummaryOptions, VideoChannelModel, ScopeNames as VideoChannelScopeNames } from './video-channel.js'@@ -210,7 +211,7 @@ export type ForAPIOptions = {required: true},{- attributes: [ 'width', 'height', 'fileUrl', 'filename' ],+ attributes: thumbnailAPIAttributes,model: ThumbnailModel,required: false}@@ -1920,32 +1921,45 @@ export class VideoModel extends SequelizeModel<VideoModel> {// ---------------------------------------------------------------------------- getBestThumbnail (this: Pick<MVideoThumbnail, 'Thumbnails'>) {+ getBestThumbnail (this: Pick<MVideoThumbnail, 'Thumbnails' | 'filterThumbnails'>, ratio: ThumbnailAspectRatio, maxWidth?: number) {if (!this.Thumbnails || this.Thumbnails.length === 0) return undefined- return maxBy(this.Thumbnails, 'width')+ return maxBy(this.filterThumbnails(ratio, maxWidth), 'width')}- getBestThumbnailStaticPath (this: Pick<MVideoThumbnail, 'Thumbnails' | 'getBestThumbnail'>) {- const thumbnail = this.getBestThumbnail()+ getBestThumbnailStaticPath (+ this: Pick<MVideoThumbnail, 'Thumbnails' | 'filterThumbnails' | 'getBestThumbnail'>,+ ratio: ThumbnailAspectRatio,+ maxWidth?: number+ ) {+ const thumbnail = this.getBestThumbnail(ratio, maxWidth)if (!thumbnail) return nullreturn thumbnail.getFileStaticPath()}- getSmallestThumbnail (this: Pick<MVideoThumbnail, 'Thumbnails'>) {+ getSmallestThumbnail (this: Pick<MVideoThumbnail, 'Thumbnails' | 'filterThumbnails'>, ratio: ThumbnailAspectRatio) {if (!this.Thumbnails || this.Thumbnails.length === 0) return undefined- return minBy(this.Thumbnails, 'width')+ return minBy(this.filterThumbnails(ratio), 'width')}- getSmallestThumbnailStaticPath (this: Pick<MVideoThumbnail, 'Thumbnails' | 'getSmallestThumbnail'>) {- const thumbnail = this.getSmallestThumbnail()+ getSmallestThumbnailStaticPath (+ this: Pick<MVideoThumbnail, 'Thumbnails' | 'filterThumbnails' | 'getSmallestThumbnail'>,+ ratio: ThumbnailAspectRatio+ ) {+ const thumbnail = this.getSmallestThumbnail(ratio)if (!thumbnail) return nullreturn thumbnail.getFileStaticPath()}+ filterThumbnails (this: Pick<MVideoThumbnail, 'Thumbnails'>, ratio: ThumbnailAspectRatio, maxWidth?: number) {+ if (!this.Thumbnails) return []++ return this.Thumbnails.filter(t => t.aspectRatio === ratio && (!maxWidth || t.width <= maxWidth))+ }+// ---------------------------------------------------------------------------isLocal (this: MVideoOwned) {diff --git a/server/core/types/models/abuse/abuse.ts b/server/core/types/models/abuse/abuse.tsindex 94100f1e4a..fd57fd05fc 100644--- a/server/core/types/models/abuse/abuse.ts+++ b/server/core/types/models/abuse/abuse.ts@@ -52,6 +52,7 @@ export type MVideoAbuseFormattable =| 'Thumbnails'| 'getSmallestThumbnail'| 'getSmallestThumbnailStaticPath'+ | 'filterThumbnails'>>diff --git a/server/scripts/regenerate-thumbnails.ts b/server/scripts/regenerate-thumbnails.tsindex 17ae455f88..cf76a9ee9a 100644--- a/server/scripts/regenerate-thumbnails.ts+++ b/server/scripts/regenerate-thumbnails.ts@@ -31,7 +31,7 @@ async function processVideo (id: number) {console.log('Processing video %s.', video.name)- const bestImage = video.getBestThumbnail()+ const bestImage = video.getBestThumbnail('16:9')if (!await pathExists(bestImage.getFSPath())) {throw new Error(`Thumbnail ${bestImage.getFSPath()} does not exist on disk`)@@ -44,6 +44,7 @@ async function processVideo (id: number) {filename: generateImageFilename(),height: size.height,width: size.width,+ aspectRatio: size.aspectRatio,fileUrl: null,automaticallyGenerated: bestImage.automaticallyGenerated,cached: falsediff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yamlindex e1e00f62af..6130b81833 100644--- a/support/doc/api/openapi.yaml+++ b/support/doc/api/openapi.yaml@@ -8908,6 +8908,9 @@ components:type: integerheight:type: integer+ aspectRatio:+ type: string+ example: '16:9'VideoFile:properties:id: