diff options
Diffstat (limited to 'packages/peertube-runner/server/process/shared/process-vod.ts')
-rw-r--r-- | packages/peertube-runner/server/process/shared/process-vod.ts | 201 |
1 files changed, 0 insertions, 201 deletions
diff --git a/packages/peertube-runner/server/process/shared/process-vod.ts b/packages/peertube-runner/server/process/shared/process-vod.ts deleted file mode 100644 index f7c076b27..000000000 --- a/packages/peertube-runner/server/process/shared/process-vod.ts +++ /dev/null | |||
@@ -1,201 +0,0 @@ | |||
1 | import { remove } from 'fs-extra' | ||
2 | import { logger } from 'packages/peertube-runner/shared' | ||
3 | import { join } from 'path' | ||
4 | import { buildUUID } from '@shared/extra-utils' | ||
5 | import { | ||
6 | RunnerJobVODAudioMergeTranscodingPayload, | ||
7 | RunnerJobVODHLSTranscodingPayload, | ||
8 | RunnerJobVODWebVideoTranscodingPayload, | ||
9 | VODAudioMergeTranscodingSuccess, | ||
10 | VODHLSTranscodingSuccess, | ||
11 | VODWebVideoTranscodingSuccess | ||
12 | } from '@shared/models' | ||
13 | import { ConfigManager } from '../../../shared/config-manager' | ||
14 | import { buildFFmpegVOD, downloadInputFile, ProcessOptions, scheduleTranscodingProgress } from './common' | ||
15 | |||
16 | export async function processWebVideoTranscoding (options: ProcessOptions<RunnerJobVODWebVideoTranscodingPayload>) { | ||
17 | const { server, job, runnerToken } = options | ||
18 | |||
19 | const payload = job.payload | ||
20 | |||
21 | let ffmpegProgress: number | ||
22 | let inputPath: string | ||
23 | |||
24 | const outputPath = join(ConfigManager.Instance.getTranscodingDirectory(), `output-${buildUUID()}.mp4`) | ||
25 | |||
26 | const updateProgressInterval = scheduleTranscodingProgress({ | ||
27 | job, | ||
28 | server, | ||
29 | runnerToken, | ||
30 | progressGetter: () => ffmpegProgress | ||
31 | }) | ||
32 | |||
33 | try { | ||
34 | logger.info(`Downloading input file ${payload.input.videoFileUrl} for web video transcoding job ${job.jobToken}`) | ||
35 | |||
36 | inputPath = await downloadInputFile({ url: payload.input.videoFileUrl, runnerToken, job }) | ||
37 | |||
38 | logger.info(`Downloaded input file ${payload.input.videoFileUrl} for job ${job.jobToken}. Running web video transcoding.`) | ||
39 | |||
40 | const ffmpegVod = buildFFmpegVOD({ | ||
41 | onJobProgress: progress => { ffmpegProgress = progress } | ||
42 | }) | ||
43 | |||
44 | await ffmpegVod.transcode({ | ||
45 | type: 'video', | ||
46 | |||
47 | inputPath, | ||
48 | |||
49 | outputPath, | ||
50 | |||
51 | inputFileMutexReleaser: () => {}, | ||
52 | |||
53 | resolution: payload.output.resolution, | ||
54 | fps: payload.output.fps | ||
55 | }) | ||
56 | |||
57 | const successBody: VODWebVideoTranscodingSuccess = { | ||
58 | videoFile: outputPath | ||
59 | } | ||
60 | |||
61 | await server.runnerJobs.success({ | ||
62 | jobToken: job.jobToken, | ||
63 | jobUUID: job.uuid, | ||
64 | runnerToken, | ||
65 | payload: successBody | ||
66 | }) | ||
67 | } finally { | ||
68 | if (inputPath) await remove(inputPath) | ||
69 | if (outputPath) await remove(outputPath) | ||
70 | if (updateProgressInterval) clearInterval(updateProgressInterval) | ||
71 | } | ||
72 | } | ||
73 | |||
74 | export async function processHLSTranscoding (options: ProcessOptions<RunnerJobVODHLSTranscodingPayload>) { | ||
75 | const { server, job, runnerToken } = options | ||
76 | const payload = job.payload | ||
77 | |||
78 | let ffmpegProgress: number | ||
79 | let inputPath: string | ||
80 | |||
81 | const uuid = buildUUID() | ||
82 | const outputPath = join(ConfigManager.Instance.getTranscodingDirectory(), `${uuid}-${payload.output.resolution}.m3u8`) | ||
83 | const videoFilename = `${uuid}-${payload.output.resolution}-fragmented.mp4` | ||
84 | const videoPath = join(join(ConfigManager.Instance.getTranscodingDirectory(), videoFilename)) | ||
85 | |||
86 | const updateProgressInterval = scheduleTranscodingProgress({ | ||
87 | job, | ||
88 | server, | ||
89 | runnerToken, | ||
90 | progressGetter: () => ffmpegProgress | ||
91 | }) | ||
92 | |||
93 | try { | ||
94 | logger.info(`Downloading input file ${payload.input.videoFileUrl} for HLS transcoding job ${job.jobToken}`) | ||
95 | |||
96 | inputPath = await downloadInputFile({ url: payload.input.videoFileUrl, runnerToken, job }) | ||
97 | |||
98 | logger.info(`Downloaded input file ${payload.input.videoFileUrl} for job ${job.jobToken}. Running HLS transcoding.`) | ||
99 | |||
100 | const ffmpegVod = buildFFmpegVOD({ | ||
101 | onJobProgress: progress => { ffmpegProgress = progress } | ||
102 | }) | ||
103 | |||
104 | await ffmpegVod.transcode({ | ||
105 | type: 'hls', | ||
106 | copyCodecs: false, | ||
107 | inputPath, | ||
108 | hlsPlaylist: { videoFilename }, | ||
109 | outputPath, | ||
110 | |||
111 | inputFileMutexReleaser: () => {}, | ||
112 | |||
113 | resolution: payload.output.resolution, | ||
114 | fps: payload.output.fps | ||
115 | }) | ||
116 | |||
117 | const successBody: VODHLSTranscodingSuccess = { | ||
118 | resolutionPlaylistFile: outputPath, | ||
119 | videoFile: videoPath | ||
120 | } | ||
121 | |||
122 | await server.runnerJobs.success({ | ||
123 | jobToken: job.jobToken, | ||
124 | jobUUID: job.uuid, | ||
125 | runnerToken, | ||
126 | payload: successBody | ||
127 | }) | ||
128 | } finally { | ||
129 | if (inputPath) await remove(inputPath) | ||
130 | if (outputPath) await remove(outputPath) | ||
131 | if (videoPath) await remove(videoPath) | ||
132 | if (updateProgressInterval) clearInterval(updateProgressInterval) | ||
133 | } | ||
134 | } | ||
135 | |||
136 | export async function processAudioMergeTranscoding (options: ProcessOptions<RunnerJobVODAudioMergeTranscodingPayload>) { | ||
137 | const { server, job, runnerToken } = options | ||
138 | const payload = job.payload | ||
139 | |||
140 | let ffmpegProgress: number | ||
141 | let audioPath: string | ||
142 | let inputPath: string | ||
143 | |||
144 | const outputPath = join(ConfigManager.Instance.getTranscodingDirectory(), `output-${buildUUID()}.mp4`) | ||
145 | |||
146 | const updateProgressInterval = scheduleTranscodingProgress({ | ||
147 | job, | ||
148 | server, | ||
149 | runnerToken, | ||
150 | progressGetter: () => ffmpegProgress | ||
151 | }) | ||
152 | |||
153 | try { | ||
154 | logger.info( | ||
155 | `Downloading input files ${payload.input.audioFileUrl} and ${payload.input.previewFileUrl} ` + | ||
156 | `for audio merge transcoding job ${job.jobToken}` | ||
157 | ) | ||
158 | |||
159 | audioPath = await downloadInputFile({ url: payload.input.audioFileUrl, runnerToken, job }) | ||
160 | inputPath = await downloadInputFile({ url: payload.input.previewFileUrl, runnerToken, job }) | ||
161 | |||
162 | logger.info( | ||
163 | `Downloaded input files ${payload.input.audioFileUrl} and ${payload.input.previewFileUrl} ` + | ||
164 | `for job ${job.jobToken}. Running audio merge transcoding.` | ||
165 | ) | ||
166 | |||
167 | const ffmpegVod = buildFFmpegVOD({ | ||
168 | onJobProgress: progress => { ffmpegProgress = progress } | ||
169 | }) | ||
170 | |||
171 | await ffmpegVod.transcode({ | ||
172 | type: 'merge-audio', | ||
173 | |||
174 | audioPath, | ||
175 | inputPath, | ||
176 | |||
177 | outputPath, | ||
178 | |||
179 | inputFileMutexReleaser: () => {}, | ||
180 | |||
181 | resolution: payload.output.resolution, | ||
182 | fps: payload.output.fps | ||
183 | }) | ||
184 | |||
185 | const successBody: VODAudioMergeTranscodingSuccess = { | ||
186 | videoFile: outputPath | ||
187 | } | ||
188 | |||
189 | await server.runnerJobs.success({ | ||
190 | jobToken: job.jobToken, | ||
191 | jobUUID: job.uuid, | ||
192 | runnerToken, | ||
193 | payload: successBody | ||
194 | }) | ||
195 | } finally { | ||
196 | if (audioPath) await remove(audioPath) | ||
197 | if (inputPath) await remove(inputPath) | ||
198 | if (outputPath) await remove(outputPath) | ||
199 | if (updateProgressInterval) clearInterval(updateProgressInterval) | ||
200 | } | ||
201 | } | ||