Fix resolution for portrait videos

This commit is contained in:
Chocobozzz 2018-02-27 15:57:28 +01:00
parent 6fdc553adb
commit 056aa7f2b4
No known key found for this signature in database
GPG key ID: 583A612D890159BE
5 changed files with 27 additions and 19 deletions

View file

@ -6,9 +6,13 @@ import { unlinkPromise } from './core-utils'
import { processImage } from './image-utils'
import { logger } from './logger'
async function getVideoFileHeight (path: string) {
async function getVideoFileResolution (path: string) {
const videoStream = await getVideoFileStream(path)
return videoStream.height
return {
videoFileResolution: Math.min(videoStream.height, videoStream.width),
isPortraitMode: videoStream.height > videoStream.width
}
}
async function getVideoFileFPS (path: string) {
@ -74,6 +78,7 @@ type TranscodeOptions = {
inputPath: string
outputPath: string
resolution?: VideoResolution
isPortraitMode?: boolean
}
function transcode (options: TranscodeOptions) {
@ -90,7 +95,8 @@ function transcode (options: TranscodeOptions) {
if (fps > MAX_VIDEO_TRANSCODING_FPS) command = command.withFPS(MAX_VIDEO_TRANSCODING_FPS)
if (options.resolution !== undefined) {
const size = `?x${options.resolution}` // '?x720' for example
// '?x720' or '720x?' for example
const size = options.isPortraitMode === true ? `${options.resolution}x?` : `?x${options.resolution}`
command = command.size(size)
}
@ -103,7 +109,7 @@ function transcode (options: TranscodeOptions) {
// ---------------------------------------------------------------------------
export {
getVideoFileHeight,
getVideoFileResolution,
getDurationFromVideoFile,
generateImageFromVideoFile,
transcode,