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'
10 .then(() => process.exit(0))
16 async function run () {
17 await initDatabaseModels(true)
19 const localVideos = await VideoModel.listLocal()
21 for (const video of localVideos) {
22 for (const file of video.VideoFiles) {
23 const inputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file))
25 const [ videoBitrate, fps, resolution ] = await Promise.all([
26 getVideoFileBitrate(inputPath),
27 getVideoFileFPS(inputPath),
28 getVideoFileResolution(inputPath)
31 const isMaxBitrateExceeded = videoBitrate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)
32 if (isMaxBitrateExceeded) {
33 await optimizeVideofile(video, file)
38 console.log('Finished optimizing videos')