aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/transcoding/transcoding.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-05 10:36:19 +0200
committerChocobozzz <me@florianbigard.com>2022-08-09 09:18:07 +0200
commit84cae54e7a2595bea0c3ea106a4d111fd11a4ec6 (patch)
tree03fe73edf049ce60df6bbc34dcfb2031c07ea59c /server/lib/transcoding/transcoding.ts
parent7e0f50d6e0c7dc583d40e196c283eb20dc386ae6 (diff)
downloadPeerTube-84cae54e7a2595bea0c3ea106a4d111fd11a4ec6.tar.gz
PeerTube-84cae54e7a2595bea0c3ea106a4d111fd11a4ec6.tar.zst
PeerTube-84cae54e7a2595bea0c3ea106a4d111fd11a4ec6.zip
Add option to not transcode original resolution
Diffstat (limited to 'server/lib/transcoding/transcoding.ts')
-rw-r--r--server/lib/transcoding/transcoding.ts55
1 files changed, 38 insertions, 17 deletions
diff --git a/server/lib/transcoding/transcoding.ts b/server/lib/transcoding/transcoding.ts
index 924141d1c..3681de994 100644
--- a/server/lib/transcoding/transcoding.ts
+++ b/server/lib/transcoding/transcoding.ts
@@ -10,6 +10,7 @@ import { VideoResolution, VideoStorage } from '../../../shared/models/videos'
10import { 10import {
11 buildFileMetadata, 11 buildFileMetadata,
12 canDoQuickTranscode, 12 canDoQuickTranscode,
13 computeResolutionsToTranscode,
13 getVideoStreamDuration, 14 getVideoStreamDuration,
14 getVideoStreamFPS, 15 getVideoStreamFPS,
15 transcodeVOD, 16 transcodeVOD,
@@ -32,7 +33,13 @@ import { VideoTranscodingProfilesManager } from './default-transcoding-profiles'
32 */ 33 */
33 34
34// Optimize the original video file and replace it. The resolution is not changed. 35// Optimize the original video file and replace it. The resolution is not changed.
35function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile: MVideoFile, job?: Job) { 36function optimizeOriginalVideofile (options: {
37 video: MVideoFullLight
38 inputVideoFile: MVideoFile
39 job: Job
40}) {
41 const { video, inputVideoFile, job } = options
42
36 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR 43 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
37 const newExtname = '.mp4' 44 const newExtname = '.mp4'
38 45
@@ -43,7 +50,7 @@ function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile: MVid
43 ? 'quick-transcode' 50 ? 'quick-transcode'
44 : 'video' 51 : 'video'
45 52
46 const resolution = toEven(inputVideoFile.resolution) 53 const resolution = buildOriginalFileResolution(inputVideoFile.resolution)
47 54
48 const transcodeOptions: TranscodeVODOptions = { 55 const transcodeOptions: TranscodeVODOptions = {
49 type: transcodeType, 56 type: transcodeType,
@@ -63,6 +70,7 @@ function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile: MVid
63 await transcodeVOD(transcodeOptions) 70 await transcodeVOD(transcodeOptions)
64 71
65 // Important to do this before getVideoFilename() to take in account the new filename 72 // Important to do this before getVideoFilename() to take in account the new filename
73 inputVideoFile.resolution = resolution
66 inputVideoFile.extname = newExtname 74 inputVideoFile.extname = newExtname
67 inputVideoFile.filename = generateWebTorrentVideoFilename(resolution, newExtname) 75 inputVideoFile.filename = generateWebTorrentVideoFilename(resolution, newExtname)
68 inputVideoFile.storage = VideoStorage.FILE_SYSTEM 76 inputVideoFile.storage = VideoStorage.FILE_SYSTEM
@@ -76,17 +84,22 @@ function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile: MVid
76 }) 84 })
77} 85}
78 86
79// Transcode the original video file to a lower resolution 87// Transcode the original video file to a lower resolution compatible with WebTorrent
80// We are sure it's x264 in mp4 because optimizeOriginalVideofile was already executed 88function transcodeNewWebTorrentResolution (options: {
81function transcodeNewWebTorrentResolution (video: MVideoFullLight, resolution: VideoResolution, isPortrait: boolean, job: Job) { 89 video: MVideoFullLight
90 resolution: VideoResolution
91 job: Job
92}) {
93 const { video, resolution, job } = options
94
82 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR 95 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
83 const extname = '.mp4' 96 const newExtname = '.mp4'
84 97
85 return VideoPathManager.Instance.makeAvailableVideoFile(video.getMaxQualityFile().withVideoOrPlaylist(video), async videoInputPath => { 98 return VideoPathManager.Instance.makeAvailableVideoFile(video.getMaxQualityFile().withVideoOrPlaylist(video), async videoInputPath => {
86 const newVideoFile = new VideoFileModel({ 99 const newVideoFile = new VideoFileModel({
87 resolution, 100 resolution,
88 extname, 101 extname: newExtname,
89 filename: generateWebTorrentVideoFilename(resolution, extname), 102 filename: generateWebTorrentVideoFilename(resolution, newExtname),
90 size: 0, 103 size: 0,
91 videoId: video.id 104 videoId: video.id
92 }) 105 })
@@ -117,7 +130,6 @@ function transcodeNewWebTorrentResolution (video: MVideoFullLight, resolution: V
117 profile: CONFIG.TRANSCODING.PROFILE, 130 profile: CONFIG.TRANSCODING.PROFILE,
118 131
119 resolution, 132 resolution,
120 isPortraitMode: isPortrait,
121 133
122 job 134 job
123 } 135 }
@@ -129,7 +141,13 @@ function transcodeNewWebTorrentResolution (video: MVideoFullLight, resolution: V
129} 141}
130 142
131// Merge an image with an audio file to create a video 143// Merge an image with an audio file to create a video
132function mergeAudioVideofile (video: MVideoFullLight, resolution: VideoResolution, job: Job) { 144function mergeAudioVideofile (options: {
145 video: MVideoFullLight
146 resolution: VideoResolution
147 job: Job
148}) {
149 const { video, resolution, job } = options
150
133 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR 151 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
134 const newExtname = '.mp4' 152 const newExtname = '.mp4'
135 153
@@ -188,13 +206,11 @@ async function generateHlsPlaylistResolutionFromTS (options: {
188 video: MVideo 206 video: MVideo
189 concatenatedTsFilePath: string 207 concatenatedTsFilePath: string
190 resolution: VideoResolution 208 resolution: VideoResolution
191 isPortraitMode: boolean
192 isAAC: boolean 209 isAAC: boolean
193}) { 210}) {
194 return generateHlsPlaylistCommon({ 211 return generateHlsPlaylistCommon({
195 video: options.video, 212 video: options.video,
196 resolution: options.resolution, 213 resolution: options.resolution,
197 isPortraitMode: options.isPortraitMode,
198 inputPath: options.concatenatedTsFilePath, 214 inputPath: options.concatenatedTsFilePath,
199 type: 'hls-from-ts' as 'hls-from-ts', 215 type: 'hls-from-ts' as 'hls-from-ts',
200 isAAC: options.isAAC 216 isAAC: options.isAAC
@@ -207,14 +223,12 @@ function generateHlsPlaylistResolution (options: {
207 videoInputPath: string 223 videoInputPath: string
208 resolution: VideoResolution 224 resolution: VideoResolution
209 copyCodecs: boolean 225 copyCodecs: boolean
210 isPortraitMode: boolean
211 job?: Job 226 job?: Job
212}) { 227}) {
213 return generateHlsPlaylistCommon({ 228 return generateHlsPlaylistCommon({
214 video: options.video, 229 video: options.video,
215 resolution: options.resolution, 230 resolution: options.resolution,
216 copyCodecs: options.copyCodecs, 231 copyCodecs: options.copyCodecs,
217 isPortraitMode: options.isPortraitMode,
218 inputPath: options.videoInputPath, 232 inputPath: options.videoInputPath,
219 type: 'hls' as 'hls', 233 type: 'hls' as 'hls',
220 job: options.job 234 job: options.job
@@ -267,11 +281,10 @@ async function generateHlsPlaylistCommon (options: {
267 resolution: VideoResolution 281 resolution: VideoResolution
268 copyCodecs?: boolean 282 copyCodecs?: boolean
269 isAAC?: boolean 283 isAAC?: boolean
270 isPortraitMode: boolean
271 284
272 job?: Job 285 job?: Job
273}) { 286}) {
274 const { type, video, inputPath, resolution, copyCodecs, isPortraitMode, isAAC, job } = options 287 const { type, video, inputPath, resolution, copyCodecs, isAAC, job } = options
275 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR 288 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
276 289
277 const videoTranscodedBasePath = join(transcodeDirectory, type) 290 const videoTranscodedBasePath = join(transcodeDirectory, type)
@@ -292,7 +305,6 @@ async function generateHlsPlaylistCommon (options: {
292 305
293 resolution, 306 resolution,
294 copyCodecs, 307 copyCodecs,
295 isPortraitMode,
296 308
297 isAAC, 309 isAAC,
298 310
@@ -350,3 +362,12 @@ async function generateHlsPlaylistCommon (options: {
350 362
351 return { resolutionPlaylistPath, videoFile: savedVideoFile } 363 return { resolutionPlaylistPath, videoFile: savedVideoFile }
352} 364}
365
366function buildOriginalFileResolution (inputResolution: number) {
367 if (CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION === true) return toEven(inputResolution)
368
369 const resolutions = computeResolutionsToTranscode({ inputResolution, type: 'vod', includeInputResolution: false })
370 if (resolutions.length === 0) return toEven(inputResolution)
371
372 return Math.max(...resolutions)
373}