]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/optimize-old-videos.ts
Fix webtorrent disabled by default
[github/Chocobozzz/PeerTube.git] / scripts / optimize-old-videos.ts
CommitLineData
74cd011b 1import { CONFIG, VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
9f1ddd24 2import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
edb4ffc7 3import { getMaxBitrate } from '../shared/models/videos'
edb4ffc7 4import { VideoModel } from '../server/models/video/video'
edb4ffc7 5import { optimizeVideofile } from '../server/lib/video-transcoding'
74cd011b
C
6import { initDatabaseModels } from '../server/initializers'
7import { join } from 'path'
edb4ffc7
FA
8
9run()
10 .then(() => process.exit(0))
11 .catch(err => {
12 console.error(err)
13 process.exit(-1)
14 })
15
16async function run () {
74cd011b
C
17 await initDatabaseModels(true)
18
9f1ddd24 19 const localVideos = await VideoModel.listLocal()
edb4ffc7 20
9f1ddd24
C
21 for (const video of localVideos) {
22 for (const file of video.VideoFiles) {
74cd011b 23 const inputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file))
9f1ddd24
C
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 }
edb4ffc7
FA
35 }
36 }
9f1ddd24 37
edb4ffc7
FA
38 console.log('Finished optimizing videos')
39}