diff options
Diffstat (limited to 'scripts/optimize-old-videos.ts')
-rw-r--r-- | scripts/optimize-old-videos.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/optimize-old-videos.ts b/scripts/optimize-old-videos.ts new file mode 100644 index 000000000..ab44acfbe --- /dev/null +++ b/scripts/optimize-old-videos.ts | |||
@@ -0,0 +1,36 @@ | |||
1 | import { join } from 'path' | ||
2 | import { readdir } from 'fs-extra' | ||
3 | import { CONFIG, VIDEO_TRANSCODING_FPS } from '../server/initializers/constants' | ||
4 | import { getVideoFileResolution, getVideoFileBitrate, getVideoFileFPS } from '../server/helpers/ffmpeg-utils' | ||
5 | import { getMaxBitrate } from '../shared/models/videos' | ||
6 | import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' | ||
7 | import { VideoModel } from '../server/models/video/video' | ||
8 | import { getUUIDFromFilename } from '../server/helpers/utils' | ||
9 | import { optimizeVideofile } from '../server/lib/video-transcoding' | ||
10 | |||
11 | run() | ||
12 | .then(() => process.exit(0)) | ||
13 | .catch(err => { | ||
14 | console.error(err) | ||
15 | process.exit(-1) | ||
16 | }) | ||
17 | |||
18 | async function run () { | ||
19 | const files = await readdir(CONFIG.STORAGE.VIDEOS_DIR) | ||
20 | for (const file of files) { | ||
21 | const inputPath = join(CONFIG.STORAGE.VIDEOS_DIR, file) | ||
22 | const videoBitrate = await getVideoFileBitrate(inputPath) | ||
23 | const fps = await getVideoFileFPS(inputPath) | ||
24 | const resolution = await getVideoFileResolution(inputPath) | ||
25 | const uuid = getUUIDFromFilename(file) | ||
26 | |||
27 | const isLocalVideo = await VideoRedundancyModel.isLocalByVideoUUIDExists(uuid) | ||
28 | const isMaxBitrateExceeded = | ||
29 | videoBitrate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS) | ||
30 | if (uuid && isLocalVideo && isMaxBitrateExceeded) { | ||
31 | const videoModel = await VideoModel.loadByUUIDWithFile(uuid) | ||
32 | await optimizeVideofile(videoModel, inputPath) | ||
33 | } | ||
34 | } | ||
35 | console.log('Finished optimizing videos') | ||
36 | } | ||