diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-06 10:57:40 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | 053aed43fb255b4ae4324a845534f2f562c3b6cc (patch) | |
tree | 04cae6af371a1ee869051c67be28acea5581d16d /server/lib | |
parent | 3bc68dfd6183078fb56b53e24e74f889c85c4ae0 (diff) | |
download | PeerTube-053aed43fb255b4ae4324a845534f2f562c3b6cc.tar.gz PeerTube-053aed43fb255b4ae4324a845534f2f562c3b6cc.tar.zst PeerTube-053aed43fb255b4ae4324a845534f2f562c3b6cc.zip |
Regenerate miniature on live save
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/videos.ts | 7 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-live-ending.ts | 12 | ||||
-rw-r--r-- | server/lib/live-manager.ts | 8 | ||||
-rw-r--r-- | server/lib/video-paths.ts | 4 | ||||
-rw-r--r-- | server/lib/video-transcoding.ts | 17 | ||||
-rw-r--r-- | server/lib/video.ts | 2 |
6 files changed, 31 insertions, 19 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index ab4aac0a1..4053f487c 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import { VideoLiveModel } from '@server/models/video/video-live' | ||
2 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
3 | import { maxBy, minBy } from 'lodash' | 2 | import { maxBy, minBy } from 'lodash' |
4 | import * as magnetUtil from 'magnet-uri' | 3 | import * as magnetUtil from 'magnet-uri' |
5 | import { join } from 'path' | 4 | import { join } from 'path' |
6 | import * as request from 'request' | 5 | import * as request from 'request' |
7 | import * as sequelize from 'sequelize' | 6 | import * as sequelize from 'sequelize' |
7 | import { VideoLiveModel } from '@server/models/video/video-live' | ||
8 | import { | 8 | import { |
9 | ActivityHashTagObject, | 9 | ActivityHashTagObject, |
10 | ActivityMagnetUrlObject, | 10 | ActivityMagnetUrlObject, |
@@ -13,8 +13,7 @@ import { | |||
13 | ActivitypubHttpFetcherPayload, | 13 | ActivitypubHttpFetcherPayload, |
14 | ActivityTagObject, | 14 | ActivityTagObject, |
15 | ActivityUrlObject, | 15 | ActivityUrlObject, |
16 | ActivityVideoUrlObject, | 16 | ActivityVideoUrlObject |
17 | VideoState | ||
18 | } from '../../../shared/index' | 17 | } from '../../../shared/index' |
19 | import { VideoObject } from '../../../shared/models/activitypub/objects' | 18 | import { VideoObject } from '../../../shared/models/activitypub/objects' |
20 | import { VideoPrivacy } from '../../../shared/models/videos' | 19 | import { VideoPrivacy } from '../../../shared/models/videos' |
@@ -562,8 +561,6 @@ function isAPHashTagObject (url: any): url is ActivityHashTagObject { | |||
562 | return url && url.type === 'Hashtag' | 561 | return url && url.type === 'Hashtag' |
563 | } | 562 | } |
564 | 563 | ||
565 | |||
566 | |||
567 | async function createVideo (videoObject: VideoObject, channel: MChannelAccountLight, waitThumbnail = false) { | 564 | async function createVideo (videoObject: VideoObject, channel: MChannelAccountLight, waitThumbnail = false) { |
568 | logger.debug('Adding remote video %s.', videoObject.id) | 565 | logger.debug('Adding remote video %s.', videoObject.id) |
569 | 566 | ||
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts index 3892260c4..3d9341738 100644 --- a/server/lib/job-queue/handlers/video-live-ending.ts +++ b/server/lib/job-queue/handlers/video-live-ending.ts | |||
@@ -10,8 +10,9 @@ import { VideoFileModel } from '@server/models/video/video-file' | |||
10 | import { VideoLiveModel } from '@server/models/video/video-live' | 10 | import { VideoLiveModel } from '@server/models/video/video-live' |
11 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' | 11 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' |
12 | import { MStreamingPlaylist, MVideo, MVideoLive } from '@server/types/models' | 12 | import { MStreamingPlaylist, MVideo, MVideoLive } from '@server/types/models' |
13 | import { VideoLiveEndingPayload, VideoState } from '@shared/models' | 13 | import { ThumbnailType, VideoLiveEndingPayload, VideoState } from '@shared/models' |
14 | import { logger } from '../../../helpers/logger' | 14 | import { logger } from '../../../helpers/logger' |
15 | import { generateVideoMiniature } from '@server/lib/thumbnail' | ||
15 | 16 | ||
16 | async function processVideoLiveEnding (job: Bull.Job) { | 17 | async function processVideoLiveEnding (job: Bull.Job) { |
17 | const payload = job.data as VideoLiveEndingPayload | 18 | const payload = job.data as VideoLiveEndingPayload |
@@ -109,6 +110,15 @@ async function saveLive (video: MVideo, live: MVideoLive) { | |||
109 | await remove(videoInputPath) | 110 | await remove(videoInputPath) |
110 | } | 111 | } |
111 | 112 | ||
113 | // Regenerate the thumbnail & preview? | ||
114 | if (videoWithFiles.getMiniature().automaticallyGenerated === true) { | ||
115 | await generateVideoMiniature(videoWithFiles, videoWithFiles.getMaxQualityFile(), ThumbnailType.MINIATURE) | ||
116 | } | ||
117 | |||
118 | if (videoWithFiles.getPreview().automaticallyGenerated === true) { | ||
119 | await generateVideoMiniature(videoWithFiles, videoWithFiles.getMaxQualityFile(), ThumbnailType.PREVIEW) | ||
120 | } | ||
121 | |||
112 | await publishAndFederateIfNeeded(video, true) | 122 | await publishAndFederateIfNeeded(video, true) |
113 | } | 123 | } |
114 | 124 | ||
diff --git a/server/lib/live-manager.ts b/server/lib/live-manager.ts index d253d06fc..9a2914cc5 100644 --- a/server/lib/live-manager.ts +++ b/server/lib/live-manager.ts | |||
@@ -4,7 +4,13 @@ import * as chokidar from 'chokidar' | |||
4 | import { FfmpegCommand } from 'fluent-ffmpeg' | 4 | import { FfmpegCommand } from 'fluent-ffmpeg' |
5 | import { ensureDir, stat } from 'fs-extra' | 5 | import { ensureDir, stat } from 'fs-extra' |
6 | import { basename } from 'path' | 6 | import { basename } from 'path' |
7 | import { computeResolutionsToTranscode, getVideoFileFPS, getVideoFileResolution, getVideoStreamCodec, getVideoStreamSize, runLiveMuxing, runLiveTranscoding } from '@server/helpers/ffmpeg-utils' | 7 | import { |
8 | computeResolutionsToTranscode, | ||
9 | getVideoFileFPS, | ||
10 | getVideoFileResolution, | ||
11 | runLiveMuxing, | ||
12 | runLiveTranscoding | ||
13 | } from '@server/helpers/ffmpeg-utils' | ||
8 | import { logger } from '@server/helpers/logger' | 14 | import { logger } from '@server/helpers/logger' |
9 | import { CONFIG, registerConfigChangedHandler } from '@server/initializers/config' | 15 | import { CONFIG, registerConfigChangedHandler } from '@server/initializers/config' |
10 | import { MEMOIZE_TTL, P2P_MEDIA_LOADER_PEER_VERSION, VIDEO_LIVE, WEBSERVER } from '@server/initializers/constants' | 16 | import { MEMOIZE_TTL, P2P_MEDIA_LOADER_PEER_VERSION, VIDEO_LIVE, WEBSERVER } from '@server/initializers/constants' |
diff --git a/server/lib/video-paths.ts b/server/lib/video-paths.ts index b6cb39d25..53fc8e81d 100644 --- a/server/lib/video-paths.ts +++ b/server/lib/video-paths.ts | |||
@@ -9,7 +9,7 @@ import { extractVideo } from '@server/helpers/video' | |||
9 | function getVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { | 9 | function getVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { |
10 | const video = extractVideo(videoOrPlaylist) | 10 | const video = extractVideo(videoOrPlaylist) |
11 | 11 | ||
12 | if (isStreamingPlaylist(videoOrPlaylist)) { | 12 | if (videoFile.isHLS()) { |
13 | return generateVideoStreamingPlaylistName(video.uuid, videoFile.resolution) | 13 | return generateVideoStreamingPlaylistName(video.uuid, videoFile.resolution) |
14 | } | 14 | } |
15 | 15 | ||
@@ -25,7 +25,7 @@ function generateWebTorrentVideoName (uuid: string, resolution: number, extname: | |||
25 | } | 25 | } |
26 | 26 | ||
27 | function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { | 27 | function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { |
28 | if (isStreamingPlaylist(videoOrPlaylist)) { | 28 | if (videoFile.isHLS()) { |
29 | const video = extractVideo(videoOrPlaylist) | 29 | const video = extractVideo(videoOrPlaylist) |
30 | 30 | ||
31 | return join(getHLSDirectory(video), getVideoFilename(videoOrPlaylist, videoFile)) | 31 | return join(getHLSDirectory(video), getVideoFilename(videoOrPlaylist, videoFile)) |
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index c62b3c1ce..e267b1397 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts | |||
@@ -1,5 +1,9 @@ | |||
1 | import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers/constants' | 1 | import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' |
2 | import { basename, extname as extnameUtil, join } from 'path' | 2 | import { basename, extname as extnameUtil, join } from 'path' |
3 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | ||
4 | import { MStreamingPlaylistFilesVideo, MVideoFile, MVideoWithAllFiles, MVideoWithFile } from '@server/types/models' | ||
5 | import { VideoResolution } from '../../shared/models/videos' | ||
6 | import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type' | ||
3 | import { | 7 | import { |
4 | canDoQuickTranscode, | 8 | canDoQuickTranscode, |
5 | getDurationFromVideoFile, | 9 | getDurationFromVideoFile, |
@@ -9,18 +13,13 @@ import { | |||
9 | TranscodeOptions, | 13 | TranscodeOptions, |
10 | TranscodeOptionsType | 14 | TranscodeOptionsType |
11 | } from '../helpers/ffmpeg-utils' | 15 | } from '../helpers/ffmpeg-utils' |
12 | import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' | ||
13 | import { logger } from '../helpers/logger' | 16 | import { logger } from '../helpers/logger' |
14 | import { VideoResolution } from '../../shared/models/videos' | 17 | import { CONFIG } from '../initializers/config' |
18 | import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers/constants' | ||
15 | import { VideoFileModel } from '../models/video/video-file' | 19 | import { VideoFileModel } from '../models/video/video-file' |
16 | import { updateMasterHLSPlaylist, updateSha256VODSegments } from './hls' | ||
17 | import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' | 20 | import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' |
18 | import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type' | 21 | import { updateMasterHLSPlaylist, updateSha256VODSegments } from './hls' |
19 | import { CONFIG } from '../initializers/config' | ||
20 | import { MStreamingPlaylistFilesVideo, MVideoFile, MVideoWithAllFiles, MVideoWithFile } from '@server/types/models' | ||
21 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | ||
22 | import { generateVideoStreamingPlaylistName, getVideoFilename, getVideoFilePath } from './video-paths' | 22 | import { generateVideoStreamingPlaylistName, getVideoFilename, getVideoFilePath } from './video-paths' |
23 | import { spawn } from 'child_process' | ||
24 | 23 | ||
25 | /** | 24 | /** |
26 | * Optimize the original video file and replace it. The resolution is not changed. | 25 | * Optimize the original video file and replace it. The resolution is not changed. |
diff --git a/server/lib/video.ts b/server/lib/video.ts index 8d9918b2d..d03ab0452 100644 --- a/server/lib/video.ts +++ b/server/lib/video.ts | |||
@@ -4,7 +4,7 @@ import { TagModel } from '@server/models/video/tag' | |||
4 | import { VideoModel } from '@server/models/video/video' | 4 | import { VideoModel } from '@server/models/video/video' |
5 | import { FilteredModelAttributes } from '@server/types' | 5 | import { FilteredModelAttributes } from '@server/types' |
6 | import { MTag, MThumbnail, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' | 6 | import { MTag, MThumbnail, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' |
7 | import { ThumbnailType, VideoCreate, VideoPrivacy, VideoState } from '@shared/models' | 7 | import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models' |
8 | import { federateVideoIfNeeded } from './activitypub/videos' | 8 | import { federateVideoIfNeeded } from './activitypub/videos' |
9 | import { Notifier } from './notifier' | 9 | import { Notifier } from './notifier' |
10 | import { createVideoMiniatureFromExisting } from './thumbnail' | 10 | import { createVideoMiniatureFromExisting } from './thumbnail' |