aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-transcoding.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video-transcoding.ts')
-rw-r--r--server/lib/video-transcoding.ts36
1 files changed, 25 insertions, 11 deletions
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index a6b79eaea..beef78b44 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -1,3 +1,4 @@
1import { Job } from 'bull'
1import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' 2import { copyFile, ensureDir, move, remove, stat } from 'fs-extra'
2import { basename, extname as extnameUtil, join } from 'path' 3import { basename, extname as extnameUtil, join } from 'path'
3import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 4import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
@@ -23,11 +24,10 @@ import { availableEncoders } from './video-transcoding-profiles'
23 */ 24 */
24 25
25// Optimize the original video file and replace it. The resolution is not changed. 26// Optimize the original video file and replace it. The resolution is not changed.
26async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFileArg?: MVideoFile) { 27async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFile: MVideoFile, job?: Job) {
27 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR 28 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
28 const newExtname = '.mp4' 29 const newExtname = '.mp4'
29 30
30 const inputVideoFile = inputVideoFileArg || video.getMaxQualityFile()
31 const videoInputPath = getVideoFilePath(video, inputVideoFile) 31 const videoInputPath = getVideoFilePath(video, inputVideoFile)
32 const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname) 32 const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname)
33 33
@@ -44,7 +44,9 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFileA
44 availableEncoders, 44 availableEncoders,
45 profile: 'default', 45 profile: 'default',
46 46
47 resolution: inputVideoFile.resolution 47 resolution: inputVideoFile.resolution,
48
49 job
48 } 50 }
49 51
50 // Could be very long! 52 // Could be very long!
@@ -70,7 +72,7 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFileA
70} 72}
71 73
72// Transcode the original video file to a lower resolution. 74// Transcode the original video file to a lower resolution.
73async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoResolution, isPortrait: boolean) { 75async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoResolution, isPortrait: boolean, job: Job) {
74 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR 76 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
75 const extname = '.mp4' 77 const extname = '.mp4'
76 78
@@ -96,7 +98,9 @@ async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoR
96 availableEncoders, 98 availableEncoders,
97 profile: 'default', 99 profile: 'default',
98 100
99 resolution 101 resolution,
102
103 job
100 } 104 }
101 : { 105 : {
102 type: 'video' as 'video', 106 type: 'video' as 'video',
@@ -107,7 +111,9 @@ async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoR
107 profile: 'default', 111 profile: 'default',
108 112
109 resolution, 113 resolution,
110 isPortraitMode: isPortrait 114 isPortraitMode: isPortrait,
115
116 job
111 } 117 }
112 118
113 await transcode(transcodeOptions) 119 await transcode(transcodeOptions)
@@ -116,7 +122,7 @@ async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoR
116} 122}
117 123
118// Merge an image with an audio file to create a video 124// Merge an image with an audio file to create a video
119async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: VideoResolution) { 125async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: VideoResolution, job: Job) {
120 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR 126 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
121 const newExtname = '.mp4' 127 const newExtname = '.mp4'
122 128
@@ -140,7 +146,9 @@ async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: Video
140 profile: 'default', 146 profile: 'default',
141 147
142 audioPath: audioInputPath, 148 audioPath: audioInputPath,
143 resolution 149 resolution,
150
151 job
144 } 152 }
145 153
146 try { 154 try {
@@ -190,6 +198,7 @@ function generateHlsPlaylist (options: {
190 resolution: VideoResolution 198 resolution: VideoResolution
191 copyCodecs: boolean 199 copyCodecs: boolean
192 isPortraitMode: boolean 200 isPortraitMode: boolean
201 job?: Job
193}) { 202}) {
194 return generateHlsPlaylistCommon({ 203 return generateHlsPlaylistCommon({
195 video: options.video, 204 video: options.video,
@@ -197,7 +206,8 @@ function generateHlsPlaylist (options: {
197 copyCodecs: options.copyCodecs, 206 copyCodecs: options.copyCodecs,
198 isPortraitMode: options.isPortraitMode, 207 isPortraitMode: options.isPortraitMode,
199 inputPath: options.videoInputPath, 208 inputPath: options.videoInputPath,
200 type: 'hls' as 'hls' 209 type: 'hls' as 'hls',
210 job: options.job
201 }) 211 })
202} 212}
203 213
@@ -251,8 +261,10 @@ async function generateHlsPlaylistCommon (options: {
251 copyCodecs?: boolean 261 copyCodecs?: boolean
252 isAAC?: boolean 262 isAAC?: boolean
253 isPortraitMode: boolean 263 isPortraitMode: boolean
264
265 job?: Job
254}) { 266}) {
255 const { type, video, inputPath, resolution, copyCodecs, isPortraitMode, isAAC } = options 267 const { type, video, inputPath, resolution, copyCodecs, isPortraitMode, isAAC, job } = options
256 268
257 const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) 269 const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)
258 await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)) 270 await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid))
@@ -277,7 +289,9 @@ async function generateHlsPlaylistCommon (options: {
277 289
278 hlsPlaylist: { 290 hlsPlaylist: {
279 videoFilename 291 videoFilename
280 } 292 },
293
294 job
281 } 295 }
282 296
283 await transcode(transcodeOptions) 297 await transcode(transcodeOptions)