aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/optimize-old-videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/optimize-old-videos.ts')
-rw-r--r--scripts/optimize-old-videos.ts39
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 @@
1import { CONFIG, VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
2import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
3import { getMaxBitrate } from '../shared/models/videos'
4import { VideoModel } from '../server/models/video/video'
5import { optimizeVideofile } from '../server/lib/video-transcoding'
6import { initDatabaseModels } from '../server/initializers'
7import { join } from 'path'
8
9run()
10 .then(() => process.exit(0))
11 .catch(err => {
12 console.error(err)
13 process.exit(-1)
14 })
15
16async 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}