diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-file.ts | 15 | ||||
-rw-r--r-- | server/models/video/video.ts | 26 |
2 files changed, 32 insertions, 9 deletions
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 @@ | |||
1 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { isVideoFileInfoHashValid, isVideoFileResolutionValid, isVideoFileSizeValid } from '../../helpers/custom-validators/videos' | 3 | import { |
4 | isVideoFileInfoHashValid, | ||
5 | isVideoFileResolutionValid, | ||
6 | isVideoFileSizeValid, | ||
7 | isVideoFPSResolutionValid | ||
8 | } from '../../helpers/custom-validators/videos' | ||
4 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 9 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
5 | import { throwIfNotValid } from '../utils' | 10 | import { throwIfNotValid } from '../utils' |
6 | import { VideoModel } from './video' | 11 | import { VideoModel } from './video' |
@@ -42,6 +47,12 @@ export class VideoFileModel extends Model<VideoFileModel> { | |||
42 | @Column | 47 | @Column |
43 | infoHash: string | 48 | infoHash: string |
44 | 49 | ||
50 | @AllowNull(true) | ||
51 | @Default(null) | ||
52 | @Is('VideoFileFPS', value => throwIfNotValid(value, isVideoFPSResolutionValid, 'fps')) | ||
53 | @Column | ||
54 | fps: number | ||
55 | |||
45 | @ForeignKey(() => VideoModel) | 56 | @ForeignKey(() => VideoModel) |
46 | @Column | 57 | @Column |
47 | videoId: number | 58 | 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 { | |||
52 | isVideoStateValid, | 52 | isVideoStateValid, |
53 | isVideoSupportValid | 53 | isVideoSupportValid |
54 | } from '../../helpers/custom-validators/videos' | 54 | } from '../../helpers/custom-validators/videos' |
55 | import { generateImageFromVideoFile, getVideoFileResolution, transcode } from '../../helpers/ffmpeg-utils' | 55 | import { generateImageFromVideoFile, getVideoFileFPS, getVideoFileResolution, transcode } from '../../helpers/ffmpeg-utils' |
56 | import { logger } from '../../helpers/logger' | 56 | import { logger } from '../../helpers/logger' |
57 | import { getServerActor } from '../../helpers/utils' | 57 | import { getServerActor } from '../../helpers/utils' |
58 | import { | 58 | import { |
@@ -1168,6 +1168,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1168 | }, | 1168 | }, |
1169 | magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs), | 1169 | magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs), |
1170 | size: videoFile.size, | 1170 | size: videoFile.size, |
1171 | fps: videoFile.fps, | ||
1171 | torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp), | 1172 | torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp), |
1172 | torrentDownloadUrl: this.getTorrentDownloadUrl(videoFile, baseUrlHttp), | 1173 | torrentDownloadUrl: this.getTorrentDownloadUrl(videoFile, baseUrlHttp), |
1173 | fileUrl: this.getVideoFileUrl(videoFile, baseUrlHttp), | 1174 | fileUrl: this.getVideoFileUrl(videoFile, baseUrlHttp), |
@@ -1303,11 +1304,11 @@ export class VideoModel extends Model<VideoModel> { | |||
1303 | const newExtname = '.mp4' | 1304 | const newExtname = '.mp4' |
1304 | const inputVideoFile = this.getOriginalFile() | 1305 | const inputVideoFile = this.getOriginalFile() |
1305 | const videoInputPath = join(videosDirectory, this.getVideoFilename(inputVideoFile)) | 1306 | const videoInputPath = join(videosDirectory, this.getVideoFilename(inputVideoFile)) |
1306 | const videoOutputPath = join(videosDirectory, this.id + '-transcoded' + newExtname) | 1307 | const videoTranscodedPath = join(videosDirectory, this.id + '-transcoded' + newExtname) |
1307 | 1308 | ||
1308 | const transcodeOptions = { | 1309 | const transcodeOptions = { |
1309 | inputPath: videoInputPath, | 1310 | inputPath: videoInputPath, |
1310 | outputPath: videoOutputPath | 1311 | outputPath: videoTranscodedPath |
1311 | } | 1312 | } |
1312 | 1313 | ||
1313 | // Could be very long! | 1314 | // Could be very long! |
@@ -1319,10 +1320,13 @@ export class VideoModel extends Model<VideoModel> { | |||
1319 | // Important to do this before getVideoFilename() to take in account the new file extension | 1320 | // Important to do this before getVideoFilename() to take in account the new file extension |
1320 | inputVideoFile.set('extname', newExtname) | 1321 | inputVideoFile.set('extname', newExtname) |
1321 | 1322 | ||
1322 | await renamePromise(videoOutputPath, this.getVideoFilePath(inputVideoFile)) | 1323 | const videoOutputPath = this.getVideoFilePath(inputVideoFile) |
1323 | const stats = await statPromise(this.getVideoFilePath(inputVideoFile)) | 1324 | await renamePromise(videoTranscodedPath, videoOutputPath) |
1325 | const stats = await statPromise(videoOutputPath) | ||
1326 | const fps = await getVideoFileFPS(videoOutputPath) | ||
1324 | 1327 | ||
1325 | inputVideoFile.set('size', stats.size) | 1328 | inputVideoFile.set('size', stats.size) |
1329 | inputVideoFile.set('fps', fps) | ||
1326 | 1330 | ||
1327 | await this.createTorrentAndSetInfoHash(inputVideoFile) | 1331 | await this.createTorrentAndSetInfoHash(inputVideoFile) |
1328 | await inputVideoFile.save() | 1332 | await inputVideoFile.save() |
@@ -1360,8 +1364,10 @@ export class VideoModel extends Model<VideoModel> { | |||
1360 | await transcode(transcodeOptions) | 1364 | await transcode(transcodeOptions) |
1361 | 1365 | ||
1362 | const stats = await statPromise(videoOutputPath) | 1366 | const stats = await statPromise(videoOutputPath) |
1367 | const fps = await getVideoFileFPS(videoOutputPath) | ||
1363 | 1368 | ||
1364 | newVideoFile.set('size', stats.size) | 1369 | newVideoFile.set('size', stats.size) |
1370 | newVideoFile.set('fps', fps) | ||
1365 | 1371 | ||
1366 | await this.createTorrentAndSetInfoHash(newVideoFile) | 1372 | await this.createTorrentAndSetInfoHash(newVideoFile) |
1367 | 1373 | ||
@@ -1371,10 +1377,15 @@ export class VideoModel extends Model<VideoModel> { | |||
1371 | } | 1377 | } |
1372 | 1378 | ||
1373 | async importVideoFile (inputFilePath: string) { | 1379 | async importVideoFile (inputFilePath: string) { |
1380 | const { videoFileResolution } = await getVideoFileResolution(inputFilePath) | ||
1381 | const { size } = await statPromise(inputFilePath) | ||
1382 | const fps = await getVideoFileFPS(inputFilePath) | ||
1383 | |||
1374 | let updatedVideoFile = new VideoFileModel({ | 1384 | let updatedVideoFile = new VideoFileModel({ |
1375 | resolution: (await getVideoFileResolution(inputFilePath)).videoFileResolution, | 1385 | resolution: videoFileResolution, |
1376 | extname: extname(inputFilePath), | 1386 | extname: extname(inputFilePath), |
1377 | size: (await statPromise(inputFilePath)).size, | 1387 | size, |
1388 | fps, | ||
1378 | videoId: this.id | 1389 | videoId: this.id |
1379 | }) | 1390 | }) |
1380 | 1391 | ||
@@ -1390,6 +1401,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1390 | // Update the database | 1401 | // Update the database |
1391 | currentVideoFile.set('extname', updatedVideoFile.extname) | 1402 | currentVideoFile.set('extname', updatedVideoFile.extname) |
1392 | currentVideoFile.set('size', updatedVideoFile.size) | 1403 | currentVideoFile.set('size', updatedVideoFile.size) |
1404 | currentVideoFile.set('fps', updatedVideoFile.fps) | ||
1393 | 1405 | ||
1394 | updatedVideoFile = currentVideoFile | 1406 | updatedVideoFile = currentVideoFile |
1395 | } | 1407 | } |