aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-file.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video-file.ts')
-rw-r--r--server/lib/video-file.ts54
1 files changed, 53 insertions, 1 deletions
diff --git a/server/lib/video-file.ts b/server/lib/video-file.ts
index 2ab7190f1..8fcc3c253 100644
--- a/server/lib/video-file.ts
+++ b/server/lib/video-file.ts
@@ -1,6 +1,44 @@
1import { FfprobeData } from 'fluent-ffmpeg'
1import { logger } from '@server/helpers/logger' 2import { logger } from '@server/helpers/logger'
3import { VideoFileModel } from '@server/models/video/video-file'
2import { MVideoWithAllFiles } from '@server/types/models' 4import { MVideoWithAllFiles } from '@server/types/models'
5import { getLowercaseExtension } from '@shared/core-utils'
6import { getFileSize } from '@shared/extra-utils'
7import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, isAudioFile } from '@shared/ffmpeg'
8import { VideoFileMetadata, VideoResolution } from '@shared/models'
3import { lTags } from './object-storage/shared' 9import { lTags } from './object-storage/shared'
10import { generateHLSVideoFilename, generateWebTorrentVideoFilename } from './paths'
11
12async function buildNewFile (options: {
13 path: string
14 mode: 'web-video' | 'hls'
15}) {
16 const { path, mode } = options
17
18 const probe = await ffprobePromise(path)
19 const size = await getFileSize(path)
20
21 const videoFile = new VideoFileModel({
22 extname: getLowercaseExtension(path),
23 size,
24 metadata: await buildFileMetadata(path, probe)
25 })
26
27 if (await isAudioFile(path, probe)) {
28 videoFile.resolution = VideoResolution.H_NOVIDEO
29 } else {
30 videoFile.fps = await getVideoStreamFPS(path, probe)
31 videoFile.resolution = (await getVideoStreamDimensionsInfo(path, probe)).resolution
32 }
33
34 videoFile.filename = mode === 'web-video'
35 ? generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname)
36 : generateHLSVideoFilename(videoFile.resolution)
37
38 return videoFile
39}
40
41// ---------------------------------------------------------------------------
4 42
5async function removeHLSPlaylist (video: MVideoWithAllFiles) { 43async function removeHLSPlaylist (video: MVideoWithAllFiles) {
6 const hls = video.getHLSPlaylist() 44 const hls = video.getHLSPlaylist()
@@ -61,9 +99,23 @@ async function removeWebTorrentFile (video: MVideoWithAllFiles, fileToDeleteId:
61 return video 99 return video
62} 100}
63 101
102// ---------------------------------------------------------------------------
103
104async function buildFileMetadata (path: string, existingProbe?: FfprobeData) {
105 const metadata = existingProbe || await ffprobePromise(path)
106
107 return new VideoFileMetadata(metadata)
108}
109
110// ---------------------------------------------------------------------------
111
64export { 112export {
113 buildNewFile,
114
65 removeHLSPlaylist, 115 removeHLSPlaylist,
66 removeHLSFile, 116 removeHLSFile,
67 removeAllWebTorrentFiles, 117 removeAllWebTorrentFiles,
68 removeWebTorrentFile 118 removeWebTorrentFile,
119
120 buildFileMetadata
69} 121}