JavaScript - 读取视频文件的元数据

JavaScript - Read metadata of video file(JavaScript - 读取视频文件的元数据)
本文介绍了JavaScript - 读取视频文件的元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经在这工作了好几个小时了,是时候寻求一点帮助了.

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.

浏览器读取视频元数据以检查预期的帧速率,那么我该怎么做呢?我在网上看了很多东西,没有发现任何有用的东西,但我不敢相信这是不可行的.

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.

我正在寻找 这个 但对于视频.应该很简单吧?

I'm looking for this but for videos. Should be simple, right?

注意:我正在使用 Electron 构建桌面应用程序,因此文件访问不是问题.

Note: I'm building a desktop app with Electron so file access isn't a problem.

推荐答案

您可以创建一个视频元素,其 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 事件监听器,在回调中您将可以访问视频元数据.

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)
})

这篇关于JavaScript - 读取视频文件的元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

opening html from google drive(从谷歌驱动器打开 html)
Google apps script get range of bytes from binary file(谷歌应用程序脚本从二进制文件中获取字节范围)
Sending Multiple attachments with Google Script from Google Drive(使用 Google 脚本从 Google Drive 发送多个附件)
Distributing Google Apps Scripts for Sheets in your company network(在您的公司网络中分发适用于表格的 Google Apps 脚本)
Upload file to my google drive from anyone using javascript(使用 javascript 将文件从任何人上传到我的谷歌驱动器)
quot;Shared Drivequot; support in Google Apps Script(“共享驱动器Google Apps 脚本中的支持)