mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-12-02 05:19:17 -06:00
Fix resolution for portrait videos
This commit is contained in:
parent
6fdc553adb
commit
056aa7f2b4
@ -3,7 +3,7 @@ import { extname, join } from 'path'
|
||||
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'
|
||||
@ -187,11 +187,11 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
|
||||
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)
|
||||
|
@ -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,
|
||||
|
@ -3,7 +3,7 @@ import { join } from 'path'
|
||||
|
||||
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,
|
||||
@ -27,7 +27,7 @@ function up (utils: {
|
||||
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'
|
||||
|
@ -11,7 +11,8 @@ import { JobQueue } from '../job-queue'
|
||||
|
||||
export type VideoFilePayload = {
|
||||
videoUUID: string
|
||||
resolution?: VideoResolution
|
||||
resolution?: VideoResolution,
|
||||
isPortraitMode?: boolean
|
||||
}
|
||||
|
||||
async function processVideoFile (job: kue.Job) {
|
||||
@ -27,7 +28,7 @@ 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()
|
||||
@ -66,12 +67,12 @@ async function onVideoFileOptimizerSuccess (video: VideoModel) {
|
||||
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 }
|
||||
)
|
||||
|
||||
|
@ -42,7 +42,7 @@ import {
|
||||
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 {
|
||||
@ -1140,7 +1140,7 @@ export class VideoModel extends Model<VideoModel> {
|
||||
}
|
||||
}
|
||||
|
||||
transcodeOriginalVideofile = async function (resolution: VideoResolution) {
|
||||
transcodeOriginalVideofile = async function (resolution: VideoResolution, isPortraitMode: boolean) {
|
||||
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
|
||||
const extname = '.mp4'
|
||||
|
||||
@ -1158,7 +1158,8 @@ export class VideoModel extends Model<VideoModel> {
|
||||
const transcodeOptions = {
|
||||
inputPath: videoInputPath,
|
||||
outputPath: videoOutputPath,
|
||||
resolution
|
||||
resolution,
|
||||
isPortraitMode
|
||||
}
|
||||
|
||||
await transcode(transcodeOptions)
|
||||
@ -1174,10 +1175,10 @@ export class VideoModel extends Model<VideoModel> {
|
||||
this.VideoFiles.push(newVideoFile)
|
||||
}
|
||||
|
||||
getOriginalFileHeight () {
|
||||
getOriginalFileResolution () {
|
||||
const originalFilePath = this.getVideoFilePath(this.getOriginalFile())
|
||||
|
||||
return getVideoFileHeight(originalFilePath)
|
||||
return getVideoFileResolution(originalFilePath)
|
||||
}
|
||||
|
||||
getDescriptionPath () {
|
||||
|
Loading…
Reference in New Issue
Block a user