aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/transcoding
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/transcoding')
-rw-r--r--server/lib/transcoding/transcoding.ts61
1 files changed, 12 insertions, 49 deletions
diff --git a/server/lib/transcoding/transcoding.ts b/server/lib/transcoding/transcoding.ts
index 69a973fbd..924141d1c 100644
--- a/server/lib/transcoding/transcoding.ts
+++ b/server/lib/transcoding/transcoding.ts
@@ -5,9 +5,8 @@ import { toEven } from '@server/helpers/core-utils'
5import { retryTransactionWrapper } from '@server/helpers/database-utils' 5import { retryTransactionWrapper } from '@server/helpers/database-utils'
6import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 6import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
7import { sequelizeTypescript } from '@server/initializers/database' 7import { sequelizeTypescript } from '@server/initializers/database'
8import { MStreamingPlaylistFilesVideo, MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' 8import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models'
9import { VideoResolution, VideoStorage } from '../../../shared/models/videos' 9import { VideoResolution, VideoStorage } from '../../../shared/models/videos'
10import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
11import { 10import {
12 buildFileMetadata, 11 buildFileMetadata,
13 canDoQuickTranscode, 12 canDoQuickTranscode,
@@ -18,17 +17,10 @@ import {
18 TranscodeVODOptionsType 17 TranscodeVODOptionsType
19} from '../../helpers/ffmpeg' 18} from '../../helpers/ffmpeg'
20import { CONFIG } from '../../initializers/config' 19import { CONFIG } from '../../initializers/config'
21import { P2P_MEDIA_LOADER_PEER_VERSION } from '../../initializers/constants'
22import { VideoFileModel } from '../../models/video/video-file' 20import { VideoFileModel } from '../../models/video/video-file'
23import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist' 21import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist'
24import { updateMasterHLSPlaylist, updateSha256VODSegments } from '../hls' 22import { updatePlaylistAfterFileChange } from '../hls'
25import { 23import { generateHLSVideoFilename, generateWebTorrentVideoFilename, getHlsResolutionPlaylistFilename } from '../paths'
26 generateHLSMasterPlaylistFilename,
27 generateHlsSha256SegmentsFilename,
28 generateHLSVideoFilename,
29 generateWebTorrentVideoFilename,
30 getHlsResolutionPlaylistFilename
31} from '../paths'
32import { VideoPathManager } from '../video-path-manager' 24import { VideoPathManager } from '../video-path-manager'
33import { VideoTranscodingProfilesManager } from './default-transcoding-profiles' 25import { VideoTranscodingProfilesManager } from './default-transcoding-profiles'
34 26
@@ -260,7 +252,7 @@ async function onWebTorrentVideoFileTranscoding (
260 await createTorrentAndSetInfoHash(video, videoFile) 252 await createTorrentAndSetInfoHash(video, videoFile)
261 253
262 const oldFile = await VideoFileModel.loadWebTorrentFile({ videoId: video.id, fps: videoFile.fps, resolution: videoFile.resolution }) 254 const oldFile = await VideoFileModel.loadWebTorrentFile({ videoId: video.id, fps: videoFile.fps, resolution: videoFile.resolution })
263 if (oldFile) await video.removeWebTorrentFileAndTorrent(oldFile) 255 if (oldFile) await video.removeWebTorrentFile(oldFile)
264 256
265 await VideoFileModel.customUpsert(videoFile, 'video', undefined) 257 await VideoFileModel.customUpsert(videoFile, 'video', undefined)
266 video.VideoFiles = await video.$get('VideoFiles') 258 video.VideoFiles = await video.$get('VideoFiles')
@@ -314,35 +306,15 @@ async function generateHlsPlaylistCommon (options: {
314 await transcodeVOD(transcodeOptions) 306 await transcodeVOD(transcodeOptions)
315 307
316 // Create or update the playlist 308 // Create or update the playlist
317 const { playlist, oldPlaylistFilename, oldSegmentsSha256Filename } = await retryTransactionWrapper(() => { 309 const playlist = await retryTransactionWrapper(() => {
318 return sequelizeTypescript.transaction(async transaction => { 310 return sequelizeTypescript.transaction(async transaction => {
319 const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video, transaction) 311 return VideoStreamingPlaylistModel.loadOrGenerate(video, transaction)
320
321 const oldPlaylistFilename = playlist.playlistFilename
322 const oldSegmentsSha256Filename = playlist.segmentsSha256Filename
323
324 playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive)
325 playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(video.isLive)
326
327 playlist.p2pMediaLoaderInfohashes = []
328 playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION
329
330 playlist.type = VideoStreamingPlaylistType.HLS
331
332 await playlist.save({ transaction })
333
334 return { playlist, oldPlaylistFilename, oldSegmentsSha256Filename }
335 }) 312 })
336 }) 313 })
337 314
338 if (oldPlaylistFilename) await video.removeStreamingPlaylistFile(playlist, oldPlaylistFilename)
339 if (oldSegmentsSha256Filename) await video.removeStreamingPlaylistFile(playlist, oldSegmentsSha256Filename)
340
341 // Build the new playlist file
342 const extname = extnameUtil(videoFilename)
343 const newVideoFile = new VideoFileModel({ 315 const newVideoFile = new VideoFileModel({
344 resolution, 316 resolution,
345 extname, 317 extname: extnameUtil(videoFilename),
346 size: 0, 318 size: 0,
347 filename: videoFilename, 319 filename: videoFilename,
348 fps: -1, 320 fps: -1,
@@ -350,8 +322,6 @@ async function generateHlsPlaylistCommon (options: {
350 }) 322 })
351 323
352 const videoFilePath = VideoPathManager.Instance.getFSVideoFileOutputPath(playlist, newVideoFile) 324 const videoFilePath = VideoPathManager.Instance.getFSVideoFileOutputPath(playlist, newVideoFile)
353
354 // Move files from tmp transcoded directory to the appropriate place
355 await ensureDir(VideoPathManager.Instance.getFSHLSOutputPath(video)) 325 await ensureDir(VideoPathManager.Instance.getFSHLSOutputPath(video))
356 326
357 // Move playlist file 327 // Move playlist file
@@ -369,21 +339,14 @@ async function generateHlsPlaylistCommon (options: {
369 await createTorrentAndSetInfoHash(playlist, newVideoFile) 339 await createTorrentAndSetInfoHash(playlist, newVideoFile)
370 340
371 const oldFile = await VideoFileModel.loadHLSFile({ playlistId: playlist.id, fps: newVideoFile.fps, resolution: newVideoFile.resolution }) 341 const oldFile = await VideoFileModel.loadHLSFile({ playlistId: playlist.id, fps: newVideoFile.fps, resolution: newVideoFile.resolution })
372 if (oldFile) await video.removeStreamingPlaylistVideoFile(playlist, oldFile) 342 if (oldFile) {
343 await video.removeStreamingPlaylistVideoFile(playlist, oldFile)
344 await oldFile.destroy()
345 }
373 346
374 const savedVideoFile = await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined) 347 const savedVideoFile = await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined)
375 348
376 const playlistWithFiles = playlist as MStreamingPlaylistFilesVideo 349 await updatePlaylistAfterFileChange(video, playlist)
377 playlistWithFiles.VideoFiles = await playlist.$get('VideoFiles')
378 playlist.assignP2PMediaLoaderInfoHashes(video, playlistWithFiles.VideoFiles)
379 playlist.storage = VideoStorage.FILE_SYSTEM
380
381 await playlist.save()
382
383 video.setHLSPlaylist(playlist)
384
385 await updateMasterHLSPlaylist(video, playlistWithFiles)
386 await updateSha256VODSegments(video, playlistWithFiles)
387 350
388 return { resolutionPlaylistPath, videoFile: savedVideoFile } 351 return { resolutionPlaylistPath, videoFile: savedVideoFile }
389} 352}