diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/video-transcoding.ts | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index 8e906a1eb..d6b6b251a 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts | |||
@@ -16,11 +16,12 @@ import { CONFIG } from '../initializers/config' | |||
16 | */ | 16 | */ |
17 | async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) { | 17 | async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) { |
18 | const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR | 18 | const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR |
19 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR | ||
19 | const newExtname = '.mp4' | 20 | const newExtname = '.mp4' |
20 | 21 | ||
21 | const inputVideoFile = inputVideoFileArg ? inputVideoFileArg : video.getOriginalFile() | 22 | const inputVideoFile = inputVideoFileArg ? inputVideoFileArg : video.getOriginalFile() |
22 | const videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile)) | 23 | const videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile)) |
23 | const videoTranscodedPath = join(videosDirectory, video.id + '-transcoded' + newExtname) | 24 | const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname) |
24 | 25 | ||
25 | const doQuickTranscode = await(canDoQuickTranscode(videoInputPath)) | 26 | const doQuickTranscode = await(canDoQuickTranscode(videoInputPath)) |
26 | 27 | ||
@@ -40,10 +41,11 @@ async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFi | |||
40 | // Important to do this before getVideoFilename() to take in account the new file extension | 41 | // Important to do this before getVideoFilename() to take in account the new file extension |
41 | inputVideoFile.set('extname', newExtname) | 42 | inputVideoFile.set('extname', newExtname) |
42 | 43 | ||
44 | const stats = await stat(videoTranscodedPath) | ||
45 | const fps = await getVideoFileFPS(videoTranscodedPath) | ||
46 | |||
43 | const videoOutputPath = video.getVideoFilePath(inputVideoFile) | 47 | const videoOutputPath = video.getVideoFilePath(inputVideoFile) |
44 | await move(videoTranscodedPath, videoOutputPath) | 48 | await move(videoTranscodedPath, videoOutputPath) |
45 | const stats = await stat(videoOutputPath) | ||
46 | const fps = await getVideoFileFPS(videoOutputPath) | ||
47 | 49 | ||
48 | inputVideoFile.set('size', stats.size) | 50 | inputVideoFile.set('size', stats.size) |
49 | inputVideoFile.set('fps', fps) | 51 | inputVideoFile.set('fps', fps) |
@@ -63,6 +65,7 @@ async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFi | |||
63 | */ | 65 | */ |
64 | async function transcodeOriginalVideofile (video: VideoModel, resolution: VideoResolution, isPortrait: boolean) { | 66 | async function transcodeOriginalVideofile (video: VideoModel, resolution: VideoResolution, isPortrait: boolean) { |
65 | const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR | 67 | const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR |
68 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR | ||
66 | const extname = '.mp4' | 69 | const extname = '.mp4' |
67 | 70 | ||
68 | // We are sure it's x264 in mp4 because optimizeOriginalVideofile was already executed | 71 | // We are sure it's x264 in mp4 because optimizeOriginalVideofile was already executed |
@@ -75,18 +78,21 @@ async function transcodeOriginalVideofile (video: VideoModel, resolution: VideoR | |||
75 | videoId: video.id | 78 | videoId: video.id |
76 | }) | 79 | }) |
77 | const videoOutputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(newVideoFile)) | 80 | const videoOutputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(newVideoFile)) |
81 | const videoTranscodedPath = join(transcodeDirectory, video.getVideoFilename(newVideoFile)) | ||
78 | 82 | ||
79 | const transcodeOptions = { | 83 | const transcodeOptions = { |
80 | inputPath: videoInputPath, | 84 | inputPath: videoInputPath, |
81 | outputPath: videoOutputPath, | 85 | outputPath: videoTranscodedPath, |
82 | resolution, | 86 | resolution, |
83 | isPortraitMode: isPortrait | 87 | isPortraitMode: isPortrait |
84 | } | 88 | } |
85 | 89 | ||
86 | await transcode(transcodeOptions) | 90 | await transcode(transcodeOptions) |
87 | 91 | ||
88 | const stats = await stat(videoOutputPath) | 92 | const stats = await stat(videoTranscodedPath) |
89 | const fps = await getVideoFileFPS(videoOutputPath) | 93 | const fps = await getVideoFileFPS(videoTranscodedPath) |
94 | |||
95 | await move(videoTranscodedPath, videoOutputPath) | ||
90 | 96 | ||
91 | newVideoFile.set('size', stats.size) | 97 | newVideoFile.set('size', stats.size) |
92 | newVideoFile.set('fps', fps) | 98 | newVideoFile.set('fps', fps) |