diff options
author | Felix Ableitner <me@nutomic.com> | 2018-10-08 09:26:04 -0500 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-08 16:26:04 +0200 |
commit | edb4ffc7e0b13659d7c73b120f2c87b27e4c26a1 (patch) | |
tree | fb9df6826eaeb23ab3bcac7fe21773978c68d27c /scripts | |
parent | 2cae5f13076a31aa95774679aed1f13c3bd5f8ce (diff) | |
download | PeerTube-edb4ffc7e0b13659d7c73b120f2c87b27e4c26a1.tar.gz PeerTube-edb4ffc7e0b13659d7c73b120f2c87b27e4c26a1.tar.zst PeerTube-edb4ffc7e0b13659d7c73b120f2c87b27e4c26a1.zip |
Set bitrate limits for transcoding (fixes #638) (#1135)
* Set bitrate limits for transcoding (fixes #638)
* added optimization script and test, changed stuff
* fix test, improve docs
* re-add optimize-old-videos script
* added documentation
* Don't optimize videos without valid UUID, or redundancy videos
* move getUUIDFromFilename
* fix tests?
* update torrent and file size, some more fixes/improvements
* use higher bitrate for high fps video, adjust bitrates
* add test video
* don't throw error if resolution is undefined
* generate test fixture on the fly
* use random noise video for bitrate test, add promise
* shorten test video to avoid timeout
* use existing function to optimize video
* various fixes
* increase test timeout
* limit test fixture size, add link
* test fixes
* add await
* more test fixes, add -b:v parameter
* replace ffmpeg wiki link
* fix ffmpeg params
* fix unit test
* add test fixture to .gitgnore
* add video transcoding fps model
* add missing file
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/help.sh | 1 | ||||
-rw-r--r-- | scripts/optimize-old-videos.ts | 36 | ||||
-rwxr-xr-x | scripts/prune-storage.ts | 10 |
3 files changed, 38 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" | |||
18 | printf " create-transcoding-job -- -v [video UUID] \n" | 18 | printf " create-transcoding-job -- -v [video UUID] \n" |
19 | printf " -> Create a transcoding job for a particular video\n" | 19 | printf " -> Create a transcoding job for a particular video\n" |
20 | printf " prune-storage -> Delete (after confirmation) unknown video files/thumbnails/previews... (due to a bad video deletion, transcoding job not finished...)\n" | 20 | printf " prune-storage -> Delete (after confirmation) unknown video files/thumbnails/previews... (due to a bad video deletion, transcoding job not finished...)\n" |
21 | printf " optimize-old-videos -> Re-transcode videos that have a high bitrate, to make them suitable for streaming over slow connections" | ||
21 | printf " dev -> Watch, run the livereload and run the server so that you can develop the application\n" | 22 | printf " dev -> Watch, run the livereload and run the server so that you can develop the application\n" |
22 | printf " start -> Run the server\n" | 23 | printf " start -> Run the server\n" |
23 | printf " update-host -> Upgrade scheme/host in torrent files according to the webserver configuration (config/ folder)\n" | 24 | 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 new file mode 100644 index 000000000..ab44acfbe --- /dev/null +++ b/scripts/optimize-old-videos.ts | |||
@@ -0,0 +1,36 @@ | |||
1 | import { join } from 'path' | ||
2 | import { readdir } from 'fs-extra' | ||
3 | import { CONFIG, VIDEO_TRANSCODING_FPS } from '../server/initializers/constants' | ||
4 | import { getVideoFileResolution, getVideoFileBitrate, getVideoFileFPS } from '../server/helpers/ffmpeg-utils' | ||
5 | import { getMaxBitrate } from '../shared/models/videos' | ||
6 | import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' | ||
7 | import { VideoModel } from '../server/models/video/video' | ||
8 | import { getUUIDFromFilename } from '../server/helpers/utils' | ||
9 | import { optimizeVideofile } from '../server/lib/video-transcoding' | ||
10 | |||
11 | run() | ||
12 | .then(() => process.exit(0)) | ||
13 | .catch(err => { | ||
14 | console.error(err) | ||
15 | process.exit(-1) | ||
16 | }) | ||
17 | |||
18 | async function run () { | ||
19 | const files = await readdir(CONFIG.STORAGE.VIDEOS_DIR) | ||
20 | for (const file of files) { | ||
21 | const inputPath = join(CONFIG.STORAGE.VIDEOS_DIR, file) | ||
22 | const videoBitrate = await getVideoFileBitrate(inputPath) | ||
23 | const fps = await getVideoFileFPS(inputPath) | ||
24 | const resolution = await getVideoFileResolution(inputPath) | ||
25 | const uuid = getUUIDFromFilename(file) | ||
26 | |||
27 | const isLocalVideo = await VideoRedundancyModel.isLocalByVideoUUIDExists(uuid) | ||
28 | const isMaxBitrateExceeded = | ||
29 | videoBitrate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS) | ||
30 | if (uuid && isLocalVideo && isMaxBitrateExceeded) { | ||
31 | const videoModel = await VideoModel.loadByUUIDWithFile(uuid) | ||
32 | await optimizeVideofile(videoModel, inputPath) | ||
33 | } | ||
34 | } | ||
35 | console.log('Finished optimizing videos') | ||
36 | } | ||
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' | |||
5 | import { initDatabaseModels } from '../server/initializers' | 5 | import { initDatabaseModels } from '../server/initializers' |
6 | import { remove, readdir } from 'fs-extra' | 6 | import { remove, readdir } from 'fs-extra' |
7 | import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' | 7 | import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' |
8 | import { getUUIDFromFilename } from '../server/helpers/utils' | ||
8 | 9 | ||
9 | run() | 10 | run() |
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 | ||
85 | function 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 | |||
94 | async function askConfirmation () { | 86 | async function askConfirmation () { |
95 | return new Promise((res, rej) => { | 87 | return new Promise((res, rej) => { |
96 | prompt.start() | 88 | prompt.start() |