aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/optimize-old-videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-06 13:35:25 +0200
committerChocobozzz <me@florianbigard.com>2021-08-06 14:13:26 +0200
commit679c12e69c9f3a2d003ee3abe8b8da49f25b2bd3 (patch)
tree03abf589275db05e5b1fa1c89f57049cd807324a /scripts/optimize-old-videos.ts
parentc826f34a45757b324a20f71665b44ed10e6953b5 (diff)
downloadPeerTube-679c12e69c9f3a2d003ee3abe8b8da49f25b2bd3.tar.gz
PeerTube-679c12e69c9f3a2d003ee3abe8b8da49f25b2bd3.tar.zst
PeerTube-679c12e69c9f3a2d003ee3abe8b8da49f25b2bd3.zip
Improve target bitrate calculation
Diffstat (limited to 'scripts/optimize-old-videos.ts')
-rw-r--r--scripts/optimize-old-videos.ts7
1 files changed, 3 insertions, 4 deletions
diff --git a/scripts/optimize-old-videos.ts b/scripts/optimize-old-videos.ts
index bde9d1e01..9e66105dd 100644
--- a/scripts/optimize-old-videos.ts
+++ b/scripts/optimize-old-videos.ts
@@ -1,9 +1,7 @@
1import { registerTSPaths } from '../server/helpers/register-ts-paths' 1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths() 2registerTSPaths()
3 3
4import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
5import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffprobe-utils' 4import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffprobe-utils'
6import { getMaxBitrate } from '../shared/models/videos'
7import { VideoModel } from '../server/models/video/video' 5import { VideoModel } from '../server/models/video/video'
8import { optimizeOriginalVideofile } from '../server/lib/transcoding/video-transcoding' 6import { optimizeOriginalVideofile } from '../server/lib/transcoding/video-transcoding'
9import { initDatabaseModels } from '../server/initializers/database' 7import { initDatabaseModels } from '../server/initializers/database'
@@ -11,6 +9,7 @@ import { basename, dirname } from 'path'
11import { copy, move, remove } from 'fs-extra' 9import { copy, move, remove } from 'fs-extra'
12import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 10import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
13import { getVideoFilePath } from '@server/lib/video-paths' 11import { getVideoFilePath } from '@server/lib/video-paths'
12import { getMaxBitrate } from '@shared/core-utils'
14 13
15run() 14run()
16 .then(() => process.exit(0)) 15 .then(() => process.exit(0))
@@ -42,13 +41,13 @@ async function run () {
42 for (const file of video.VideoFiles) { 41 for (const file of video.VideoFiles) {
43 currentFilePath = getVideoFilePath(video, file) 42 currentFilePath = getVideoFilePath(video, file)
44 43
45 const [ videoBitrate, fps, resolution ] = await Promise.all([ 44 const [ videoBitrate, fps, dataResolution ] = await Promise.all([
46 getVideoFileBitrate(currentFilePath), 45 getVideoFileBitrate(currentFilePath),
47 getVideoFileFPS(currentFilePath), 46 getVideoFileFPS(currentFilePath),
48 getVideoFileResolution(currentFilePath) 47 getVideoFileResolution(currentFilePath)
49 ]) 48 ])
50 49
51 const maxBitrate = getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS) 50 const maxBitrate = getMaxBitrate({ ...dataResolution, fps })
52 const isMaxBitrateExceeded = videoBitrate > maxBitrate 51 const isMaxBitrateExceeded = videoBitrate > maxBitrate
53 if (isMaxBitrateExceeded) { 52 if (isMaxBitrateExceeded) {
54 console.log( 53 console.log(