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