ai-stories-factory / src /lib /utils /getVideoOrientation.ts
jbilcke-hf's picture
jbilcke-hf HF staff
upgrade libs
7fd8bde
raw
history blame
675 Bytes
import { ClapMediaOrientation } from "@aitube/clap"
/**
* Determine the video orientation from a video URL (data-uri or hosted)
*
* @param url
* @returns
*/
export async function getVideoOrientation(url: string): Promise<ClapMediaOrientation> {
return new Promise<ClapMediaOrientation>(resolve => {
const video = document.createElement('video')
video.addEventListener( "loadedmetadata", function () {
resolve(
this.videoHeight < this.videoWidth ? ClapMediaOrientation.LANDSCAPE :
this.videoHeight > this.videoWidth ? ClapMediaOrientation.PORTRAIT :
ClapMediaOrientation.SQUARE
)
}, false)
video.src = url
})
}