From 3a6f351b255d21ec42578632600ba699885f350e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Jun 2018 16:41:29 +0200 Subject: Handle higher FPS for high resolution (test) --- server/models/video/video-file.ts | 15 +++++++++++++-- server/models/video/video.ts | 26 +++++++++++++++++++------- 2 files changed, 32 insertions(+), 9 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index df4067a4e..372d18d69 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -1,6 +1,11 @@ import { values } from 'lodash' -import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' -import { isVideoFileInfoHashValid, isVideoFileResolutionValid, isVideoFileSizeValid } from '../../helpers/custom-validators/videos' +import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { + isVideoFileInfoHashValid, + isVideoFileResolutionValid, + isVideoFileSizeValid, + isVideoFPSResolutionValid +} from '../../helpers/custom-validators/videos' import { CONSTRAINTS_FIELDS } from '../../initializers' import { throwIfNotValid } from '../utils' import { VideoModel } from './video' @@ -42,6 +47,12 @@ export class VideoFileModel extends Model { @Column infoHash: string + @AllowNull(true) + @Default(null) + @Is('VideoFileFPS', value => throwIfNotValid(value, isVideoFPSResolutionValid, 'fps')) + @Column + fps: number + @ForeignKey(() => VideoModel) @Column videoId: number diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 5d8089328..ab33b7c99 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -52,7 +52,7 @@ import { isVideoStateValid, isVideoSupportValid } from '../../helpers/custom-validators/videos' -import { generateImageFromVideoFile, getVideoFileResolution, transcode } from '../../helpers/ffmpeg-utils' +import { generateImageFromVideoFile, getVideoFileFPS, getVideoFileResolution, transcode } from '../../helpers/ffmpeg-utils' import { logger } from '../../helpers/logger' import { getServerActor } from '../../helpers/utils' import { @@ -1168,6 +1168,7 @@ export class VideoModel extends Model { }, magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs), size: videoFile.size, + fps: videoFile.fps, torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp), torrentDownloadUrl: this.getTorrentDownloadUrl(videoFile, baseUrlHttp), fileUrl: this.getVideoFileUrl(videoFile, baseUrlHttp), @@ -1303,11 +1304,11 @@ export class VideoModel extends Model { const newExtname = '.mp4' const inputVideoFile = this.getOriginalFile() const videoInputPath = join(videosDirectory, this.getVideoFilename(inputVideoFile)) - const videoOutputPath = join(videosDirectory, this.id + '-transcoded' + newExtname) + const videoTranscodedPath = join(videosDirectory, this.id + '-transcoded' + newExtname) const transcodeOptions = { inputPath: videoInputPath, - outputPath: videoOutputPath + outputPath: videoTranscodedPath } // Could be very long! @@ -1319,10 +1320,13 @@ export class VideoModel extends Model { // Important to do this before getVideoFilename() to take in account the new file extension inputVideoFile.set('extname', newExtname) - await renamePromise(videoOutputPath, this.getVideoFilePath(inputVideoFile)) - const stats = await statPromise(this.getVideoFilePath(inputVideoFile)) + const videoOutputPath = this.getVideoFilePath(inputVideoFile) + await renamePromise(videoTranscodedPath, videoOutputPath) + const stats = await statPromise(videoOutputPath) + const fps = await getVideoFileFPS(videoOutputPath) inputVideoFile.set('size', stats.size) + inputVideoFile.set('fps', fps) await this.createTorrentAndSetInfoHash(inputVideoFile) await inputVideoFile.save() @@ -1360,8 +1364,10 @@ export class VideoModel extends Model { await transcode(transcodeOptions) const stats = await statPromise(videoOutputPath) + const fps = await getVideoFileFPS(videoOutputPath) newVideoFile.set('size', stats.size) + newVideoFile.set('fps', fps) await this.createTorrentAndSetInfoHash(newVideoFile) @@ -1371,10 +1377,15 @@ export class VideoModel extends Model { } async importVideoFile (inputFilePath: string) { + const { videoFileResolution } = await getVideoFileResolution(inputFilePath) + const { size } = await statPromise(inputFilePath) + const fps = await getVideoFileFPS(inputFilePath) + let updatedVideoFile = new VideoFileModel({ - resolution: (await getVideoFileResolution(inputFilePath)).videoFileResolution, + resolution: videoFileResolution, extname: extname(inputFilePath), - size: (await statPromise(inputFilePath)).size, + size, + fps, videoId: this.id }) @@ -1390,6 +1401,7 @@ export class VideoModel extends Model { // Update the database currentVideoFile.set('extname', updatedVideoFile.extname) currentVideoFile.set('size', updatedVideoFile.size) + currentVideoFile.set('fps', updatedVideoFile.fps) updatedVideoFile = currentVideoFile } -- cgit v1.2.3