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 | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/packages/peertube-runner/server/process/shared/process-vod.ts b/packages/peertube-runner/server/process/shared/process-vod.ts new file mode 100644 index 000000000..aae61e9c5 --- /dev/null +++ b/packages/peertube-runner/server/process/shared/process-vod.ts | |||
@@ -0,0 +1,131 @@ | |||
1 | import { remove } from 'fs-extra' | ||
2 | import { join } from 'path' | ||
3 | import { buildUUID } from '@shared/extra-utils' | ||
4 | import { | ||
5 | RunnerJobVODAudioMergeTranscodingPayload, | ||
6 | RunnerJobVODHLSTranscodingPayload, | ||
7 | RunnerJobVODWebVideoTranscodingPayload, | ||
8 | VODAudioMergeTranscodingSuccess, | ||
9 | VODHLSTranscodingSuccess, | ||
10 | VODWebVideoTranscodingSuccess | ||
11 | } from '@shared/models' | ||
12 | import { ConfigManager } from '../../../shared/config-manager' | ||
13 | import { buildFFmpegVOD, downloadInputFile, ProcessOptions } from './common' | ||
14 | |||
15 | export async function processWebVideoTranscoding (options: ProcessOptions<RunnerJobVODWebVideoTranscodingPayload>) { | ||
16 | const { server, job, runnerToken } = options | ||
17 | const payload = job.payload | ||
18 | |||
19 | const inputPath = await downloadInputFile({ url: payload.input.videoFileUrl, runnerToken, job }) | ||
20 | |||
21 | const ffmpegVod = buildFFmpegVOD({ job, server, runnerToken }) | ||
22 | |||
23 | const outputPath = join(ConfigManager.Instance.getTranscodingDirectory(), `output-${buildUUID()}.mp4`) | ||
24 | |||
25 | await ffmpegVod.transcode({ | ||
26 | type: 'video', | ||
27 | |||
28 | inputPath, | ||
29 | |||
30 | outputPath, | ||
31 | |||
32 | inputFileMutexReleaser: () => {}, | ||
33 | |||
34 | resolution: payload.output.resolution, | ||
35 | fps: payload.output.fps | ||
36 | }) | ||
37 | |||
38 | const successBody: VODWebVideoTranscodingSuccess = { | ||
39 | videoFile: outputPath | ||
40 | } | ||
41 | |||
42 | await server.runnerJobs.success({ | ||
43 | jobToken: job.jobToken, | ||
44 | jobUUID: job.uuid, | ||
45 | runnerToken, | ||
46 | payload: successBody | ||
47 | }) | ||
48 | |||
49 | await remove(outputPath) | ||
50 | } | ||
51 | |||
52 | export async function processHLSTranscoding (options: ProcessOptions<RunnerJobVODHLSTranscodingPayload>) { | ||
53 | const { server, job, runnerToken } = options | ||
54 | const payload = job.payload | ||
55 | |||
56 | const inputPath = await downloadInputFile({ url: payload.input.videoFileUrl, runnerToken, job }) | ||
57 | const uuid = buildUUID() | ||
58 | |||
59 | const outputPath = join(ConfigManager.Instance.getTranscodingDirectory(), `${uuid}-${payload.output.resolution}.m3u8`) | ||
60 | const videoFilename = `${uuid}-${payload.output.resolution}-fragmented.mp4` | ||
61 | const videoPath = join(join(ConfigManager.Instance.getTranscodingDirectory(), videoFilename)) | ||
62 | |||
63 | const ffmpegVod = buildFFmpegVOD({ job, server, runnerToken }) | ||
64 | |||
65 | await ffmpegVod.transcode({ | ||
66 | type: 'hls', | ||
67 | copyCodecs: false, | ||
68 | inputPath, | ||
69 | hlsPlaylist: { videoFilename }, | ||
70 | outputPath, | ||
71 | |||
72 | inputFileMutexReleaser: () => {}, | ||
73 | |||
74 | resolution: payload.output.resolution, | ||
75 | fps: payload.output.fps | ||
76 | }) | ||
77 | |||
78 | const successBody: VODHLSTranscodingSuccess = { | ||
79 | resolutionPlaylistFile: outputPath, | ||
80 | videoFile: videoPath | ||
81 | } | ||
82 | |||
83 | await server.runnerJobs.success({ | ||
84 | jobToken: job.jobToken, | ||
85 | jobUUID: job.uuid, | ||
86 | runnerToken, | ||
87 | payload: successBody | ||
88 | }) | ||
89 | |||
90 | await remove(outputPath) | ||
91 | await remove(videoPath) | ||
92 | } | ||
93 | |||
94 | export async function processAudioMergeTranscoding (options: ProcessOptions<RunnerJobVODAudioMergeTranscodingPayload>) { | ||
95 | const { server, job, runnerToken } = options | ||
96 | const payload = job.payload | ||
97 | |||
98 | const audioPath = await downloadInputFile({ url: payload.input.audioFileUrl, runnerToken, job }) | ||
99 | const inputPath = await downloadInputFile({ url: payload.input.previewFileUrl, runnerToken, job }) | ||
100 | |||
101 | const outputPath = join(ConfigManager.Instance.getTranscodingDirectory(), `output-${buildUUID()}.mp4`) | ||
102 | |||
103 | const ffmpegVod = buildFFmpegVOD({ job, server, runnerToken }) | ||
104 | |||
105 | await ffmpegVod.transcode({ | ||
106 | type: 'merge-audio', | ||
107 | |||
108 | audioPath, | ||
109 | inputPath, | ||
110 | |||
111 | outputPath, | ||
112 | |||
113 | inputFileMutexReleaser: () => {}, | ||
114 | |||
115 | resolution: payload.output.resolution, | ||
116 | fps: payload.output.fps | ||
117 | }) | ||
118 | |||
119 | const successBody: VODAudioMergeTranscodingSuccess = { | ||
120 | videoFile: outputPath | ||
121 | } | ||
122 | |||
123 | await server.runnerJobs.success({ | ||
124 | jobToken: job.jobToken, | ||
125 | jobUUID: job.uuid, | ||
126 | runnerToken, | ||
127 | payload: successBody | ||
128 | }) | ||
129 | |||
130 | await remove(outputPath) | ||
131 | } | ||