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 /server/lib | |
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 'server/lib')
-rw-r--r-- | server/lib/activitypub/crawl.ts | 2 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-file.ts | 4 | ||||
-rw-r--r-- | server/lib/video-transcoding.ts | 15 |
3 files changed, 13 insertions, 8 deletions
diff --git a/server/lib/activitypub/crawl.ts b/server/lib/activitypub/crawl.ts index 55912341c..db9ce3293 100644 --- a/server/lib/activitypub/crawl.ts +++ b/server/lib/activitypub/crawl.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { ACTIVITY_PUB, JOB_REQUEST_TIMEOUT } from '../../initializers' | 1 | import { ACTIVITY_PUB, JOB_REQUEST_TIMEOUT } from '../../initializers' |
2 | import { doRequest } from '../../helpers/requests' | 2 | import { doRequest } from '../../helpers/requests' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import Bluebird = require('bluebird') | 4 | import * as Bluebird from 'bluebird' |
5 | 5 | ||
6 | async function crawlCollectionPage <T> (uri: string, handler: (items: T[]) => Promise<any> | Bluebird<any>) { | 6 | async function crawlCollectionPage <T> (uri: string, handler: (items: T[]) => Promise<any> | Bluebird<any>) { |
7 | logger.info('Crawling ActivityPub data on %s.', uri) | 7 | logger.info('Crawling ActivityPub data on %s.', uri) |
diff --git a/server/lib/job-queue/handlers/video-file.ts b/server/lib/job-queue/handlers/video-file.ts index 1463c93fc..adc0a2a15 100644 --- a/server/lib/job-queue/handlers/video-file.ts +++ b/server/lib/job-queue/handlers/video-file.ts | |||
@@ -8,7 +8,7 @@ import { retryTransactionWrapper } from '../../../helpers/database-utils' | |||
8 | import { sequelizeTypescript } from '../../../initializers' | 8 | import { sequelizeTypescript } from '../../../initializers' |
9 | import * as Bluebird from 'bluebird' | 9 | import * as Bluebird from 'bluebird' |
10 | import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' | 10 | import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' |
11 | import { importVideoFile, transcodeOriginalVideofile, optimizeOriginalVideofile } from '../../video-transcoding' | 11 | import { importVideoFile, transcodeOriginalVideofile, optimizeVideofile } from '../../video-transcoding' |
12 | 12 | ||
13 | export type VideoFilePayload = { | 13 | export type VideoFilePayload = { |
14 | videoUUID: string | 14 | videoUUID: string |
@@ -56,7 +56,7 @@ async function processVideoFile (job: Bull.Job) { | |||
56 | 56 | ||
57 | await retryTransactionWrapper(onVideoFileTranscoderOrImportSuccess, video) | 57 | await retryTransactionWrapper(onVideoFileTranscoderOrImportSuccess, video) |
58 | } else { | 58 | } else { |
59 | await optimizeOriginalVideofile(video) | 59 | await optimizeVideofile(video) |
60 | 60 | ||
61 | await retryTransactionWrapper(onVideoFileOptimizerSuccess, video, payload.isNewVideo) | 61 | await retryTransactionWrapper(onVideoFileOptimizerSuccess, video, payload.isNewVideo) |
62 | } | 62 | } |
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index bf3ff78c2..04cadf74b 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { CONFIG } from '../initializers' | 1 | import { CONFIG } from '../initializers' |
2 | import { join, extname } from 'path' | 2 | import { join, extname, basename } from 'path' |
3 | import { getVideoFileFPS, getVideoFileResolution, transcode } from '../helpers/ffmpeg-utils' | 3 | import { getVideoFileFPS, getVideoFileResolution, transcode } from '../helpers/ffmpeg-utils' |
4 | import { copy, remove, rename, stat } from 'fs-extra' | 4 | import { copy, remove, rename, stat } from 'fs-extra' |
5 | import { logger } from '../helpers/logger' | 5 | import { logger } from '../helpers/logger' |
@@ -7,11 +7,16 @@ import { VideoResolution } from '../../shared/models/videos' | |||
7 | import { VideoFileModel } from '../models/video/video-file' | 7 | import { VideoFileModel } from '../models/video/video-file' |
8 | import { VideoModel } from '../models/video/video' | 8 | import { VideoModel } from '../models/video/video' |
9 | 9 | ||
10 | async function optimizeOriginalVideofile (video: VideoModel) { | 10 | async function optimizeVideofile (video: VideoModel, videoInputPath?: string) { |
11 | const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR | 11 | const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR |
12 | const newExtname = '.mp4' | 12 | const newExtname = '.mp4' |
13 | const inputVideoFile = video.getOriginalFile() | 13 | let inputVideoFile = null |
14 | const videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile)) | 14 | if (videoInputPath == null) { |
15 | inputVideoFile = video.getOriginalFile() | ||
16 | videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile)) | ||
17 | } else { | ||
18 | inputVideoFile = basename(videoInputPath) | ||
19 | } | ||
15 | const videoTranscodedPath = join(videosDirectory, video.id + '-transcoded' + newExtname) | 20 | const videoTranscodedPath = join(videosDirectory, video.id + '-transcoded' + newExtname) |
16 | 21 | ||
17 | const transcodeOptions = { | 22 | const transcodeOptions = { |
@@ -124,7 +129,7 @@ async function importVideoFile (video: VideoModel, inputFilePath: string) { | |||
124 | } | 129 | } |
125 | 130 | ||
126 | export { | 131 | export { |
127 | optimizeOriginalVideofile, | 132 | optimizeVideofile, |
128 | transcodeOriginalVideofile, | 133 | transcodeOriginalVideofile, |
129 | importVideoFile | 134 | importVideoFile |
130 | } | 135 | } |