aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/transcoding
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-25 10:57:16 +0200
committerChocobozzz <me@florianbigard.com>2022-07-25 10:57:16 +0200
commit7b6b445d91d3f0bcbb526cb1e8c1f26b96f0a971 (patch)
tree1bc9724411941e0082243164d6cc53d02902b1f7 /server/lib/transcoding
parent4f50475c67356fb1fecd1de6d2551fdc5ad9a739 (diff)
downloadPeerTube-7b6b445d91d3f0bcbb526cb1e8c1f26b96f0a971.tar.gz
PeerTube-7b6b445d91d3f0bcbb526cb1e8c1f26b96f0a971.tar.zst
PeerTube-7b6b445d91d3f0bcbb526cb1e8c1f26b96f0a971.zip
Regenerate video filenames on transcoding
In particular when using manual transcoding, to invalidate potential HTTP caches in front of peertube
Diffstat (limited to 'server/lib/transcoding')
-rw-r--r--server/lib/transcoding/transcoding.ts28
1 files changed, 18 insertions, 10 deletions
diff --git a/server/lib/transcoding/transcoding.ts b/server/lib/transcoding/transcoding.ts
index b64ce6e1f..69a973fbd 100644
--- a/server/lib/transcoding/transcoding.ts
+++ b/server/lib/transcoding/transcoding.ts
@@ -2,7 +2,9 @@ import { Job } from 'bull'
2import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' 2import { copyFile, ensureDir, move, remove, stat } from 'fs-extra'
3import { basename, extname as extnameUtil, join } from 'path' 3import { basename, extname as extnameUtil, join } from 'path'
4import { toEven } from '@server/helpers/core-utils' 4import { toEven } from '@server/helpers/core-utils'
5import { retryTransactionWrapper } from '@server/helpers/database-utils'
5import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 6import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
7import { sequelizeTypescript } from '@server/initializers/database'
6import { MStreamingPlaylistFilesVideo, MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' 8import { MStreamingPlaylistFilesVideo, MVideo, MVideoFile, MVideoFullLight } from '@server/types/models'
7import { VideoResolution, VideoStorage } from '../../../shared/models/videos' 9import { VideoResolution, VideoStorage } from '../../../shared/models/videos'
8import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 10import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
@@ -29,8 +31,6 @@ import {
29} from '../paths' 31} from '../paths'
30import { VideoPathManager } from '../video-path-manager' 32import { VideoPathManager } from '../video-path-manager'
31import { VideoTranscodingProfilesManager } from './default-transcoding-profiles' 33import { VideoTranscodingProfilesManager } from './default-transcoding-profiles'
32import { retryTransactionWrapper } from '@server/helpers/database-utils'
33import { sequelizeTypescript } from '@server/initializers/database'
34 34
35/** 35/**
36 * 36 *
@@ -259,6 +259,9 @@ async function onWebTorrentVideoFileTranscoding (
259 259
260 await createTorrentAndSetInfoHash(video, videoFile) 260 await createTorrentAndSetInfoHash(video, videoFile)
261 261
262 const oldFile = await VideoFileModel.loadWebTorrentFile({ videoId: video.id, fps: videoFile.fps, resolution: videoFile.resolution })
263 if (oldFile) await video.removeWebTorrentFileAndTorrent(oldFile)
264
262 await VideoFileModel.customUpsert(videoFile, 'video', undefined) 265 await VideoFileModel.customUpsert(videoFile, 'video', undefined)
263 video.VideoFiles = await video.$get('VideoFiles') 266 video.VideoFiles = await video.$get('VideoFiles')
264 267
@@ -311,17 +314,15 @@ async function generateHlsPlaylistCommon (options: {
311 await transcodeVOD(transcodeOptions) 314 await transcodeVOD(transcodeOptions)
312 315
313 // Create or update the playlist 316 // Create or update the playlist
314 const playlist = await retryTransactionWrapper(() => { 317 const { playlist, oldPlaylistFilename, oldSegmentsSha256Filename } = await retryTransactionWrapper(() => {
315 return sequelizeTypescript.transaction(async transaction => { 318 return sequelizeTypescript.transaction(async transaction => {
316 const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video, transaction) 319 const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video, transaction)
317 320
318 if (!playlist.playlistFilename) { 321 const oldPlaylistFilename = playlist.playlistFilename
319 playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive) 322 const oldSegmentsSha256Filename = playlist.segmentsSha256Filename
320 }
321 323
322 if (!playlist.segmentsSha256Filename) { 324 playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive)
323 playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(video.isLive) 325 playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(video.isLive)
324 }
325 326
326 playlist.p2pMediaLoaderInfohashes = [] 327 playlist.p2pMediaLoaderInfohashes = []
327 playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION 328 playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION
@@ -330,10 +331,13 @@ async function generateHlsPlaylistCommon (options: {
330 331
331 await playlist.save({ transaction }) 332 await playlist.save({ transaction })
332 333
333 return playlist 334 return { playlist, oldPlaylistFilename, oldSegmentsSha256Filename }
334 }) 335 })
335 }) 336 })
336 337
338 if (oldPlaylistFilename) await video.removeStreamingPlaylistFile(playlist, oldPlaylistFilename)
339 if (oldSegmentsSha256Filename) await video.removeStreamingPlaylistFile(playlist, oldSegmentsSha256Filename)
340
337 // Build the new playlist file 341 // Build the new playlist file
338 const extname = extnameUtil(videoFilename) 342 const extname = extnameUtil(videoFilename)
339 const newVideoFile = new VideoFileModel({ 343 const newVideoFile = new VideoFileModel({
@@ -364,11 +368,15 @@ async function generateHlsPlaylistCommon (options: {
364 368
365 await createTorrentAndSetInfoHash(playlist, newVideoFile) 369 await createTorrentAndSetInfoHash(playlist, newVideoFile)
366 370
371 const oldFile = await VideoFileModel.loadHLSFile({ playlistId: playlist.id, fps: newVideoFile.fps, resolution: newVideoFile.resolution })
372 if (oldFile) await video.removeStreamingPlaylistVideoFile(playlist, oldFile)
373
367 const savedVideoFile = await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined) 374 const savedVideoFile = await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined)
368 375
369 const playlistWithFiles = playlist as MStreamingPlaylistFilesVideo 376 const playlistWithFiles = playlist as MStreamingPlaylistFilesVideo
370 playlistWithFiles.VideoFiles = await playlist.$get('VideoFiles') 377 playlistWithFiles.VideoFiles = await playlist.$get('VideoFiles')
371 playlist.assignP2PMediaLoaderInfoHashes(video, playlistWithFiles.VideoFiles) 378 playlist.assignP2PMediaLoaderInfoHashes(video, playlistWithFiles.VideoFiles)
379 playlist.storage = VideoStorage.FILE_SYSTEM
372 380
373 await playlist.save() 381 await playlist.save()
374 382