aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffmpeg
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/helpers/ffmpeg
parent7e0f50d6e0c7dc583d40e196c283eb20dc386ae6 (diff)
downloadPeerTube-84cae54e7a2595bea0c3ea106a4d111fd11a4ec6.tar.gz
PeerTube-84cae54e7a2595bea0c3ea106a4d111fd11a4ec6.tar.zst
PeerTube-84cae54e7a2595bea0c3ea106a4d111fd11a4ec6.zip
Add option to not transcode original resolution
Diffstat (limited to 'server/helpers/ffmpeg')
-rw-r--r--server/helpers/ffmpeg/ffmpeg-vod.ts12
-rw-r--r--server/helpers/ffmpeg/ffprobe-utils.ts26
2 files changed, 25 insertions, 13 deletions
diff --git a/server/helpers/ffmpeg/ffmpeg-vod.ts b/server/helpers/ffmpeg/ffmpeg-vod.ts
index c3622ceb1..f84157e0f 100644
--- a/server/helpers/ffmpeg/ffmpeg-vod.ts
+++ b/server/helpers/ffmpeg/ffmpeg-vod.ts
@@ -7,7 +7,7 @@ import { AvailableEncoders, VideoResolution } from '@shared/models'
7import { logger, loggerTagsFactory } from '../logger' 7import { logger, loggerTagsFactory } from '../logger'
8import { getFFmpeg, runCommand } from './ffmpeg-commons' 8import { getFFmpeg, runCommand } from './ffmpeg-commons'
9import { presetCopy, presetOnlyAudio, presetVOD } from './ffmpeg-presets' 9import { presetCopy, presetOnlyAudio, presetVOD } from './ffmpeg-presets'
10import { computeFPS, getVideoStreamFPS } from './ffprobe-utils' 10import { computeFPS, ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS } from './ffprobe-utils'
11import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants' 11import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants'
12 12
13const lTags = loggerTagsFactory('ffmpeg') 13const lTags = loggerTagsFactory('ffmpeg')
@@ -27,8 +27,6 @@ interface BaseTranscodeVODOptions {
27 27
28 resolution: number 28 resolution: number
29 29
30 isPortraitMode?: boolean
31
32 job?: Job 30 job?: Job
33} 31}
34 32
@@ -115,13 +113,17 @@ export {
115// --------------------------------------------------------------------------- 113// ---------------------------------------------------------------------------
116 114
117async function buildVODCommand (command: FfmpegCommand, options: TranscodeVODOptions) { 115async function buildVODCommand (command: FfmpegCommand, options: TranscodeVODOptions) {
118 let fps = await getVideoStreamFPS(options.inputPath) 116 const probe = await ffprobePromise(options.inputPath)
117
118 let fps = await getVideoStreamFPS(options.inputPath, probe)
119 fps = computeFPS(fps, options.resolution) 119 fps = computeFPS(fps, options.resolution)
120 120
121 let scaleFilterValue: string 121 let scaleFilterValue: string
122 122
123 if (options.resolution !== undefined) { 123 if (options.resolution !== undefined) {
124 scaleFilterValue = options.isPortraitMode === true 124 const videoStreamInfo = await getVideoStreamDimensionsInfo(options.inputPath, probe)
125
126 scaleFilterValue = videoStreamInfo?.isPortraitMode === true
125 ? `w=${options.resolution}:h=-2` 127 ? `w=${options.resolution}:h=-2`
126 : `w=-2:h=${options.resolution}` 128 : `w=-2:h=${options.resolution}`
127 } 129 }
diff --git a/server/helpers/ffmpeg/ffprobe-utils.ts b/server/helpers/ffmpeg/ffprobe-utils.ts
index 9529162eb..7bcd27665 100644
--- a/server/helpers/ffmpeg/ffprobe-utils.ts
+++ b/server/helpers/ffmpeg/ffprobe-utils.ts
@@ -90,15 +90,21 @@ async function getAudioStreamCodec (path: string, existingProbe?: FfprobeData) {
90// Resolutions 90// Resolutions
91// --------------------------------------------------------------------------- 91// ---------------------------------------------------------------------------
92 92
93function computeLowerResolutionsToTranscode (videoFileResolution: number, type: 'vod' | 'live') { 93function computeResolutionsToTranscode (options: {
94 inputResolution: number
95 type: 'vod' | 'live'
96 includeInputResolution: boolean
97}) {
98 const { inputResolution, type, includeInputResolution } = options
99
94 const configResolutions = type === 'vod' 100 const configResolutions = type === 'vod'
95 ? CONFIG.TRANSCODING.RESOLUTIONS 101 ? CONFIG.TRANSCODING.RESOLUTIONS
96 : CONFIG.LIVE.TRANSCODING.RESOLUTIONS 102 : CONFIG.LIVE.TRANSCODING.RESOLUTIONS
97 103
98 const resolutionsEnabled: number[] = [] 104 const resolutionsEnabled = new Set<number>()
99 105
100 // Put in the order we want to proceed jobs 106 // Put in the order we want to proceed jobs
101 const resolutions: VideoResolution[] = [ 107 const availableResolutions: VideoResolution[] = [
102 VideoResolution.H_NOVIDEO, 108 VideoResolution.H_NOVIDEO,
103 VideoResolution.H_480P, 109 VideoResolution.H_480P,
104 VideoResolution.H_360P, 110 VideoResolution.H_360P,
@@ -110,13 +116,17 @@ function computeLowerResolutionsToTranscode (videoFileResolution: number, type:
110 VideoResolution.H_4K 116 VideoResolution.H_4K
111 ] 117 ]
112 118
113 for (const resolution of resolutions) { 119 for (const resolution of availableResolutions) {
114 if (configResolutions[resolution + 'p'] === true && videoFileResolution > resolution) { 120 if (configResolutions[resolution + 'p'] === true && inputResolution > resolution) {
115 resolutionsEnabled.push(resolution) 121 resolutionsEnabled.add(resolution)
116 } 122 }
117 } 123 }
118 124
119 return resolutionsEnabled 125 if (includeInputResolution) {
126 resolutionsEnabled.add(inputResolution)
127 }
128
129 return Array.from(resolutionsEnabled)
120} 130}
121 131
122// --------------------------------------------------------------------------- 132// ---------------------------------------------------------------------------
@@ -224,7 +234,7 @@ export {
224 computeFPS, 234 computeFPS,
225 getClosestFramerateStandard, 235 getClosestFramerateStandard,
226 236
227 computeLowerResolutionsToTranscode, 237 computeResolutionsToTranscode,
228 238
229 canDoQuickTranscode, 239 canDoQuickTranscode,
230 canDoQuickVideoTranscode, 240 canDoQuickVideoTranscode,