1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Change a little bit optimize-old-videos logic

This commit is contained in:
Chocobozzz 2018-10-08 16:50:56 +02:00
parent edb4ffc7e0
commit 9f1ddd2496
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 33 additions and 28 deletions

View file

@ -1,11 +1,7 @@
import { join } from 'path'
import { readdir } from 'fs-extra'
import { CONFIG, VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
import { getVideoFileResolution, getVideoFileBitrate, getVideoFileFPS } from '../server/helpers/ffmpeg-utils'
import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
import { getMaxBitrate } from '../shared/models/videos'
import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy'
import { VideoModel } from '../server/models/video/video'
import { getUUIDFromFilename } from '../server/helpers/utils'
import { optimizeVideofile } from '../server/lib/video-transcoding'
run()
@ -16,21 +12,24 @@ run()
})
async function run () {
const files = await readdir(CONFIG.STORAGE.VIDEOS_DIR)
for (const file of files) {
const inputPath = join(CONFIG.STORAGE.VIDEOS_DIR, file)
const videoBitrate = await getVideoFileBitrate(inputPath)
const fps = await getVideoFileFPS(inputPath)
const resolution = await getVideoFileResolution(inputPath)
const uuid = getUUIDFromFilename(file)
const localVideos = await VideoModel.listLocal()
const isLocalVideo = await VideoRedundancyModel.isLocalByVideoUUIDExists(uuid)
const isMaxBitrateExceeded =
videoBitrate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)
if (uuid && isLocalVideo && isMaxBitrateExceeded) {
const videoModel = await VideoModel.loadByUUIDWithFile(uuid)
await optimizeVideofile(videoModel, inputPath)
for (const video of localVideos) {
for (const file of video.VideoFiles) {
const inputPath = video.getVideoFilename(file)
const [ videoBitrate, fps, resolution ] = await Promise.all([
getVideoFileBitrate(inputPath),
getVideoFileFPS(inputPath),
getVideoFileResolution(inputPath)
])
const isMaxBitrateExceeded = videoBitrate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)
if (isMaxBitrateExceeded) {
await optimizeVideofile(video, file)
}
}
}
console.log('Finished optimizing videos')
}