aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-transcoding.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-01-21 15:58:17 +0100
committerChocobozzz <me@florianbigard.com>2021-01-21 15:58:17 +0100
commit24516aa26a6753517b379cf7b5104c1a24eccad6 (patch)
treea94b561faa63238f8ac69848f6b0379f0ade08a2 /server/lib/video-transcoding.ts
parent3b01f4c0ac764ecb70efaadfd939ca868c28769c (diff)
downloadPeerTube-24516aa26a6753517b379cf7b5104c1a24eccad6.tar.gz
PeerTube-24516aa26a6753517b379cf7b5104c1a24eccad6.tar.zst
PeerTube-24516aa26a6753517b379cf7b5104c1a24eccad6.zip
Refactor transcoding job handlers
Diffstat (limited to 'server/lib/video-transcoding.ts')
-rw-r--r--server/lib/video-transcoding.ts25
1 files changed, 15 insertions, 10 deletions
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index beef78b44..7af7a481c 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -60,7 +60,7 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFile:
60 60
61 const videoOutputPath = getVideoFilePath(video, inputVideoFile) 61 const videoOutputPath = getVideoFilePath(video, inputVideoFile)
62 62
63 await onVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath) 63 await onWebTorrentVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath)
64 64
65 return transcodeType 65 return transcodeType
66 } catch (err) { 66 } catch (err) {
@@ -72,7 +72,7 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFile:
72} 72}
73 73
74// Transcode the original video file to a lower resolution. 74// Transcode the original video file to a lower resolution.
75async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoResolution, isPortrait: boolean, job: Job) { 75async function transcodeNewWebTorrentResolution (video: MVideoWithFile, resolution: VideoResolution, isPortrait: boolean, job: Job) {
76 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR 76 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
77 const extname = '.mp4' 77 const extname = '.mp4'
78 78
@@ -118,7 +118,7 @@ async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoR
118 118
119 await transcode(transcodeOptions) 119 await transcode(transcodeOptions)
120 120
121 return onVideoFileTranscoding(video, newVideoFile, videoTranscodedPath, videoOutputPath) 121 return onWebTorrentVideoFileTranscoding(video, newVideoFile, videoTranscodedPath, videoOutputPath)
122} 122}
123 123
124// Merge an image with an audio file to create a video 124// Merge an image with an audio file to create a video
@@ -170,11 +170,11 @@ async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: Video
170 video.duration = await getDurationFromVideoFile(videoTranscodedPath) 170 video.duration = await getDurationFromVideoFile(videoTranscodedPath)
171 await video.save() 171 await video.save()
172 172
173 return onVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath) 173 return onWebTorrentVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath)
174} 174}
175 175
176// Concat TS segments from a live video to a fragmented mp4 HLS playlist 176// Concat TS segments from a live video to a fragmented mp4 HLS playlist
177async function generateHlsPlaylistFromTS (options: { 177async function generateHlsPlaylistResolutionFromTS (options: {
178 video: MVideoWithFile 178 video: MVideoWithFile
179 concatenatedTsFilePath: string 179 concatenatedTsFilePath: string
180 resolution: VideoResolution 180 resolution: VideoResolution
@@ -192,7 +192,7 @@ async function generateHlsPlaylistFromTS (options: {
192} 192}
193 193
194// Generate an HLS playlist from an input file, and update the master playlist 194// Generate an HLS playlist from an input file, and update the master playlist
195function generateHlsPlaylist (options: { 195function generateHlsPlaylistResolution (options: {
196 video: MVideoWithFile 196 video: MVideoWithFile
197 videoInputPath: string 197 videoInputPath: string
198 resolution: VideoResolution 198 resolution: VideoResolution
@@ -224,17 +224,22 @@ function getEnabledResolutions (type: 'vod' | 'live') {
224// --------------------------------------------------------------------------- 224// ---------------------------------------------------------------------------
225 225
226export { 226export {
227 generateHlsPlaylist, 227 generateHlsPlaylistResolution,
228 generateHlsPlaylistFromTS, 228 generateHlsPlaylistResolutionFromTS,
229 optimizeOriginalVideofile, 229 optimizeOriginalVideofile,
230 transcodeNewResolution, 230 transcodeNewWebTorrentResolution,
231 mergeAudioVideofile, 231 mergeAudioVideofile,
232 getEnabledResolutions 232 getEnabledResolutions
233} 233}
234 234
235// --------------------------------------------------------------------------- 235// ---------------------------------------------------------------------------
236 236
237async function onVideoFileTranscoding (video: MVideoWithFile, videoFile: MVideoFile, transcodingPath: string, outputPath: string) { 237async function onWebTorrentVideoFileTranscoding (
238 video: MVideoWithFile,
239 videoFile: MVideoFile,
240 transcodingPath: string,
241 outputPath: string
242) {
238 const stats = await stat(transcodingPath) 243 const stats = await stat(transcodingPath)
239 const fps = await getVideoFileFPS(transcodingPath) 244 const fps = await getVideoFileFPS(transcodingPath)
240 const metadata = await getMetadataFromFile(transcodingPath) 245 const metadata = await getMetadataFromFile(transcodingPath)