From 1d1da33661c6f0b42a2e5bf7fd4a0e6b9d9265cd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 18 Aug 2021 10:59:38 +0200 Subject: More robust optimize transcoding job --- server/lib/transcoding/video-transcoding.ts | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'server/lib') diff --git a/server/lib/transcoding/video-transcoding.ts b/server/lib/transcoding/video-transcoding.ts index ee228c011..250a678eb 100644 --- a/server/lib/transcoding/video-transcoding.ts +++ b/server/lib/transcoding/video-transcoding.ts @@ -8,7 +8,6 @@ import { VideoResolution, VideoStorage } from '../../../shared/models/videos' import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' import { transcode, TranscodeOptions, TranscodeOptionsType } from '../../helpers/ffmpeg-utils' import { canDoQuickTranscode, getDurationFromVideoFile, getMetadataFromFile, getVideoFileFPS } from '../../helpers/ffprobe-utils' -import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers/config' import { P2P_MEDIA_LOADER_PEER_VERSION } from '../../initializers/constants' import { VideoFileModel } from '../../models/video/video-file' @@ -62,25 +61,17 @@ function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile: MVid // Could be very long! await transcode(transcodeOptions) - try { - await remove(videoInputPath) - - // Important to do this before getVideoFilename() to take in account the new filename - inputVideoFile.extname = newExtname - inputVideoFile.filename = generateWebTorrentVideoFilename(resolution, newExtname) - inputVideoFile.storage = VideoStorage.FILE_SYSTEM - - const videoOutputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, inputVideoFile) + // Important to do this before getVideoFilename() to take in account the new filename + inputVideoFile.extname = newExtname + inputVideoFile.filename = generateWebTorrentVideoFilename(resolution, newExtname) + inputVideoFile.storage = VideoStorage.FILE_SYSTEM - const { videoFile } = await onWebTorrentVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath) + const videoOutputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, inputVideoFile) - return { transcodeType, videoFile } - } catch (err) { - // Auto destruction... - video.destroy().catch(err => logger.error('Cannot destruct video after transcoding failure.', { err })) + const { videoFile } = await onWebTorrentVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath) + await remove(videoInputPath) - throw err - } + return { transcodeType, videoFile } }) } -- cgit v1.2.3