import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared'
import { renamePromise } from '../../../helpers/core-utils'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
-import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils'
+import { getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
import { processImage } from '../../../helpers/image-utils'
import { logger } from '../../../helpers/logger'
import { createReqFiles, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils'
const video = new VideoModel(videoData)
video.url = getVideoActivityPubUrl(video)
- const videoFileHeight = await getVideoFileHeight(videoPhysicalFile.path)
+ const { videoFileResolution } = await getVideoFileResolution(videoPhysicalFile.path)
const videoFileData = {
extname: extname(videoPhysicalFile.filename),
- resolution: videoFileHeight,
+ resolution: videoFileResolution,
size: videoPhysicalFile.size
}
const videoFile = new VideoFileModel(videoFileData)
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) {
inputPath: string
outputPath: string
resolution?: VideoResolution
+ isPortraitMode?: boolean
}
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)
}
// ---------------------------------------------------------------------------
export {
- getVideoFileHeight,
+ getVideoFileResolution,
getDurationFromVideoFile,
generateImageFromVideoFile,
transcode,
import { readdirPromise, renamePromise } from '../../helpers/core-utils'
import { CONFIG } from '../../initializers/constants'
-import { getVideoFileHeight } from '../../helpers/ffmpeg-utils'
+import { getVideoFileResolution } from '../../helpers/ffmpeg-utils'
function up (utils: {
transaction: Sequelize.Transaction,
const uuid = matches[1]
const ext = matches[2]
- const p = getVideoFileHeight(join(videoFileDir, videoFile))
+ const p = getVideoFileResolution(join(videoFileDir, videoFile))
.then(height => {
const oldTorrentName = uuid + '.torrent'
const newTorrentName = uuid + '-' + height + '.torrent'
export type VideoFilePayload = {
videoUUID: string
- resolution?: VideoResolution
+ resolution?: VideoResolution,
+ isPortraitMode?: boolean
}
async function processVideoFile (job: kue.Job) {
// Transcoding in other resolution
if (payload.resolution) {
- await video.transcodeOriginalVideofile(payload.resolution)
+ await video.transcodeOriginalVideofile(payload.resolution, payload.isPortraitMode)
await onVideoFileTranscoderSuccess(video)
} else {
await video.optimizeOriginalVideofile()
await shareVideoByServerAndChannel(video, undefined)
}
- const originalFileHeight = await videoDatabase.getOriginalFileHeight()
+ const { videoFileResolution } = await videoDatabase.getOriginalFileResolution()
// Create transcoding jobs if there are enabled resolutions
- const resolutionsEnabled = computeResolutionsToTranscode(originalFileHeight)
+ const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution)
logger.info(
- 'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, originalFileHeight,
+ 'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, videoFileResolution,
{ resolutions: resolutionsEnabled }
)
isVideoNameValid,
isVideoPrivacyValid, isVideoSupportValid
} from '../../helpers/custom-validators/videos'
-import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils'
+import { generateImageFromVideoFile, getVideoFileResolution, transcode } from '../../helpers/ffmpeg-utils'
import { logger } from '../../helpers/logger'
import { getServerActor } from '../../helpers/utils'
import {
}
}
- transcodeOriginalVideofile = async function (resolution: VideoResolution) {
+ transcodeOriginalVideofile = async function (resolution: VideoResolution, isPortraitMode: boolean) {
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
const extname = '.mp4'
const transcodeOptions = {
inputPath: videoInputPath,
outputPath: videoOutputPath,
- resolution
+ resolution,
+ isPortraitMode
}
await transcode(transcodeOptions)
this.VideoFiles.push(newVideoFile)
}
- getOriginalFileHeight () {
+ getOriginalFileResolution () {
const originalFilePath = this.getVideoFilePath(this.getOriginalFile())
- return getVideoFileHeight(originalFilePath)
+ return getVideoFileResolution(originalFilePath)
}
getDescriptionPath () {