aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/optimize-old-videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/optimize-old-videos.ts')
-rw-r--r--scripts/optimize-old-videos.ts17
1 files changed, 9 insertions, 8 deletions
diff --git a/scripts/optimize-old-videos.ts b/scripts/optimize-old-videos.ts
index eb61ec43c..107483c50 100644
--- a/scripts/optimize-old-videos.ts
+++ b/scripts/optimize-old-videos.ts
@@ -1,15 +1,16 @@
1import { registerTSPaths } from '../server/helpers/register-ts-paths' 1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths()
3
4import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants' 2import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
5import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils' 3import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
6import { getMaxBitrate } from '../shared/models/videos' 4import { getMaxBitrate } from '../shared/models/videos'
7import { VideoModel } from '../server/models/video/video' 5import { VideoModel } from '../server/models/video/video'
8import { optimizeVideofile } from '../server/lib/video-transcoding' 6import { optimizeOriginalVideofile } from '../server/lib/video-transcoding'
9import { initDatabaseModels } from '../server/initializers' 7import { initDatabaseModels } from '../server/initializers'
10import { basename, dirname, join } from 'path' 8import { basename, dirname } from 'path'
11import { copy, move, remove } from 'fs-extra' 9import { copy, move, remove } from 'fs-extra'
12import { CONFIG } from '../server/initializers/config' 10import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
11import { getVideoFilePath } from '@server/lib/video-paths'
12
13registerTSPaths()
13 14
14run() 15run()
15 .then(() => process.exit(0)) 16 .then(() => process.exit(0))
@@ -37,7 +38,7 @@ async function run () {
37 currentVideoId = video.id 38 currentVideoId = video.id
38 39
39 for (const file of video.VideoFiles) { 40 for (const file of video.VideoFiles) {
40 currentFile = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file)) 41 currentFile = getVideoFilePath(video, file)
41 42
42 const [ videoBitrate, fps, resolution ] = await Promise.all([ 43 const [ videoBitrate, fps, resolution ] = await Promise.all([
43 getVideoFileBitrate(currentFile), 44 getVideoFileBitrate(currentFile),
@@ -56,7 +57,7 @@ async function run () {
56 const backupFile = `${currentFile}_backup` 57 const backupFile = `${currentFile}_backup`
57 await copy(currentFile, backupFile) 58 await copy(currentFile, backupFile)
58 59
59 await optimizeVideofile(video, file) 60 await optimizeOriginalVideofile(video, file)
60 61
61 const originalDuration = await getDurationFromVideoFile(backupFile) 62 const originalDuration = await getDurationFromVideoFile(backupFile)
62 const newDuration = await getDurationFromVideoFile(currentFile) 63 const newDuration = await getDurationFromVideoFile(currentFile)
@@ -69,7 +70,7 @@ async function run () {
69 70
70 console.log('Failed to optimize %s, restoring original', basename(currentFile)) 71 console.log('Failed to optimize %s, restoring original', basename(currentFile))
71 await move(backupFile, currentFile, { overwrite: true }) 72 await move(backupFile, currentFile, { overwrite: true })
72 await video.createTorrentAndSetInfoHash(file) 73 await createTorrentAndSetInfoHash(video, file)
73 await file.save() 74 await file.save()
74 } 75 }
75 } 76 }