mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Add video aspect ratio in server
This commit is contained in:
parent
c75381208f
commit
b6b1aaa56f
52 changed files with 345 additions and 237 deletions
|
@ -103,9 +103,14 @@ function calculateBitrate (options: {
|
|||
VideoResolution.H_NOVIDEO
|
||||
]
|
||||
|
||||
const size1 = resolution
|
||||
const size2 = ratio < 1 && ratio > 0
|
||||
? resolution / ratio // Portrait mode
|
||||
: resolution * ratio
|
||||
|
||||
for (const toTestResolution of resolutionsOrder) {
|
||||
if (toTestResolution <= resolution) {
|
||||
return Math.floor(resolution * resolution * ratio * fps * bitPerPixel[toTestResolution])
|
||||
return Math.floor(size1 * size2 * fps * bitPerPixel[toTestResolution])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { VideoDetails, VideoPrivacy, VideoStreamingPlaylistType } from '@peertube/peertube-models'
|
||||
|
||||
function getAllPrivacies () {
|
||||
export function getAllPrivacies () {
|
||||
return [ VideoPrivacy.PUBLIC, VideoPrivacy.INTERNAL, VideoPrivacy.PRIVATE, VideoPrivacy.UNLISTED, VideoPrivacy.PASSWORD_PROTECTED ]
|
||||
}
|
||||
|
||||
function getAllFiles (video: Partial<Pick<VideoDetails, 'files' | 'streamingPlaylists'>>) {
|
||||
export function getAllFiles (video: Partial<Pick<VideoDetails, 'files' | 'streamingPlaylists'>>) {
|
||||
const files = video.files
|
||||
|
||||
const hls = getHLS(video)
|
||||
|
@ -13,12 +13,13 @@ function getAllFiles (video: Partial<Pick<VideoDetails, 'files' | 'streamingPlay
|
|||
return files
|
||||
}
|
||||
|
||||
function getHLS (video: Partial<Pick<VideoDetails, 'streamingPlaylists'>>) {
|
||||
export function getHLS (video: Partial<Pick<VideoDetails, 'streamingPlaylists'>>) {
|
||||
return video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
|
||||
}
|
||||
|
||||
export {
|
||||
getAllPrivacies,
|
||||
getAllFiles,
|
||||
getHLS
|
||||
export function buildAspectRatio (options: { width: number, height: number }) {
|
||||
const { width, height } = options
|
||||
if (!width || !height) return null
|
||||
|
||||
return Math.round((width / height) * 10000) / 10000 // 4 decimals precision
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue