diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-27 11:29:24 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-27 11:29:24 +0100 |
commit | 266707202c2ffcb8a1b7649ec29106dd444f4a77 (patch) | |
tree | f2d83c39d90ad80fb13fa04931a055beed63ca8c | |
parent | ea99d15fe87d03568f4b5077e1ce37c742c9fa33 (diff) | |
download | PeerTube-266707202c2ffcb8a1b7649ec29106dd444f4a77.tar.gz PeerTube-266707202c2ffcb8a1b7649ec29106dd444f4a77.tar.zst PeerTube-266707202c2ffcb8a1b7649ec29106dd444f4a77.zip |
Keep ratio for thumbnails
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 18 | ||||
-rw-r--r-- | server/models/video/video.ts | 8 |
2 files changed, 13 insertions, 13 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index ad6f2f867..57911bc73 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -1,6 +1,8 @@ | |||
1 | import * as ffmpeg from 'fluent-ffmpeg' | 1 | import * as ffmpeg from 'fluent-ffmpeg' |
2 | import { VideoResolution } from '../../shared/models/videos' | 2 | import { VideoResolution } from '../../shared/models/videos' |
3 | import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers' | 3 | import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers' |
4 | import { processImage } from './image-utils' | ||
5 | import { join } from 'path' | ||
4 | 6 | ||
5 | async function getVideoFileHeight (path: string) { | 7 | async function getVideoFileHeight (path: string) { |
6 | const videoStream = await getVideoFileStream(path) | 8 | const videoStream = await getVideoFileStream(path) |
@@ -34,23 +36,25 @@ function getDurationFromVideoFile (path: string) { | |||
34 | }) | 36 | }) |
35 | } | 37 | } |
36 | 38 | ||
37 | function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: string) { | 39 | async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) { |
40 | const pendingImageName = 'pending-' + imageName | ||
41 | |||
38 | const options = { | 42 | const options = { |
39 | filename: imageName, | 43 | filename: pendingImageName, |
40 | count: 1, | 44 | count: 1, |
41 | folder | 45 | folder |
42 | } | 46 | } |
43 | 47 | ||
44 | if (size !== undefined) { | 48 | await new Promise<string>((res, rej) => { |
45 | options['size'] = size | ||
46 | } | ||
47 | |||
48 | return new Promise<string>((res, rej) => { | ||
49 | ffmpeg(fromPath) | 49 | ffmpeg(fromPath) |
50 | .on('error', rej) | 50 | .on('error', rej) |
51 | .on('end', () => res(imageName)) | 51 | .on('end', () => res(imageName)) |
52 | .thumbnail(options) | 52 | .thumbnail(options) |
53 | }) | 53 | }) |
54 | |||
55 | const pendingImagePath = join(folder, pendingImageName) | ||
56 | const destination = join(folder, imageName) | ||
57 | await processImage({ path: pendingImagePath }, destination, size) | ||
54 | } | 58 | } |
55 | 59 | ||
56 | type TranscodeOptions = { | 60 | type TranscodeOptions = { |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 839b81a8b..4e065e377 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -793,24 +793,20 @@ export class VideoModel extends Model<VideoModel> { | |||
793 | } | 793 | } |
794 | 794 | ||
795 | createPreview (videoFile: VideoFileModel) { | 795 | createPreview (videoFile: VideoFileModel) { |
796 | const imageSize = PREVIEWS_SIZE.width + 'x' + PREVIEWS_SIZE.height | ||
797 | |||
798 | return generateImageFromVideoFile( | 796 | return generateImageFromVideoFile( |
799 | this.getVideoFilePath(videoFile), | 797 | this.getVideoFilePath(videoFile), |
800 | CONFIG.STORAGE.PREVIEWS_DIR, | 798 | CONFIG.STORAGE.PREVIEWS_DIR, |
801 | this.getPreviewName(), | 799 | this.getPreviewName(), |
802 | imageSize | 800 | PREVIEWS_SIZE |
803 | ) | 801 | ) |
804 | } | 802 | } |
805 | 803 | ||
806 | createThumbnail (videoFile: VideoFileModel) { | 804 | createThumbnail (videoFile: VideoFileModel) { |
807 | const imageSize = THUMBNAILS_SIZE.width + 'x' + THUMBNAILS_SIZE.height | ||
808 | |||
809 | return generateImageFromVideoFile( | 805 | return generateImageFromVideoFile( |
810 | this.getVideoFilePath(videoFile), | 806 | this.getVideoFilePath(videoFile), |
811 | CONFIG.STORAGE.THUMBNAILS_DIR, | 807 | CONFIG.STORAGE.THUMBNAILS_DIR, |
812 | this.getThumbnailName(), | 808 | this.getThumbnailName(), |
813 | imageSize | 809 | THUMBNAILS_SIZE |
814 | ) | 810 | ) |
815 | } | 811 | } |
816 | 812 | ||