aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/job-queue/handlers/video-live-ending.ts3
-rw-r--r--server/lib/job-queue/handlers/video-transcoding.ts26
-rw-r--r--server/lib/live/live-manager.ts14
-rw-r--r--server/lib/transcoding/transcoding.ts55
4 files changed, 58 insertions, 40 deletions
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts
index 10507fb83..78d0b2192 100644
--- a/server/lib/job-queue/handlers/video-live-ending.ts
+++ b/server/lib/job-queue/handlers/video-live-ending.ts
@@ -213,13 +213,12 @@ async function assignReplayFilesToVideo (options: {
213 const probe = await ffprobePromise(concatenatedTsFilePath) 213 const probe = await ffprobePromise(concatenatedTsFilePath)
214 const { audioStream } = await getAudioStream(concatenatedTsFilePath, probe) 214 const { audioStream } = await getAudioStream(concatenatedTsFilePath, probe)
215 215
216 const { resolution, isPortraitMode } = await getVideoStreamDimensionsInfo(concatenatedTsFilePath, probe) 216 const { resolution } = await getVideoStreamDimensionsInfo(concatenatedTsFilePath, probe)
217 217
218 const { resolutionPlaylistPath: outputPath } = await generateHlsPlaylistResolutionFromTS({ 218 const { resolutionPlaylistPath: outputPath } = await generateHlsPlaylistResolutionFromTS({
219 video, 219 video,
220 concatenatedTsFilePath, 220 concatenatedTsFilePath,
221 resolution, 221 resolution,
222 isPortraitMode,
223 isAAC: audioStream?.codec_name === 'aac' 222 isAAC: audioStream?.codec_name === 'aac'
224 }) 223 })
225 224
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts
index d3fb7778b..b07876a1c 100644
--- a/server/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/lib/job-queue/handlers/video-transcoding.ts
@@ -1,5 +1,6 @@
1import { Job } from 'bull' 1import { Job } from 'bull'
2import { TranscodeVODOptionsType } from '@server/helpers/ffmpeg' 2import { TranscodeVODOptionsType } from '@server/helpers/ffmpeg'
3import { Hooks } from '@server/lib/plugins/hooks'
3import { addTranscodingJob, getTranscodingJobPriority } from '@server/lib/video' 4import { addTranscodingJob, getTranscodingJobPriority } from '@server/lib/video'
4import { VideoPathManager } from '@server/lib/video-path-manager' 5import { VideoPathManager } from '@server/lib/video-path-manager'
5import { moveToFailedTranscodingState, moveToNextState } from '@server/lib/video-state' 6import { moveToFailedTranscodingState, moveToNextState } from '@server/lib/video-state'
@@ -16,7 +17,7 @@ import {
16 VideoTranscodingPayload 17 VideoTranscodingPayload
17} from '@shared/models' 18} from '@shared/models'
18import { retryTransactionWrapper } from '../../../helpers/database-utils' 19import { retryTransactionWrapper } from '../../../helpers/database-utils'
19import { computeLowerResolutionsToTranscode } from '../../../helpers/ffmpeg' 20import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg'
20import { logger, loggerTagsFactory } from '../../../helpers/logger' 21import { logger, loggerTagsFactory } from '../../../helpers/logger'
21import { CONFIG } from '../../../initializers/config' 22import { CONFIG } from '../../../initializers/config'
22import { VideoModel } from '../../../models/video/video' 23import { VideoModel } from '../../../models/video/video'
@@ -26,7 +27,6 @@ import {
26 optimizeOriginalVideofile, 27 optimizeOriginalVideofile,
27 transcodeNewWebTorrentResolution 28 transcodeNewWebTorrentResolution
28} from '../../transcoding/transcoding' 29} from '../../transcoding/transcoding'
29import { Hooks } from '@server/lib/plugins/hooks'
30 30
31type HandlerFunction = (job: Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<void> 31type HandlerFunction = (job: Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<void>
32 32
@@ -99,7 +99,6 @@ async function handleHLSJob (job: Job, payload: HLSTranscodingPayload, video: MV
99 videoInputPath, 99 videoInputPath,
100 resolution: payload.resolution, 100 resolution: payload.resolution,
101 copyCodecs: payload.copyCodecs, 101 copyCodecs: payload.copyCodecs,
102 isPortraitMode: payload.isPortraitMode || false,
103 job 102 job
104 }) 103 })
105 }) 104 })
@@ -117,7 +116,7 @@ async function handleNewWebTorrentResolutionJob (
117) { 116) {
118 logger.info('Handling WebTorrent transcoding job for %s.', video.uuid, lTags(video.uuid)) 117 logger.info('Handling WebTorrent transcoding job for %s.', video.uuid, lTags(video.uuid))
119 118
120 await transcodeNewWebTorrentResolution(video, payload.resolution, payload.isPortraitMode || false, job) 119 await transcodeNewWebTorrentResolution({ video, resolution: payload.resolution, job })
121 120
122 logger.info('WebTorrent transcoding job for %s ended.', video.uuid, lTags(video.uuid)) 121 logger.info('WebTorrent transcoding job for %s ended.', video.uuid, lTags(video.uuid))
123 122
@@ -127,7 +126,7 @@ async function handleNewWebTorrentResolutionJob (
127async function handleWebTorrentMergeAudioJob (job: Job, payload: MergeAudioTranscodingPayload, video: MVideoFullLight, user: MUserId) { 126async function handleWebTorrentMergeAudioJob (job: Job, payload: MergeAudioTranscodingPayload, video: MVideoFullLight, user: MUserId) {
128 logger.info('Handling merge audio transcoding job for %s.', video.uuid, lTags(video.uuid)) 127 logger.info('Handling merge audio transcoding job for %s.', video.uuid, lTags(video.uuid))
129 128
130 await mergeAudioVideofile(video, payload.resolution, job) 129 await mergeAudioVideofile({ video, resolution: payload.resolution, job })
131 130
132 logger.info('Merge audio transcoding job for %s ended.', video.uuid, lTags(video.uuid)) 131 logger.info('Merge audio transcoding job for %s ended.', video.uuid, lTags(video.uuid))
133 132
@@ -137,7 +136,7 @@ async function handleWebTorrentMergeAudioJob (job: Job, payload: MergeAudioTrans
137async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodingPayload, video: MVideoFullLight, user: MUserId) { 136async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodingPayload, video: MVideoFullLight, user: MUserId) {
138 logger.info('Handling optimize transcoding job for %s.', video.uuid, lTags(video.uuid)) 137 logger.info('Handling optimize transcoding job for %s.', video.uuid, lTags(video.uuid))
139 138
140 const { transcodeType } = await optimizeOriginalVideofile(video, video.getMaxQualityFile(), job) 139 const { transcodeType } = await optimizeOriginalVideofile({ video, inputVideoFile: video.getMaxQualityFile(), job })
141 140
142 logger.info('Optimize transcoding job for %s ended.', video.uuid, lTags(video.uuid)) 141 logger.info('Optimize transcoding job for %s ended.', video.uuid, lTags(video.uuid))
143 142
@@ -161,7 +160,6 @@ async function onHlsPlaylistGeneration (video: MVideoFullLight, user: MUser, pay
161 video, 160 video,
162 user, 161 user,
163 videoFileResolution: payload.resolution, 162 videoFileResolution: payload.resolution,
164 isPortraitMode: payload.isPortraitMode,
165 hasAudio: payload.hasAudio, 163 hasAudio: payload.hasAudio,
166 isNewVideo: payload.isNewVideo ?? true, 164 isNewVideo: payload.isNewVideo ?? true,
167 type: 'hls' 165 type: 'hls'
@@ -178,7 +176,7 @@ async function onVideoFirstWebTorrentTranscoding (
178 transcodeType: TranscodeVODOptionsType, 176 transcodeType: TranscodeVODOptionsType,
179 user: MUserId 177 user: MUserId
180) { 178) {
181 const { resolution, isPortraitMode, audioStream } = await videoArg.probeMaxQualityFile() 179 const { resolution, audioStream } = await videoArg.probeMaxQualityFile()
182 180
183 // Maybe the video changed in database, refresh it 181 // Maybe the video changed in database, refresh it
184 const videoDatabase = await VideoModel.loadFull(videoArg.uuid) 182 const videoDatabase = await VideoModel.loadFull(videoArg.uuid)
@@ -189,7 +187,6 @@ async function onVideoFirstWebTorrentTranscoding (
189 const originalFileHLSPayload = { 187 const originalFileHLSPayload = {
190 ...payload, 188 ...payload,
191 189
192 isPortraitMode,
193 hasAudio: !!audioStream, 190 hasAudio: !!audioStream,
194 resolution: videoDatabase.getMaxQualityFile().resolution, 191 resolution: videoDatabase.getMaxQualityFile().resolution,
195 // If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues 192 // If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues
@@ -202,7 +199,6 @@ async function onVideoFirstWebTorrentTranscoding (
202 user, 199 user,
203 videoFileResolution: resolution, 200 videoFileResolution: resolution,
204 hasAudio: !!audioStream, 201 hasAudio: !!audioStream,
205 isPortraitMode,
206 type: 'webtorrent', 202 type: 'webtorrent',
207 isNewVideo: payload.isNewVideo ?? true 203 isNewVideo: payload.isNewVideo ?? true
208 }) 204 })
@@ -235,7 +231,6 @@ async function createHlsJobIfEnabled (user: MUserId, payload: {
235 videoUUID: string 231 videoUUID: string
236 resolution: number 232 resolution: number
237 hasAudio: boolean 233 hasAudio: boolean
238 isPortraitMode?: boolean
239 copyCodecs: boolean 234 copyCodecs: boolean
240 isMaxQuality: boolean 235 isMaxQuality: boolean
241 isNewVideo?: boolean 236 isNewVideo?: boolean
@@ -250,7 +245,7 @@ async function createHlsJobIfEnabled (user: MUserId, payload: {
250 type: 'new-resolution-to-hls', 245 type: 'new-resolution-to-hls',
251 autoDeleteWebTorrentIfNeeded: true, 246 autoDeleteWebTorrentIfNeeded: true,
252 247
253 ...pick(payload, [ 'videoUUID', 'resolution', 'isPortraitMode', 'copyCodecs', 'isMaxQuality', 'isNewVideo', 'hasAudio' ]) 248 ...pick(payload, [ 'videoUUID', 'resolution', 'copyCodecs', 'isMaxQuality', 'isNewVideo', 'hasAudio' ])
254 } 249 }
255 250
256 await addTranscodingJob(hlsTranscodingPayload, jobOptions) 251 await addTranscodingJob(hlsTranscodingPayload, jobOptions)
@@ -262,16 +257,15 @@ async function createLowerResolutionsJobs (options: {
262 video: MVideoFullLight 257 video: MVideoFullLight
263 user: MUserId 258 user: MUserId
264 videoFileResolution: number 259 videoFileResolution: number
265 isPortraitMode: boolean
266 hasAudio: boolean 260 hasAudio: boolean
267 isNewVideo: boolean 261 isNewVideo: boolean
268 type: 'hls' | 'webtorrent' 262 type: 'hls' | 'webtorrent'
269}) { 263}) {
270 const { video, user, videoFileResolution, isPortraitMode, isNewVideo, hasAudio, type } = options 264 const { video, user, videoFileResolution, isNewVideo, hasAudio, type } = options
271 265
272 // Create transcoding jobs if there are enabled resolutions 266 // Create transcoding jobs if there are enabled resolutions
273 const resolutionsEnabled = await Hooks.wrapObject( 267 const resolutionsEnabled = await Hooks.wrapObject(
274 computeLowerResolutionsToTranscode(videoFileResolution, 'vod'), 268 computeResolutionsToTranscode({ inputResolution: videoFileResolution, type: 'vod', includeInputResolution: false }),
275 'filter:transcoding.auto.lower-resolutions-to-transcode.result', 269 'filter:transcoding.auto.lower-resolutions-to-transcode.result',
276 options 270 options
277 ) 271 )
@@ -289,7 +283,6 @@ async function createLowerResolutionsJobs (options: {
289 type: 'new-resolution-to-webtorrent', 283 type: 'new-resolution-to-webtorrent',
290 videoUUID: video.uuid, 284 videoUUID: video.uuid,
291 resolution, 285 resolution,
292 isPortraitMode,
293 hasAudio, 286 hasAudio,
294 createHLSIfNeeded: true, 287 createHLSIfNeeded: true,
295 isNewVideo 288 isNewVideo
@@ -303,7 +296,6 @@ async function createLowerResolutionsJobs (options: {
303 type: 'new-resolution-to-hls', 296 type: 'new-resolution-to-hls',
304 videoUUID: video.uuid, 297 videoUUID: video.uuid,
305 resolution, 298 resolution,
306 isPortraitMode,
307 hasAudio, 299 hasAudio,
308 copyCodecs: false, 300 copyCodecs: false,
309 isMaxQuality: false, 301 isMaxQuality: false,
diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts
index bd47b01f9..1d1ecd935 100644
--- a/server/lib/live/live-manager.ts
+++ b/server/lib/live/live-manager.ts
@@ -4,7 +4,7 @@ import { createServer, Server } from 'net'
4import { join } from 'path' 4import { join } from 'path'
5import { createServer as createServerTLS, Server as ServerTLS } from 'tls' 5import { createServer as createServerTLS, Server as ServerTLS } from 'tls'
6import { 6import {
7 computeLowerResolutionsToTranscode, 7 computeResolutionsToTranscode,
8 ffprobePromise, 8 ffprobePromise,
9 getLiveSegmentTime, 9 getLiveSegmentTime,
10 getVideoStreamBitrate, 10 getVideoStreamBitrate,
@@ -26,10 +26,10 @@ import { federateVideoIfNeeded } from '../activitypub/videos'
26import { JobQueue } from '../job-queue' 26import { JobQueue } from '../job-queue'
27import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths' 27import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths'
28import { PeerTubeSocket } from '../peertube-socket' 28import { PeerTubeSocket } from '../peertube-socket'
29import { Hooks } from '../plugins/hooks'
29import { LiveQuotaStore } from './live-quota-store' 30import { LiveQuotaStore } from './live-quota-store'
30import { cleanupPermanentLive } from './live-utils' 31import { cleanupPermanentLive } from './live-utils'
31import { MuxingSession } from './shared' 32import { MuxingSession } from './shared'
32import { Hooks } from '../plugins/hooks'
33 33
34const NodeRtmpSession = require('node-media-server/src/node_rtmp_session') 34const NodeRtmpSession = require('node-media-server/src/node_rtmp_session')
35const context = require('node-media-server/src/node_core_ctx') 35const context = require('node-media-server/src/node_core_ctx')
@@ -456,11 +456,17 @@ class LiveManager {
456 } 456 }
457 457
458 private buildAllResolutionsToTranscode (originResolution: number) { 458 private buildAllResolutionsToTranscode (originResolution: number) {
459 const includeInputResolution = CONFIG.LIVE.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION
460
459 const resolutionsEnabled = CONFIG.LIVE.TRANSCODING.ENABLED 461 const resolutionsEnabled = CONFIG.LIVE.TRANSCODING.ENABLED
460 ? computeLowerResolutionsToTranscode(originResolution, 'live') 462 ? computeResolutionsToTranscode({ inputResolution: originResolution, type: 'live', includeInputResolution })
461 : [] 463 : []
462 464
463 return resolutionsEnabled.concat([ originResolution ]) 465 if (resolutionsEnabled.length === 0) {
466 return [ originResolution ]
467 }
468
469 return resolutionsEnabled
464 } 470 }
465 471
466 private async createLivePlaylist (video: MVideo, allResolutions: number[]): Promise<MStreamingPlaylistVideo> { 472 private async createLivePlaylist (video: MVideo, allResolutions: number[]): Promise<MStreamingPlaylistVideo> {
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}