aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-17 10:33:36 +0200
committerChocobozzz <me@florianbigard.com>2021-08-17 10:33:36 +0200
commit66a7fc947321b923fa1e7182202e03d0e21ffb3e (patch)
tree5cb913531d3b84d0f2d4bbcc0d34f0a9a6435bc5 /scripts
parent0305db28c98fd6cf43a3c50ba92c76215e99d512 (diff)
downloadPeerTube-66a7fc947321b923fa1e7182202e03d0e21ffb3e.tar.gz
PeerTube-66a7fc947321b923fa1e7182202e03d0e21ffb3e.tar.zst
PeerTube-66a7fc947321b923fa1e7182202e03d0e21ffb3e.zip
Remove optimize old videos script
It is not compatible with HLS and I don't have time to maintain it
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/help.sh1
-rw-r--r--scripts/optimize-old-videos.ts92
2 files changed, 0 insertions, 93 deletions
diff --git a/scripts/help.sh b/scripts/help.sh
index da127092d..b58f52fa0 100755
--- a/scripts/help.sh
+++ b/scripts/help.sh
@@ -13,7 +13,6 @@ printf " reset-password -- -u [user] -> Reset the password of user [user]\n"
13printf " create-transcoding-job -- -v [video UUID] \n" 13printf " create-transcoding-job -- -v [video UUID] \n"
14printf " -> Create a transcoding job for a particular video\n" 14printf " -> Create a transcoding job for a particular video\n"
15printf " prune-storage -> Delete (after confirmation) unknown video files/thumbnails/previews... (due to a bad video deletion, transcoding job not finished...)\n" 15printf " prune-storage -> Delete (after confirmation) unknown video files/thumbnails/previews... (due to a bad video deletion, transcoding job not finished...)\n"
16printf " optimize-old-videos -> Re-transcode videos that have a high bitrate, to make them suitable for streaming over slow connections"
17printf " dev -> Watch, run the livereload and run the server so that you can develop the application\n" 16printf " dev -> Watch, run the livereload and run the server so that you can develop the application\n"
18printf " start -> Run the server\n" 17printf " start -> Run the server\n"
19printf " update-host -> Upgrade scheme/host in torrent files according to the webserver configuration (config/ folder)\n" 18printf " update-host -> Upgrade scheme/host in torrent files according to the webserver configuration (config/ folder)\n"
diff --git a/scripts/optimize-old-videos.ts b/scripts/optimize-old-videos.ts
deleted file mode 100644
index 245e4cf28..000000000
--- a/scripts/optimize-old-videos.ts
+++ /dev/null
@@ -1,92 +0,0 @@
1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths()
3
4import { copy, move, remove } from 'fs-extra'
5import { basename, dirname } from 'path'
6import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
7import { CONFIG } from '@server/initializers/config'
8import { processMoveToObjectStorage } from '@server/lib/job-queue/handlers/move-to-object-storage'
9import { VideoPathManager } from '@server/lib/video-path-manager'
10import { getMaxBitrate } from '@shared/core-utils'
11import { MoveObjectStoragePayload } from '@shared/models'
12import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffprobe-utils'
13import { initDatabaseModels } from '../server/initializers/database'
14import { optimizeOriginalVideofile } from '../server/lib/transcoding/video-transcoding'
15import { VideoModel } from '../server/models/video/video'
16
17run()
18 .then(() => process.exit(0))
19 .catch(err => {
20 console.error(err)
21 process.exit(-1)
22 })
23
24let currentVideoId: string
25let currentFilePath: string
26
27process.on('SIGINT', async function () {
28 console.log('Cleaning up temp files')
29 await remove(`${currentFilePath}_backup`)
30 await remove(`${dirname(currentFilePath)}/${currentVideoId}-transcoded.mp4`)
31 process.exit(0)
32})
33
34async function run () {
35 await initDatabaseModels(true)
36
37 const localVideos = await VideoModel.listLocal()
38
39 for (const localVideo of localVideos) {
40 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(localVideo.id)
41
42 currentVideoId = video.id
43
44 for (const file of video.VideoFiles) {
45 await VideoPathManager.Instance.makeAvailableVideoFile(video, file, async path => {
46 currentFilePath = path
47
48 const [ videoBitrate, fps, dataResolution ] = await Promise.all([
49 getVideoFileBitrate(currentFilePath),
50 getVideoFileFPS(currentFilePath),
51 getVideoFileResolution(currentFilePath)
52 ])
53
54 const maxBitrate = getMaxBitrate({ ...dataResolution, fps })
55 const isMaxBitrateExceeded = videoBitrate > maxBitrate
56 if (isMaxBitrateExceeded) {
57 console.log(
58 'Optimizing video file %s with bitrate %s kbps (max: %s kbps)',
59 basename(currentFilePath), videoBitrate / 1000, maxBitrate / 1000
60 )
61
62 const backupFile = `${currentFilePath}_backup`
63 await copy(currentFilePath, backupFile)
64
65 await optimizeOriginalVideofile(video, file)
66 // Update file path, the video filename changed
67 currentFilePath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, file)
68
69 const originalDuration = await getDurationFromVideoFile(backupFile)
70 const newDuration = await getDurationFromVideoFile(currentFilePath)
71
72 if (originalDuration === newDuration) {
73 console.log('Finished optimizing %s', basename(currentFilePath))
74 await remove(backupFile)
75 return
76 }
77
78 console.log('Failed to optimize %s, restoring original', basename(currentFilePath))
79 await move(backupFile, currentFilePath, { overwrite: true })
80 await createTorrentAndSetInfoHash(video, file)
81 await file.save()
82 }
83 })
84 }
85
86 if (CONFIG.OBJECT_STORAGE.ENABLED === true) {
87 await processMoveToObjectStorage({ data: { videoUUID: video.uuid } as MoveObjectStoragePayload } as any)
88 }
89 }
90
91 console.log('Finished optimizing videos')
92}