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