From edb4ffc7e0b13659d7c73b120f2c87b27e4c26a1 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 8 Oct 2018 09:26:04 -0500 Subject: 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 --- server/lib/video-transcoding.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'server/lib/video-transcoding.ts') 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 @@ import { CONFIG } from '../initializers' -import { join, extname } from 'path' +import { join, extname, basename } from 'path' import { getVideoFileFPS, getVideoFileResolution, transcode } from '../helpers/ffmpeg-utils' import { copy, remove, rename, stat } from 'fs-extra' import { logger } from '../helpers/logger' @@ -7,11 +7,16 @@ import { VideoResolution } from '../../shared/models/videos' import { VideoFileModel } from '../models/video/video-file' import { VideoModel } from '../models/video/video' -async function optimizeOriginalVideofile (video: VideoModel) { +async function optimizeVideofile (video: VideoModel, videoInputPath?: string) { const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR const newExtname = '.mp4' - const inputVideoFile = video.getOriginalFile() - const videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile)) + let inputVideoFile = null + if (videoInputPath == null) { + inputVideoFile = video.getOriginalFile() + videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile)) + } else { + inputVideoFile = basename(videoInputPath) + } const videoTranscodedPath = join(videosDirectory, video.id + '-transcoded' + newExtname) const transcodeOptions = { @@ -124,7 +129,7 @@ async function importVideoFile (video: VideoModel, inputFilePath: string) { } export { - optimizeOriginalVideofile, + optimizeVideofile, transcodeOriginalVideofile, importVideoFile } -- cgit v1.2.3