aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue')
-rw-r--r--server/lib/job-queue/handlers/video-live-ending.ts12
-rw-r--r--server/lib/job-queue/handlers/video-transcoding.ts23
2 files changed, 12 insertions, 23 deletions
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts
index cd5bb1d1c..32eeff4d1 100644
--- a/server/lib/job-queue/handlers/video-live-ending.ts
+++ b/server/lib/job-queue/handlers/video-live-ending.ts
@@ -1,7 +1,8 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { readdir, remove } from 'fs-extra' 2import { readdir, remove } from 'fs-extra'
3import { join } from 'path' 3import { join } from 'path'
4import { getVideoFileResolution, hlsPlaylistToFragmentedMP4 } from '@server/helpers/ffmpeg-utils' 4import { getDurationFromVideoFile, getVideoFileResolution, hlsPlaylistToFragmentedMP4 } from '@server/helpers/ffmpeg-utils'
5import { publishAndFederateIfNeeded } from '@server/lib/video'
5import { getHLSDirectory } from '@server/lib/video-paths' 6import { getHLSDirectory } from '@server/lib/video-paths'
6import { generateHlsPlaylist } from '@server/lib/video-transcoding' 7import { generateHlsPlaylist } from '@server/lib/video-transcoding'
7import { VideoModel } from '@server/models/video/video' 8import { VideoModel } from '@server/models/video/video'
@@ -44,6 +45,7 @@ async function saveLive (video: MVideo, live: MVideoLive) {
44 45
45 const playlistFiles = files.filter(f => f.endsWith('.m3u8') && f !== 'master.m3u8') 46 const playlistFiles = files.filter(f => f.endsWith('.m3u8') && f !== 'master.m3u8')
46 const resolutions: number[] = [] 47 const resolutions: number[] = []
48 let duration: number
47 49
48 for (const playlistFile of playlistFiles) { 50 for (const playlistFile of playlistFiles) {
49 const playlistPath = join(hlsDirectory, playlistFile) 51 const playlistPath = join(hlsDirectory, playlistFile)
@@ -58,6 +60,10 @@ async function saveLive (video: MVideo, live: MVideoLive) {
58 const segmentFiles = files.filter(f => f.startsWith(shouldStartWith) && f.endsWith('.ts')) 60 const segmentFiles = files.filter(f => f.startsWith(shouldStartWith) && f.endsWith('.ts'))
59 await hlsPlaylistToFragmentedMP4(hlsDirectory, segmentFiles, mp4TmpName) 61 await hlsPlaylistToFragmentedMP4(hlsDirectory, segmentFiles, mp4TmpName)
60 62
63 if (!duration) {
64 duration = await getDurationFromVideoFile(mp4TmpName)
65 }
66
61 resolutions.push(videoFileResolution) 67 resolutions.push(videoFileResolution)
62 } 68 }
63 69
@@ -67,6 +73,8 @@ async function saveLive (video: MVideo, live: MVideoLive) {
67 73
68 video.isLive = false 74 video.isLive = false
69 video.state = VideoState.TO_TRANSCODE 75 video.state = VideoState.TO_TRANSCODE
76 video.duration = duration
77
70 await video.save() 78 await video.save()
71 79
72 const videoWithFiles = await VideoModel.loadWithFiles(video.id) 80 const videoWithFiles = await VideoModel.loadWithFiles(video.id)
@@ -86,6 +94,8 @@ async function saveLive (video: MVideo, live: MVideoLive) {
86 94
87 video.state = VideoState.PUBLISHED 95 video.state = VideoState.PUBLISHED
88 await video.save() 96 await video.save()
97
98 await publishAndFederateIfNeeded(video)
89} 99}
90 100
91async function cleanupLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) { 101async function cleanupLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts
index 2aebc29f7..843a9f1b5 100644
--- a/server/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/lib/job-queue/handlers/video-transcoding.ts
@@ -1,4 +1,5 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { publishAndFederateIfNeeded } from '@server/lib/video'
2import { getVideoFilePath } from '@server/lib/video-paths' 3import { getVideoFilePath } from '@server/lib/video-paths'
3import { MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/types/models' 4import { MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/types/models'
4import { 5import {
@@ -174,25 +175,3 @@ function createHlsJobIfEnabled (payload?: { videoUUID: string, resolution: numbe
174 return JobQueue.Instance.createJob({ type: 'video-transcoding', payload: hlsTranscodingPayload }) 175 return JobQueue.Instance.createJob({ type: 'video-transcoding', payload: hlsTranscodingPayload })
175 } 176 }
176} 177}
177
178async function publishAndFederateIfNeeded (video: MVideoUUID) {
179 const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => {
180 // Maybe the video changed in database, refresh it
181 const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
182 // Video does not exist anymore
183 if (!videoDatabase) return undefined
184
185 // We transcoded the video file in another format, now we can publish it
186 const videoPublished = await videoDatabase.publishIfNeededAndSave(t)
187
188 // If the video was not published, we consider it is a new one for other instances
189 await federateVideoIfNeeded(videoDatabase, videoPublished, t)
190
191 return { videoDatabase, videoPublished }
192 })
193
194 if (videoPublished) {
195 Notifier.Instance.notifyOnNewVideoIfNeeded(videoDatabase)
196 Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(videoDatabase)
197 }
198}