]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
transcode in STORAGE.TMP_DIR for s3fs compatibility (#147)
authorlibertysoft3 <libertysoft3@protonmail.com>
Mon, 13 May 2019 05:26:56 +0000 (22:26 -0700)
committerChocobozzz <chocobozzz@cpy.re>
Thu, 16 May 2019 06:59:35 +0000 (08:59 +0200)
server/lib/video-transcoding.ts

index 8e906a1eba60df6f755f047bd165f51c6de8c010..d6b6b251a931994c0918e5584f05c1871096583b 100644 (file)
@@ -16,11 +16,12 @@ import { CONFIG } from '../initializers/config'
  */
 async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) {
   const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
+  const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
   const newExtname = '.mp4'
 
   const inputVideoFile = inputVideoFileArg ? inputVideoFileArg : video.getOriginalFile()
   const videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile))
-  const videoTranscodedPath = join(videosDirectory, video.id + '-transcoded' + newExtname)
+  const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname)
 
   const doQuickTranscode = await(canDoQuickTranscode(videoInputPath))
 
@@ -40,10 +41,11 @@ async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFi
     // Important to do this before getVideoFilename() to take in account the new file extension
     inputVideoFile.set('extname', newExtname)
 
+    const stats = await stat(videoTranscodedPath)
+    const fps = await getVideoFileFPS(videoTranscodedPath)
+
     const videoOutputPath = video.getVideoFilePath(inputVideoFile)
     await move(videoTranscodedPath, videoOutputPath)
-    const stats = await stat(videoOutputPath)
-    const fps = await getVideoFileFPS(videoOutputPath)
 
     inputVideoFile.set('size', stats.size)
     inputVideoFile.set('fps', fps)
@@ -63,6 +65,7 @@ async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFi
  */
 async function transcodeOriginalVideofile (video: VideoModel, resolution: VideoResolution, isPortrait: boolean) {
   const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
+  const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
   const extname = '.mp4'
 
   // We are sure it's x264 in mp4 because optimizeOriginalVideofile was already executed
@@ -75,18 +78,21 @@ async function transcodeOriginalVideofile (video: VideoModel, resolution: VideoR
     videoId: video.id
   })
   const videoOutputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(newVideoFile))
+  const videoTranscodedPath = join(transcodeDirectory, video.getVideoFilename(newVideoFile))
 
   const transcodeOptions = {
     inputPath: videoInputPath,
-    outputPath: videoOutputPath,
+    outputPath: videoTranscodedPath,
     resolution,
     isPortraitMode: isPortrait
   }
 
   await transcode(transcodeOptions)
 
-  const stats = await stat(videoOutputPath)
-  const fps = await getVideoFileFPS(videoOutputPath)
+  const stats = await stat(videoTranscodedPath)
+  const fps = await getVideoFileFPS(videoTranscodedPath)
+
+  await move(videoTranscodedPath, videoOutputPath)
 
   newVideoFile.set('size', stats.size)
   newVideoFile.set('fps', fps)