aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/ci.sh3
-rwxr-xr-xscripts/create-transcoding-job.ts13
-rw-r--r--scripts/optimize-old-videos.ts91
3 files changed, 61 insertions, 46 deletions
diff --git a/scripts/ci.sh b/scripts/ci.sh
index 71b1be53b..f49dbe6ad 100755
--- a/scripts/ci.sh
+++ b/scripts/ci.sh
@@ -89,9 +89,10 @@ elif [ "$1" = "api-4" ]; then
89 89
90 moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation) 90 moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation)
91 redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy) 91 redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy)
92 objectStorageFiles=$(findTestFiles ./dist/server/tests/api/object-storage)
92 activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub) 93 activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub)
93 94
94 MOCHA_PARALLEL=true TS_NODE_FILES=true runTest "$1" 2 $moderationFiles $redundancyFiles $activitypubFiles 95 MOCHA_PARALLEL=true TS_NODE_FILES=true runTest "$1" 2 $moderationFiles $redundancyFiles $activitypubFiles $objectStorageFiles
95elif [ "$1" = "external-plugins" ]; then 96elif [ "$1" = "external-plugins" ]; then
96 npm run build:server 97 npm run build:server
97 98
diff --git a/scripts/create-transcoding-job.ts b/scripts/create-transcoding-job.ts
index 3a552c19a..0bb9bfeab 100755
--- a/scripts/create-transcoding-job.ts
+++ b/scripts/create-transcoding-job.ts
@@ -6,9 +6,10 @@ import { VideoModel } from '../server/models/video/video'
6import { initDatabaseModels } from '../server/initializers/database' 6import { initDatabaseModels } from '../server/initializers/database'
7import { JobQueue } from '../server/lib/job-queue' 7import { JobQueue } from '../server/lib/job-queue'
8import { computeResolutionsToTranscode } from '@server/helpers/ffprobe-utils' 8import { computeResolutionsToTranscode } from '@server/helpers/ffprobe-utils'
9import { VideoTranscodingPayload } from '@shared/models' 9import { VideoState, VideoTranscodingPayload } from '@shared/models'
10import { CONFIG } from '@server/initializers/config' 10import { CONFIG } from '@server/initializers/config'
11import { isUUIDValid } from '@server/helpers/custom-validators/misc' 11import { isUUIDValid } from '@server/helpers/custom-validators/misc'
12import { addTranscodingJob } from '@server/lib/video'
12 13
13program 14program
14 .option('-v, --video [videoUUID]', 'Video UUID') 15 .option('-v, --video [videoUUID]', 'Video UUID')
@@ -47,7 +48,7 @@ async function run () {
47 if (!video) throw new Error('Video not found.') 48 if (!video) throw new Error('Video not found.')
48 49
49 const dataInput: VideoTranscodingPayload[] = [] 50 const dataInput: VideoTranscodingPayload[] = []
50 const { resolution } = await video.getMaxQualityResolution() 51 const resolution = video.getMaxQualityFile().resolution
51 52
52 // Generate HLS files 53 // Generate HLS files
53 if (options.generateHls || CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) { 54 if (options.generateHls || CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) {
@@ -62,6 +63,7 @@ async function run () {
62 resolution, 63 resolution,
63 isPortraitMode: false, 64 isPortraitMode: false,
64 copyCodecs: false, 65 copyCodecs: false,
66 isNewVideo: false,
65 isMaxQuality: false 67 isMaxQuality: false
66 }) 68 })
67 } 69 }
@@ -87,10 +89,13 @@ async function run () {
87 } 89 }
88 } 90 }
89 91
90 await JobQueue.Instance.init() 92 JobQueue.Instance.init()
93
94 video.state = VideoState.TO_TRANSCODE
95 await video.save()
91 96
92 for (const d of dataInput) { 97 for (const d of dataInput) {
93 await JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: d }) 98 await addTranscodingJob(d, {})
94 console.log('Transcoding job for video %s created.', video.uuid) 99 console.log('Transcoding job for video %s created.', video.uuid)
95 } 100 }
96} 101}
diff --git a/scripts/optimize-old-videos.ts b/scripts/optimize-old-videos.ts
index 9e66105dd..245e4cf28 100644
--- a/scripts/optimize-old-videos.ts
+++ b/scripts/optimize-old-videos.ts
@@ -1,15 +1,18 @@
1import { registerTSPaths } from '../server/helpers/register-ts-paths' 1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths() 2registerTSPaths()
3 3
4import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffprobe-utils'
5import { VideoModel } from '../server/models/video/video'
6import { optimizeOriginalVideofile } from '../server/lib/transcoding/video-transcoding'
7import { initDatabaseModels } from '../server/initializers/database'
8import { basename, dirname } from 'path'
9import { copy, move, remove } from 'fs-extra' 4import { copy, move, remove } from 'fs-extra'
5import { basename, dirname } from 'path'
10import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 6import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
11import { getVideoFilePath } from '@server/lib/video-paths' 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'
12import { getMaxBitrate } from '@shared/core-utils' 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'
13 16
14run() 17run()
15 .then(() => process.exit(0)) 18 .then(() => process.exit(0))
@@ -39,43 +42,49 @@ async function run () {
39 currentVideoId = video.id 42 currentVideoId = video.id
40 43
41 for (const file of video.VideoFiles) { 44 for (const file of video.VideoFiles) {
42 currentFilePath = getVideoFilePath(video, file) 45 await VideoPathManager.Instance.makeAvailableVideoFile(video, file, async path => {
43 46 currentFilePath = path
44 const [ videoBitrate, fps, dataResolution ] = await Promise.all([ 47
45 getVideoFileBitrate(currentFilePath), 48 const [ videoBitrate, fps, dataResolution ] = await Promise.all([
46 getVideoFileFPS(currentFilePath), 49 getVideoFileBitrate(currentFilePath),
47 getVideoFileResolution(currentFilePath) 50 getVideoFileFPS(currentFilePath),
48 ]) 51 getVideoFileResolution(currentFilePath)
49 52 ])
50 const maxBitrate = getMaxBitrate({ ...dataResolution, fps }) 53
51 const isMaxBitrateExceeded = videoBitrate > maxBitrate 54 const maxBitrate = getMaxBitrate({ ...dataResolution, fps })
52 if (isMaxBitrateExceeded) { 55 const isMaxBitrateExceeded = videoBitrate > maxBitrate
53 console.log( 56 if (isMaxBitrateExceeded) {
54 'Optimizing video file %s with bitrate %s kbps (max: %s kbps)', 57 console.log(
55 basename(currentFilePath), videoBitrate / 1000, maxBitrate / 1000 58 'Optimizing video file %s with bitrate %s kbps (max: %s kbps)',
56 ) 59 basename(currentFilePath), videoBitrate / 1000, maxBitrate / 1000
57 60 )
58 const backupFile = `${currentFilePath}_backup` 61
59 await copy(currentFilePath, backupFile) 62 const backupFile = `${currentFilePath}_backup`
60 63 await copy(currentFilePath, backupFile)
61 await optimizeOriginalVideofile(video, file) 64
62 // Update file path, the video filename changed 65 await optimizeOriginalVideofile(video, file)
63 currentFilePath = getVideoFilePath(video, file) 66 // Update file path, the video filename changed
64 67 currentFilePath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, file)
65 const originalDuration = await getDurationFromVideoFile(backupFile) 68
66 const newDuration = await getDurationFromVideoFile(currentFilePath) 69 const originalDuration = await getDurationFromVideoFile(backupFile)
67 70 const newDuration = await getDurationFromVideoFile(currentFilePath)
68 if (originalDuration === newDuration) { 71
69 console.log('Finished optimizing %s', basename(currentFilePath)) 72 if (originalDuration === newDuration) {
70 await remove(backupFile) 73 console.log('Finished optimizing %s', basename(currentFilePath))
71 continue 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()
72 } 82 }
83 })
84 }
73 85
74 console.log('Failed to optimize %s, restoring original', basename(currentFilePath)) 86 if (CONFIG.OBJECT_STORAGE.ENABLED === true) {
75 await move(backupFile, currentFilePath, { overwrite: true }) 87 await processMoveToObjectStorage({ data: { videoUUID: video.uuid } as MoveObjectStoragePayload } as any)
76 await createTorrentAndSetInfoHash(video, file)
77 await file.save()
78 }
79 } 88 }
80 } 89 }
81 90