diff options
Diffstat (limited to 'server/lib/video-file.ts')
-rw-r--r-- | server/lib/video-file.ts | 54 |
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 @@ | |||
1 | import { FfprobeData } from 'fluent-ffmpeg' | ||
1 | import { logger } from '@server/helpers/logger' | 2 | import { logger } from '@server/helpers/logger' |
3 | import { VideoFileModel } from '@server/models/video/video-file' | ||
2 | import { MVideoWithAllFiles } from '@server/types/models' | 4 | import { MVideoWithAllFiles } from '@server/types/models' |
5 | import { getLowercaseExtension } from '@shared/core-utils' | ||
6 | import { getFileSize } from '@shared/extra-utils' | ||
7 | import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, isAudioFile } from '@shared/ffmpeg' | ||
8 | import { VideoFileMetadata, VideoResolution } from '@shared/models' | ||
3 | import { lTags } from './object-storage/shared' | 9 | import { lTags } from './object-storage/shared' |
10 | import { generateHLSVideoFilename, generateWebTorrentVideoFilename } from './paths' | ||
11 | |||
12 | async 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 | ||
5 | async function removeHLSPlaylist (video: MVideoWithAllFiles) { | 43 | async 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 | |||
104 | async function buildFileMetadata (path: string, existingProbe?: FfprobeData) { | ||
105 | const metadata = existingProbe || await ffprobePromise(path) | ||
106 | |||
107 | return new VideoFileMetadata(metadata) | ||
108 | } | ||
109 | |||
110 | // --------------------------------------------------------------------------- | ||
111 | |||
64 | export { | 112 | export { |
113 | buildNewFile, | ||
114 | |||
65 | removeHLSPlaylist, | 115 | removeHLSPlaylist, |
66 | removeHLSFile, | 116 | removeHLSFile, |
67 | removeAllWebTorrentFiles, | 117 | removeAllWebTorrentFiles, |
68 | removeWebTorrentFile | 118 | removeWebTorrentFile, |
119 | |||
120 | buildFileMetadata | ||
69 | } | 121 | } |