利用js文件获取视频文件详细信息 如帧速率、总比特率等 您所在的位置:网站首页 js上传视频数据 利用js文件获取视频文件详细信息 如帧速率、总比特率等

利用js文件获取视频文件详细信息 如帧速率、总比特率等

2024-06-18 00:50| 来源: 网络整理| 查看: 265

问题描述:上传的视频文件有些在苹果手机上无法播放,需要要获取详细信息以判断是受哪些关键属性影响的。然而普通的方法没法获取全部的详细信息。 解决方法:引入mediainfo.js,这个js插件可以获取到全部的详细信息。其官方demo演示地址:https://mediainfo.js.org/ GitHub地址:https://github.com/buzz/mediainfo.js 官方例子:

const fileinput = document.getElementById('fileinput') const output = document.getElementById('output') const onChangeFile = (mediainfo) => { const file = fileinput.files[0] if (file) { output.value = 'Working…' const getSize = () => file.size const readChunk = (chunkSize, offset) => new Promise((resolve, reject) => { const reader = new FileReader() reader.onload = (event) => { if (event.target.error) { reject(event.target.error) } resolve(new Uint8Array(event.target.result)) } reader.readAsArrayBuffer(file.slice(offset, offset + chunkSize)) }) mediainfo .analyzeData(getSize, readChunk) .then((result) => { output.value = result }) .catch((error) => { output.value = `An error occured:\n${error.stack}` }) } } MediaInfo({ format: 'text' }, (mediainfo) => { fileinput.addEventListener('change', () => onChangeFile(mediainfo)) })

浏览器引入方式:

或者把mediainfo.min.js下载之后上传到自己服务器的地址。

经测试这个插件还是非常好用的。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有