]>
Commit | Line | Data |
---|---|---|
9f1ddd24 C |
1 | import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants' |
2 | import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils' | |
edb4ffc7 | 3 | import { getMaxBitrate } from '../shared/models/videos' |
edb4ffc7 | 4 | import { VideoModel } from '../server/models/video/video' |
edb4ffc7 FA |
5 | import { optimizeVideofile } from '../server/lib/video-transcoding' |
6 | ||
7 | run() | |
8 | .then(() => process.exit(0)) | |
9 | .catch(err => { | |
10 | console.error(err) | |
11 | process.exit(-1) | |
12 | }) | |
13 | ||
14 | async function run () { | |
9f1ddd24 | 15 | const localVideos = await VideoModel.listLocal() |
edb4ffc7 | 16 | |
9f1ddd24 C |
17 | for (const video of localVideos) { |
18 | for (const file of video.VideoFiles) { | |
19 | const inputPath = video.getVideoFilename(file) | |
20 | ||
21 | const [ videoBitrate, fps, resolution ] = await Promise.all([ | |
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 | } | |
edb4ffc7 FA |
31 | } |
32 | } | |
9f1ddd24 | 33 | |
edb4ffc7 FA |
34 | console.log('Finished optimizing videos') |
35 | } |