]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/video-transcoding.ts
Add WebFinger support (#1498)
[github/Chocobozzz/PeerTube.git] / server / lib / video-transcoding.ts
index 04cadf74bd26b54090132e75901790f4ec4f96c6..4460f46e418d5809fbda6ecdf1ce8db112254908 100644 (file)
@@ -1,22 +1,18 @@
 import { CONFIG } from '../initializers'
-import { join, extname, basename } from 'path'
+import { extname, join } from 'path'
 import { getVideoFileFPS, getVideoFileResolution, transcode } from '../helpers/ffmpeg-utils'
-import { copy, remove, rename, stat } from 'fs-extra'
+import { copy, remove, move, stat } from 'fs-extra'
 import { logger } from '../helpers/logger'
 import { VideoResolution } from '../../shared/models/videos'
 import { VideoFileModel } from '../models/video/video-file'
 import { VideoModel } from '../models/video/video'
 
-async function optimizeVideofile (video: VideoModel, videoInputPath?: string) {
+async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) {
   const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
   const newExtname = '.mp4'
-  let inputVideoFile = null
-  if (videoInputPath == null) {
-    inputVideoFile = video.getOriginalFile()
-    videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile))
-  } else {
-    inputVideoFile = basename(videoInputPath)
-  }
+
+  const inputVideoFile = inputVideoFileArg ? inputVideoFileArg : video.getOriginalFile()
+  const videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile))
   const videoTranscodedPath = join(videosDirectory, video.id + '-transcoded' + newExtname)
 
   const transcodeOptions = {
@@ -34,7 +30,7 @@ async function optimizeVideofile (video: VideoModel, videoInputPath?: string) {
     inputVideoFile.set('extname', newExtname)
 
     const videoOutputPath = video.getVideoFilePath(inputVideoFile)
-    await rename(videoTranscodedPath, videoOutputPath)
+    await move(videoTranscodedPath, videoOutputPath)
     const stats = await stat(videoOutputPath)
     const fps = await getVideoFileFPS(videoOutputPath)