aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/help.sh1
-rw-r--r--scripts/optimize-old-videos.ts35
-rwxr-xr-xscripts/prune-storage.ts10
3 files changed, 37 insertions, 9 deletions
diff --git a/scripts/help.sh b/scripts/help.sh
index 8ac090139..bc38bdb40 100755
--- a/scripts/help.sh
+++ b/scripts/help.sh
@@ -18,6 +18,7 @@ printf " reset-password -- -u [user] -> Reset the password of user [user]\n"
18printf " create-transcoding-job -- -v [video UUID] \n" 18printf " create-transcoding-job -- -v [video UUID] \n"
19printf " -> Create a transcoding job for a particular video\n" 19printf " -> Create a transcoding job for a particular video\n"
20printf " prune-storage -> Delete (after confirmation) unknown video files/thumbnails/previews... (due to a bad video deletion, transcoding job not finished...)\n" 20printf " prune-storage -> Delete (after confirmation) unknown video files/thumbnails/previews... (due to a bad video deletion, transcoding job not finished...)\n"
21printf " optimize-old-videos -> Re-transcode videos that have a high bitrate, to make them suitable for streaming over slow connections"
21printf " dev -> Watch, run the livereload and run the server so that you can develop the application\n" 22printf " dev -> Watch, run the livereload and run the server so that you can develop the application\n"
22printf " start -> Run the server\n" 23printf " start -> Run the server\n"
23printf " update-host -> Upgrade scheme/host in torrent files according to the webserver configuration (config/ folder)\n" 24printf " 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
new file mode 100644
index 000000000..02026b3da
--- /dev/null
+++ b/scripts/optimize-old-videos.ts
@@ -0,0 +1,35 @@
1import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
2import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
3import { getMaxBitrate } from '../shared/models/videos'
4import { VideoModel } from '../server/models/video/video'
5import { optimizeVideofile } from '../server/lib/video-transcoding'
6
7run()
8 .then(() => process.exit(0))
9 .catch(err => {
10 console.error(err)
11 process.exit(-1)
12 })
13
14async function run () {
15 const localVideos = await VideoModel.listLocal()
16
17 for (const video of localVideos) {
18 for (const file of video.VideoFiles) {
19 const inputPath = video.getVideoFilename(file)
20
21 const [ videoBitrate, fps, resolution ] = await Promise.all([
22 getVideoFileBitrate(inputPath),
23 getVideoFileFPS(inputPath),
24 getVideoFileResolution(inputPath)
25 ])
26
27 const isMaxBitrateExceeded = videoBitrate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)
28 if (isMaxBitrateExceeded) {
29 await optimizeVideofile(video, file)
30 }
31 }
32 }
33
34 console.log('Finished optimizing videos')
35}
diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts
index 4088fa700..4ab0b4863 100755
--- a/scripts/prune-storage.ts
+++ b/scripts/prune-storage.ts
@@ -5,6 +5,7 @@ import { VideoModel } from '../server/models/video/video'
5import { initDatabaseModels } from '../server/initializers' 5import { initDatabaseModels } from '../server/initializers'
6import { remove, readdir } from 'fs-extra' 6import { remove, readdir } from 'fs-extra'
7import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' 7import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy'
8import { getUUIDFromFilename } from '../server/helpers/utils'
8 9
9run() 10run()
10 .then(() => process.exit(0)) 11 .then(() => process.exit(0))
@@ -82,15 +83,6 @@ async function pruneDirectory (directory: string, onlyOwned = false) {
82 return toDelete 83 return toDelete
83} 84}
84 85
85function getUUIDFromFilename (filename: string) {
86 const regex = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
87 const result = filename.match(regex)
88
89 if (!result || Array.isArray(result) === false) return null
90
91 return result[0]
92}
93
94async function askConfirmation () { 86async function askConfirmation () {
95 return new Promise((res, rej) => { 87 return new Promise((res, rej) => {
96 prompt.start() 88 prompt.start()