]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/video-live-ending.ts
Split ffmpeg utils with ffprobe utils
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / video-live-ending.ts
index 3892260c46ca6c3ee827c9a71206e445e06725de..447744224bea38e224dafdf087974659eea528a6 100644 (file)
@@ -1,7 +1,9 @@
 import * as Bull from 'bull'
 import { readdir, remove } from 'fs-extra'
 import { join } from 'path'
-import { getDurationFromVideoFile, getVideoFileResolution, hlsPlaylistToFragmentedMP4 } from '@server/helpers/ffmpeg-utils'
+import { hlsPlaylistToFragmentedMP4 } from '@server/helpers/ffmpeg-utils'
+import { getDurationFromVideoFile, getVideoFileResolution } from '@server/helpers/ffprobe-utils'
+import { generateVideoMiniature } from '@server/lib/thumbnail'
 import { publishAndFederateIfNeeded } from '@server/lib/video'
 import { getHLSDirectory } from '@server/lib/video-paths'
 import { generateHlsPlaylist } from '@server/lib/video-transcoding'
@@ -10,7 +12,7 @@ import { VideoFileModel } from '@server/models/video/video-file'
 import { VideoLiveModel } from '@server/models/video/video-live'
 import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
 import { MStreamingPlaylist, MVideo, MVideoLive } from '@server/types/models'
-import { VideoLiveEndingPayload, VideoState } from '@shared/models'
+import { ThumbnailType, VideoLiveEndingPayload, VideoState } from '@shared/models'
 import { logger } from '../../../helpers/logger'
 
 async function processVideoLiveEnding (job: Bull.Job) {
@@ -82,6 +84,8 @@ async function saveLive (video: MVideo, live: MVideoLive) {
   await live.destroy()
 
   video.isLive = false
+  // Reinit views
+  video.views = 0
   video.state = VideoState.TO_TRANSCODE
   video.duration = duration
 
@@ -109,11 +113,20 @@ async function saveLive (video: MVideo, live: MVideoLive) {
     await remove(videoInputPath)
   }
 
+  // Regenerate the thumbnail & preview?
+  if (videoWithFiles.getMiniature().automaticallyGenerated === true) {
+    await generateVideoMiniature(videoWithFiles, videoWithFiles.getMaxQualityFile(), ThumbnailType.MINIATURE)
+  }
+
+  if (videoWithFiles.getPreview().automaticallyGenerated === true) {
+    await generateVideoMiniature(videoWithFiles, videoWithFiles.getMaxQualityFile(), ThumbnailType.PREVIEW)
+  }
+
   await publishAndFederateIfNeeded(video, true)
 }
 
 async function cleanupLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
-  const hlsDirectory = getHLSDirectory(video, false)
+  const hlsDirectory = getHLSDirectory(video)
 
   await remove(hlsDirectory)