diff options
Diffstat (limited to 'server/helpers/ffprobe-utils.ts')
-rw-r--r-- | server/helpers/ffprobe-utils.ts | 28 |
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 @@ | |||
1 | import * as ffmpeg from 'fluent-ffmpeg' | 1 | import { ffprobe, FfprobeData } from 'fluent-ffmpeg' |
2 | import { getMaxBitrate } from '@shared/core-utils' | 2 | import { getMaxBitrate } from '@shared/core-utils' |
3 | import { VideoFileMetadata, VideoResolution, VideoTranscodingFPS } from '../../shared/models/videos' | 3 | import { VideoFileMetadata, VideoResolution, VideoTranscodingFPS } from '../../shared/models/videos' |
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
@@ -12,8 +12,8 @@ import { logger } from './logger' | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | function ffprobePromise (path: string) { | 14 | function 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 | ||
24 | async function getAudioStream (videoPath: string, existingProbe?: ffmpeg.FfprobeData) { | 24 | async 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 | ||
79 | async function getVideoStreamSize (path: string, existingProbe?: ffmpeg.FfprobeData): Promise<{ width: number, height: number }> { | 79 | async 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 | ||
130 | async function getAudioStreamCodec (path: string, existingProbe?: ffmpeg.FfprobeData) { | 130 | async 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 | ||
146 | async function getVideoFileResolution (path: string, existingProbe?: ffmpeg.FfprobeData) { | 146 | async 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 | ||
158 | async function getVideoFileFPS (path: string, existingProbe?: ffmpeg.FfprobeData) { | 158 | async 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 | ||
176 | async function getMetadataFromFile (path: string, existingProbe?: ffmpeg.FfprobeData) { | 176 | async 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 | ||
182 | async function getVideoFileBitrate (path: string, existingProbe?: ffmpeg.FfprobeData): Promise<number> { | 182 | async 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 | ||
197 | async function getDurationFromVideoFile (path: string, existingProbe?: ffmpeg.FfprobeData) { | 197 | async 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 | ||
203 | async function getVideoStreamFromFile (path: string, existingProbe?: ffmpeg.FfprobeData) { | 203 | async 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 | ||
246 | async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> { | 246 | async 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 | ||
265 | async function canDoQuickAudioTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> { | 265 | async 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 |