+ await live.destroy()
+
+ video.isLive = false
+ video.state = VideoState.TO_TRANSCODE
+ video.duration = duration
+
+ await video.save()
+
+ // Remove old HLS playlist video files
+ const videoWithFiles = await VideoModel.loadWithFiles(video.id)
+
+ const hlsPlaylist = videoWithFiles.getHLSPlaylist()
+ await VideoFileModel.removeHLSFilesOfVideoId(hlsPlaylist.id)
+ hlsPlaylist.VideoFiles = []
+
+ for (const resolution of resolutions) {
+ const videoInputPath = buildMP4TmpPath(hlsDirectory, resolution)
+ const { isPortraitMode } = await getVideoFileResolution(videoInputPath)
+
+ await generateHlsPlaylist({
+ video: videoWithFiles,
+ videoInputPath,
+ resolution: resolution,
+ copyCodecs: true,
+ isPortraitMode
+ })
+
+ 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)
+
+ await remove(hlsDirectory)
+
+ streamingPlaylist.destroy()
+ .catch(err => logger.error('Cannot remove live streaming playlist.', { err }))
+}
+
+async function cleanupLiveFiles (hlsDirectory: string) {