aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffprobe-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-27 14:32:44 +0200
committerChocobozzz <me@florianbigard.com>2021-08-27 15:12:22 +0200
commit41fb13c330de629df2d23379209e79c7af0f2e9a (patch)
tree73bc5a90566406b3910f142beae2a879c1e4265d /server/helpers/ffprobe-utils.ts
parent40e7ed0714f96c01e16de3ac971a4b28116294e1 (diff)
downloadPeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.gz
PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.zst
PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.zip
esModuleInterop to true
Diffstat (limited to 'server/helpers/ffprobe-utils.ts')
-rw-r--r--server/helpers/ffprobe-utils.ts28
1 files changed, 14 insertions, 14 deletions
diff --git a/server/helpers/ffprobe-utils.ts b/server/helpers/ffprobe-utils.ts
index e58444b07..8381dee84 100644
--- a/server/helpers/ffprobe-utils.ts
+++ b/server/helpers/ffprobe-utils.ts
@@ -1,4 +1,4 @@
1import * as ffmpeg from 'fluent-ffmpeg' 1import { ffprobe, FfprobeData } from 'fluent-ffmpeg'
2import { getMaxBitrate } from '@shared/core-utils' 2import { getMaxBitrate } from '@shared/core-utils'
3import { VideoFileMetadata, VideoResolution, VideoTranscodingFPS } from '../../shared/models/videos' 3import { VideoFileMetadata, VideoResolution, VideoTranscodingFPS } from '../../shared/models/videos'
4import { CONFIG } from '../initializers/config' 4import { CONFIG } from '../initializers/config'
@@ -12,8 +12,8 @@ import { logger } from './logger'
12 */ 12 */
13 13
14function ffprobePromise (path: string) { 14function ffprobePromise (path: string) {
15 return new Promise<ffmpeg.FfprobeData>((res, rej) => { 15 return new Promise<FfprobeData>((res, rej) => {
16 ffmpeg.ffprobe(path, (err, data) => { 16 ffprobe(path, (err, data) => {
17 if (err) return rej(err) 17 if (err) return rej(err)
18 18
19 return res(data) 19 return res(data)
@@ -21,7 +21,7 @@ function ffprobePromise (path: string) {
21 }) 21 })
22} 22}
23 23
24async function getAudioStream (videoPath: string, existingProbe?: ffmpeg.FfprobeData) { 24async function getAudioStream (videoPath: string, existingProbe?: FfprobeData) {
25 // without position, ffprobe considers the last input only 25 // without position, ffprobe considers the last input only
26 // we make it consider the first input only 26 // we make it consider the first input only
27 // if you pass a file path to pos, then ffprobe acts on that file directly 27 // if you pass a file path to pos, then ffprobe acts on that file directly
@@ -76,7 +76,7 @@ function getMaxAudioBitrate (type: 'aac' | 'mp3' | string, bitrate: number) {
76 } 76 }
77} 77}
78 78
79async function getVideoStreamSize (path: string, existingProbe?: ffmpeg.FfprobeData): Promise<{ width: number, height: number }> { 79async function getVideoStreamSize (path: string, existingProbe?: FfprobeData): Promise<{ width: number, height: number }> {
80 const videoStream = await getVideoStreamFromFile(path, existingProbe) 80 const videoStream = await getVideoStreamFromFile(path, existingProbe)
81 81
82 return videoStream === null 82 return videoStream === null
@@ -127,7 +127,7 @@ async function getVideoStreamCodec (path: string) {
127 return `${videoCodec}.${baseProfile}${level}` 127 return `${videoCodec}.${baseProfile}${level}`
128} 128}
129 129
130async function getAudioStreamCodec (path: string, existingProbe?: ffmpeg.FfprobeData) { 130async function getAudioStreamCodec (path: string, existingProbe?: FfprobeData) {
131 const { audioStream } = await getAudioStream(path, existingProbe) 131 const { audioStream } = await getAudioStream(path, existingProbe)
132 132
133 if (!audioStream) return '' 133 if (!audioStream) return ''
@@ -143,7 +143,7 @@ async function getAudioStreamCodec (path: string, existingProbe?: ffmpeg.Ffprobe
143 return 'mp4a.40.2' // Fallback 143 return 'mp4a.40.2' // Fallback
144} 144}
145 145
146async function getVideoFileResolution (path: string, existingProbe?: ffmpeg.FfprobeData) { 146async function getVideoFileResolution (path: string, existingProbe?: FfprobeData) {
147 const size = await getVideoStreamSize(path, existingProbe) 147 const size = await getVideoStreamSize(path, existingProbe)
148 148
149 return { 149 return {
@@ -155,7 +155,7 @@ async function getVideoFileResolution (path: string, existingProbe?: ffmpeg.Ffpr
155 } 155 }
156} 156}
157 157
158async function getVideoFileFPS (path: string, existingProbe?: ffmpeg.FfprobeData) { 158async function getVideoFileFPS (path: string, existingProbe?: FfprobeData) {
159 const videoStream = await getVideoStreamFromFile(path, existingProbe) 159 const videoStream = await getVideoStreamFromFile(path, existingProbe)
160 if (videoStream === null) return 0 160 if (videoStream === null) return 0
161 161
@@ -173,13 +173,13 @@ async function getVideoFileFPS (path: string, existingProbe?: ffmpeg.FfprobeData
173 return 0 173 return 0
174} 174}
175 175
176async function getMetadataFromFile (path: string, existingProbe?: ffmpeg.FfprobeData) { 176async function getMetadataFromFile (path: string, existingProbe?: FfprobeData) {
177 const metadata = existingProbe || await ffprobePromise(path) 177 const metadata = existingProbe || await ffprobePromise(path)
178 178
179 return new VideoFileMetadata(metadata) 179 return new VideoFileMetadata(metadata)
180} 180}
181 181
182async function getVideoFileBitrate (path: string, existingProbe?: ffmpeg.FfprobeData): Promise<number> { 182async function getVideoFileBitrate (path: string, existingProbe?: FfprobeData): Promise<number> {
183 const metadata = await getMetadataFromFile(path, existingProbe) 183 const metadata = await getMetadataFromFile(path, existingProbe)
184 184
185 let bitrate = metadata.format.bit_rate as number 185 let bitrate = metadata.format.bit_rate as number
@@ -194,13 +194,13 @@ async function getVideoFileBitrate (path: string, existingProbe?: ffmpeg.Ffprobe
194 return undefined 194 return undefined
195} 195}
196 196
197async function getDurationFromVideoFile (path: string, existingProbe?: ffmpeg.FfprobeData) { 197async function getDurationFromVideoFile (path: string, existingProbe?: FfprobeData) {
198 const metadata = await getMetadataFromFile(path, existingProbe) 198 const metadata = await getMetadataFromFile(path, existingProbe)
199 199
200 return Math.round(metadata.format.duration) 200 return Math.round(metadata.format.duration)
201} 201}
202 202
203async function getVideoStreamFromFile (path: string, existingProbe?: ffmpeg.FfprobeData) { 203async function getVideoStreamFromFile (path: string, existingProbe?: FfprobeData) {
204 const metadata = await getMetadataFromFile(path, existingProbe) 204 const metadata = await getMetadataFromFile(path, existingProbe)
205 205
206 return metadata.streams.find(s => s.codec_type === 'video') || null 206 return metadata.streams.find(s => s.codec_type === 'video') || null
@@ -243,7 +243,7 @@ async function canDoQuickTranscode (path: string): Promise<boolean> {
243 await canDoQuickAudioTranscode(path, probe) 243 await canDoQuickAudioTranscode(path, probe)
244} 244}
245 245
246async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> { 246async function canDoQuickVideoTranscode (path: string, probe?: FfprobeData): Promise<boolean> {
247 const videoStream = await getVideoStreamFromFile(path, probe) 247 const videoStream = await getVideoStreamFromFile(path, probe)
248 const fps = await getVideoFileFPS(path, probe) 248 const fps = await getVideoFileFPS(path, probe)
249 const bitRate = await getVideoFileBitrate(path, probe) 249 const bitRate = await getVideoFileBitrate(path, probe)
@@ -262,7 +262,7 @@ async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeDat
262 return true 262 return true
263} 263}
264 264
265async function canDoQuickAudioTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> { 265async function canDoQuickAudioTranscode (path: string, probe?: FfprobeData): Promise<boolean> {
266 const parsedAudio = await getAudioStream(path, probe) 266 const parsedAudio = await getAudioStream(path, probe)
267 267
268 if (!parsedAudio.audioStream) return true 268 if (!parsedAudio.audioStream) return true