問(wèn)題描述
我已經(jīng)在這工作了好幾個(gè)小時(shí)了,是時(shí)候?qū)で笠稽c(diǎn)幫助了.
I've been at this for hours, it's time to ask for a little help.
我需要知道在 JavaScript/HTML 中加載視頻的幀速率,并且我試圖避免使用 VLC 插件或 ffmpeg.
I need to know the frame rate of a video on load in JavaScript/HTML and I'm trying to avoid VLC plug-in or ffmpeg.
瀏覽器讀取視頻元數(shù)據(jù)以檢查預(yù)期的幀速率,那么我該怎么做呢?我在網(wǎng)上看了很多東西,沒(méi)有發(fā)現(xiàn)任何有用的東西,但我不敢相信這是不可行的.
The browser reads the video metadata to check the intended frame rate, so how can I do this as well? I read a lot of online things and didn't find anything useful but I can't believe that this is unfeasible.
我正在尋找 這個(gè) 但對(duì)于視頻.應(yīng)該很簡(jiǎn)單吧?
I'm looking for this but for videos. Should be simple, right?
注意:我正在使用 Electron 構(gòu)建桌面應(yīng)用程序,因此文件訪問(wèn)不是問(wèn)題.
Note: I'm building a desktop app with Electron so file access isn't a problem.
推薦答案
您可以創(chuàng)建一個(gè)視頻元素,其 src 屬性指向鏈接或本地文件/blob
You can create a video element with src attribute pointing to a link or local file/blob
let video = document.createElement('video')
video.setAttribute('src', window.URL.createObjectURL(file))
為元素添加 onloadeddata 事件監(jiān)聽器,在回調(diào)中您將可以訪問(wèn)視頻元數(shù)據(jù).
Add onloadeddata event listener to the element and in the callback you'll have access to the video metadata.
video.onloadeddata = function(event) {
const {
videoHeight,
videoWidth,
duration
} = event.srcElement
console.log(videoHeight)
})
這篇關(guān)于JavaScript - 讀取視頻文件的元數(shù)據(jù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!