aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/optimize-old-videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-10-08 16:50:56 +0200
committerChocobozzz <me@florianbigard.com>2018-10-08 16:50:56 +0200
commit9f1ddd249652c1e35b45db33885a00a005f9b059 (patch)
tree193c941c0019e897abf1e12faa504fff912f5546 /scripts/optimize-old-videos.ts
parentedb4ffc7e0b13659d7c73b120f2c87b27e4c26a1 (diff)
downloadPeerTube-9f1ddd249652c1e35b45db33885a00a005f9b059.tar.gz
PeerTube-9f1ddd249652c1e35b45db33885a00a005f9b059.tar.zst
PeerTube-9f1ddd249652c1e35b45db33885a00a005f9b059.zip
Change a little bit optimize-old-videos logic
Diffstat (limited to 'scripts/optimize-old-videos.ts')
-rw-r--r--scripts/optimize-old-videos.ts37
1 files changed, 18 insertions, 19 deletions
diff --git a/scripts/optimize-old-videos.ts b/scripts/optimize-old-videos.ts
index ab44acfbe..02026b3da 100644
--- a/scripts/optimize-old-videos.ts
+++ b/scripts/optimize-old-videos.ts
@@ -1,11 +1,7 @@
1import { join } from 'path' 1import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
2import { readdir } from 'fs-extra' 2import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
3import { CONFIG, VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
4import { getVideoFileResolution, getVideoFileBitrate, getVideoFileFPS } from '../server/helpers/ffmpeg-utils'
5import { getMaxBitrate } from '../shared/models/videos' 3import { getMaxBitrate } from '../shared/models/videos'
6import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy'
7import { VideoModel } from '../server/models/video/video' 4import { VideoModel } from '../server/models/video/video'
8import { getUUIDFromFilename } from '../server/helpers/utils'
9import { optimizeVideofile } from '../server/lib/video-transcoding' 5import { optimizeVideofile } from '../server/lib/video-transcoding'
10 6
11run() 7run()
@@ -16,21 +12,24 @@ run()
16 }) 12 })
17 13
18async function run () { 14async function run () {
19 const files = await readdir(CONFIG.STORAGE.VIDEOS_DIR) 15 const localVideos = await VideoModel.listLocal()
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 16
27 const isLocalVideo = await VideoRedundancyModel.isLocalByVideoUUIDExists(uuid) 17 for (const video of localVideos) {
28 const isMaxBitrateExceeded = 18 for (const file of video.VideoFiles) {
29 videoBitrate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS) 19 const inputPath = video.getVideoFilename(file)
30 if (uuid && isLocalVideo && isMaxBitrateExceeded) { 20
31 const videoModel = await VideoModel.loadByUUIDWithFile(uuid) 21 const [ videoBitrate, fps, resolution ] = await Promise.all([
32 await optimizeVideofile(videoModel, inputPath) 22 getVideoFileBitrate(inputPath),
23 getVideoFileFPS(inputPath),
24 getVideoFileResolution(inputPath)
25 ])
26
27 const isMaxBitrateExceeded = videoBitrate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)
28 if (isMaxBitrateExceeded) {
29 await optimizeVideofile(video, file)
30 }
33 } 31 }
34 } 32 }
33
35 console.log('Finished optimizing videos') 34 console.log('Finished optimizing videos')
36} 35}