diff options
Diffstat (limited to 'server/lib/transcoding/web-transcoding.ts')
-rw-r--r-- | server/lib/transcoding/web-transcoding.ts | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/server/lib/transcoding/web-transcoding.ts b/server/lib/transcoding/web-transcoding.ts index 7cc8f20bc..f92d457a0 100644 --- a/server/lib/transcoding/web-transcoding.ts +++ b/server/lib/transcoding/web-transcoding.ts | |||
@@ -9,7 +9,8 @@ import { ffprobePromise, getVideoStreamDuration, getVideoStreamFPS, TranscodeVOD | |||
9 | import { VideoResolution, VideoStorage } from '@shared/models' | 9 | import { VideoResolution, VideoStorage } from '@shared/models' |
10 | import { CONFIG } from '../../initializers/config' | 10 | import { CONFIG } from '../../initializers/config' |
11 | import { VideoFileModel } from '../../models/video/video-file' | 11 | import { VideoFileModel } from '../../models/video/video-file' |
12 | import { generateWebTorrentVideoFilename } from '../paths' | 12 | import { JobQueue } from '../job-queue' |
13 | import { generateWebVideoFilename } from '../paths' | ||
13 | import { buildFileMetadata } from '../video-file' | 14 | import { buildFileMetadata } from '../video-file' |
14 | import { VideoPathManager } from '../video-path-manager' | 15 | import { VideoPathManager } from '../video-path-manager' |
15 | import { buildFFmpegVOD } from './shared' | 16 | import { buildFFmpegVOD } from './shared' |
@@ -62,10 +63,10 @@ export async function optimizeOriginalVideofile (options: { | |||
62 | // Important to do this before getVideoFilename() to take in account the new filename | 63 | // Important to do this before getVideoFilename() to take in account the new filename |
63 | inputVideoFile.resolution = resolution | 64 | inputVideoFile.resolution = resolution |
64 | inputVideoFile.extname = newExtname | 65 | inputVideoFile.extname = newExtname |
65 | inputVideoFile.filename = generateWebTorrentVideoFilename(resolution, newExtname) | 66 | inputVideoFile.filename = generateWebVideoFilename(resolution, newExtname) |
66 | inputVideoFile.storage = VideoStorage.FILE_SYSTEM | 67 | inputVideoFile.storage = VideoStorage.FILE_SYSTEM |
67 | 68 | ||
68 | const { videoFile } = await onWebTorrentVideoFileTranscoding({ | 69 | const { videoFile } = await onWebVideoFileTranscoding({ |
69 | video, | 70 | video, |
70 | videoFile: inputVideoFile, | 71 | videoFile: inputVideoFile, |
71 | videoOutputPath | 72 | videoOutputPath |
@@ -82,8 +83,8 @@ export async function optimizeOriginalVideofile (options: { | |||
82 | } | 83 | } |
83 | } | 84 | } |
84 | 85 | ||
85 | // Transcode the original video file to a lower resolution compatible with WebTorrent | 86 | // Transcode the original video file to a lower resolution compatible with web browsers |
86 | export async function transcodeNewWebTorrentResolution (options: { | 87 | export async function transcodeNewWebVideoResolution (options: { |
87 | video: MVideoFullLight | 88 | video: MVideoFullLight |
88 | resolution: VideoResolution | 89 | resolution: VideoResolution |
89 | fps: number | 90 | fps: number |
@@ -104,7 +105,7 @@ export async function transcodeNewWebTorrentResolution (options: { | |||
104 | const newVideoFile = new VideoFileModel({ | 105 | const newVideoFile = new VideoFileModel({ |
105 | resolution, | 106 | resolution, |
106 | extname: newExtname, | 107 | extname: newExtname, |
107 | filename: generateWebTorrentVideoFilename(resolution, newExtname), | 108 | filename: generateWebVideoFilename(resolution, newExtname), |
108 | size: 0, | 109 | size: 0, |
109 | videoId: video.id | 110 | videoId: video.id |
110 | }) | 111 | }) |
@@ -125,7 +126,7 @@ export async function transcodeNewWebTorrentResolution (options: { | |||
125 | 126 | ||
126 | await buildFFmpegVOD(job).transcode(transcodeOptions) | 127 | await buildFFmpegVOD(job).transcode(transcodeOptions) |
127 | 128 | ||
128 | return onWebTorrentVideoFileTranscoding({ video, videoFile: newVideoFile, videoOutputPath }) | 129 | return onWebVideoFileTranscoding({ video, videoFile: newVideoFile, videoOutputPath }) |
129 | }) | 130 | }) |
130 | 131 | ||
131 | return result | 132 | return result |
@@ -188,17 +189,18 @@ export async function mergeAudioVideofile (options: { | |||
188 | // Important to do this before getVideoFilename() to take in account the new file extension | 189 | // Important to do this before getVideoFilename() to take in account the new file extension |
189 | inputVideoFile.extname = newExtname | 190 | inputVideoFile.extname = newExtname |
190 | inputVideoFile.resolution = resolution | 191 | inputVideoFile.resolution = resolution |
191 | inputVideoFile.filename = generateWebTorrentVideoFilename(inputVideoFile.resolution, newExtname) | 192 | inputVideoFile.filename = generateWebVideoFilename(inputVideoFile.resolution, newExtname) |
192 | 193 | ||
193 | // ffmpeg generated a new video file, so update the video duration | 194 | // ffmpeg generated a new video file, so update the video duration |
194 | // See https://trac.ffmpeg.org/ticket/5456 | 195 | // See https://trac.ffmpeg.org/ticket/5456 |
195 | video.duration = await getVideoStreamDuration(videoOutputPath) | 196 | video.duration = await getVideoStreamDuration(videoOutputPath) |
196 | await video.save() | 197 | await video.save() |
197 | 198 | ||
198 | return onWebTorrentVideoFileTranscoding({ | 199 | return onWebVideoFileTranscoding({ |
199 | video, | 200 | video, |
200 | videoFile: inputVideoFile, | 201 | videoFile: inputVideoFile, |
201 | videoOutputPath | 202 | videoOutputPath, |
203 | wasAudioFile: true | ||
202 | }) | 204 | }) |
203 | }) | 205 | }) |
204 | 206 | ||
@@ -208,12 +210,13 @@ export async function mergeAudioVideofile (options: { | |||
208 | } | 210 | } |
209 | } | 211 | } |
210 | 212 | ||
211 | export async function onWebTorrentVideoFileTranscoding (options: { | 213 | export async function onWebVideoFileTranscoding (options: { |
212 | video: MVideoFullLight | 214 | video: MVideoFullLight |
213 | videoFile: MVideoFile | 215 | videoFile: MVideoFile |
214 | videoOutputPath: string | 216 | videoOutputPath: string |
217 | wasAudioFile?: boolean // default false | ||
215 | }) { | 218 | }) { |
216 | const { video, videoFile, videoOutputPath } = options | 219 | const { video, videoFile, videoOutputPath, wasAudioFile } = options |
217 | 220 | ||
218 | const mutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) | 221 | const mutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) |
219 | 222 | ||
@@ -236,12 +239,23 @@ export async function onWebTorrentVideoFileTranscoding (options: { | |||
236 | 239 | ||
237 | await createTorrentAndSetInfoHash(video, videoFile) | 240 | await createTorrentAndSetInfoHash(video, videoFile) |
238 | 241 | ||
239 | const oldFile = await VideoFileModel.loadWebTorrentFile({ videoId: video.id, fps: videoFile.fps, resolution: videoFile.resolution }) | 242 | const oldFile = await VideoFileModel.loadWebVideoFile({ videoId: video.id, fps: videoFile.fps, resolution: videoFile.resolution }) |
240 | if (oldFile) await video.removeWebTorrentFile(oldFile) | 243 | if (oldFile) await video.removeWebVideoFile(oldFile) |
241 | 244 | ||
242 | await VideoFileModel.customUpsert(videoFile, 'video', undefined) | 245 | await VideoFileModel.customUpsert(videoFile, 'video', undefined) |
243 | video.VideoFiles = await video.$get('VideoFiles') | 246 | video.VideoFiles = await video.$get('VideoFiles') |
244 | 247 | ||
248 | if (wasAudioFile) { | ||
249 | await JobQueue.Instance.createJob({ | ||
250 | type: 'generate-video-storyboard' as 'generate-video-storyboard', | ||
251 | payload: { | ||
252 | videoUUID: video.uuid, | ||
253 | // No need to federate, we process these jobs sequentially | ||
254 | federate: false | ||
255 | } | ||
256 | }) | ||
257 | } | ||
258 | |||
245 | return { video, videoFile } | 259 | return { video, videoFile } |
246 | } finally { | 260 | } finally { |
247 | mutexReleaser() | 261 | mutexReleaser() |