diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-17 10:33:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-17 10:33:36 +0200 |
commit | 66a7fc947321b923fa1e7182202e03d0e21ffb3e (patch) | |
tree | 5cb913531d3b84d0f2d4bbcc0d34f0a9a6435bc5 /scripts | |
parent | 0305db28c98fd6cf43a3c50ba92c76215e99d512 (diff) | |
download | PeerTube-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-x | scripts/help.sh | 1 | ||||
-rw-r--r-- | scripts/optimize-old-videos.ts | 92 |
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" | |||
13 | printf " create-transcoding-job -- -v [video UUID] \n" | 13 | printf " create-transcoding-job -- -v [video UUID] \n" |
14 | printf " -> Create a transcoding job for a particular video\n" | 14 | printf " -> Create a transcoding job for a particular video\n" |
15 | printf " prune-storage -> Delete (after confirmation) unknown video files/thumbnails/previews... (due to a bad video deletion, transcoding job not finished...)\n" | 15 | printf " prune-storage -> Delete (after confirmation) unknown video files/thumbnails/previews... (due to a bad video deletion, transcoding job not finished...)\n" |
16 | printf " optimize-old-videos -> Re-transcode videos that have a high bitrate, to make them suitable for streaming over slow connections" | ||
17 | printf " dev -> Watch, run the livereload and run the server so that you can develop the application\n" | 16 | printf " dev -> Watch, run the livereload and run the server so that you can develop the application\n" |
18 | printf " start -> Run the server\n" | 17 | printf " start -> Run the server\n" |
19 | printf " update-host -> Upgrade scheme/host in torrent files according to the webserver configuration (config/ folder)\n" | 18 | printf " 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 @@ | |||
1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' | ||
2 | registerTSPaths() | ||
3 | |||
4 | import { copy, move, remove } from 'fs-extra' | ||
5 | import { basename, dirname } from 'path' | ||
6 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | ||
7 | import { CONFIG } from '@server/initializers/config' | ||
8 | import { processMoveToObjectStorage } from '@server/lib/job-queue/handlers/move-to-object-storage' | ||
9 | import { VideoPathManager } from '@server/lib/video-path-manager' | ||
10 | import { getMaxBitrate } from '@shared/core-utils' | ||
11 | import { MoveObjectStoragePayload } from '@shared/models' | ||
12 | import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffprobe-utils' | ||
13 | import { initDatabaseModels } from '../server/initializers/database' | ||
14 | import { optimizeOriginalVideofile } from '../server/lib/transcoding/video-transcoding' | ||
15 | import { VideoModel } from '../server/models/video/video' | ||
16 | |||
17 | run() | ||
18 | .then(() => process.exit(0)) | ||
19 | .catch(err => { | ||
20 | console.error(err) | ||
21 | process.exit(-1) | ||
22 | }) | ||
23 | |||
24 | let currentVideoId: string | ||
25 | let currentFilePath: string | ||
26 | |||
27 | process.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 | |||
34 | async 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 | } | ||