X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Ftranscoding%2Fvideo-transcoding.ts;h=9942a067b08e40d75aea435524e0214e4dd9fe28;hb=743dab5517d4501f6b35cfc795de6c8b6f41ebb3;hp=ee228c011145859899371d8b2f25b5429a873d6f;hpb=0305db28c98fd6cf43a3c50ba92c76215e99d512;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/transcoding/video-transcoding.ts b/server/lib/transcoding/video-transcoding.ts index ee228c011..9942a067b 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' @@ -36,7 +35,7 @@ function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile: MVid const transcodeDirectory = CONFIG.STORAGE.TMP_DIR const newExtname = '.mp4' - return VideoPathManager.Instance.makeAvailableVideoFile(video, inputVideoFile, async videoInputPath => { + return VideoPathManager.Instance.makeAvailableVideoFile(inputVideoFile.withVideoOrPlaylist(video), async videoInputPath => { const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname) const transcodeType: TranscodeOptionsType = await canDoQuickTranscode(videoInputPath) @@ -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 } }) } @@ -90,7 +81,7 @@ function transcodeNewWebTorrentResolution (video: MVideoFullLight, resolution: V const transcodeDirectory = CONFIG.STORAGE.TMP_DIR const extname = '.mp4' - return VideoPathManager.Instance.makeAvailableVideoFile(video, video.getMaxQualityFile(), async videoInputPath => { + return VideoPathManager.Instance.makeAvailableVideoFile(video.getMaxQualityFile().withVideoOrPlaylist(video), async videoInputPath => { const newVideoFile = new VideoFileModel({ resolution, extname, @@ -143,7 +134,7 @@ function mergeAudioVideofile (video: MVideoFullLight, resolution: VideoResolutio const inputVideoFile = video.getMinQualityFile() - return VideoPathManager.Instance.makeAvailableVideoFile(video, inputVideoFile, async audioInputPath => { + return VideoPathManager.Instance.makeAvailableVideoFile(inputVideoFile.withVideoOrPlaylist(video), async audioInputPath => { const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname) // If the user updates the video preview during transcoding @@ -178,6 +169,7 @@ function mergeAudioVideofile (video: MVideoFullLight, resolution: VideoResolutio // Important to do this before getVideoFilename() to take in account the new file extension inputVideoFile.extname = newExtname + inputVideoFile.resolution = resolution inputVideoFile.filename = generateWebTorrentVideoFilename(inputVideoFile.resolution, newExtname) const videoOutputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, inputVideoFile)