美文网首页
使用mp4box校验文件视频文件解码类型

使用mp4box校验文件视频文件解码类型

作者: 羊驼626 | 来源:发表于2022-03-08 16:48 被阅读0次

场景:由于浏览器标签video不支持播放hevc编码格式的MP4文件,故在上传文件时,通过校验视频文件类型,过滤hevc编码格式的视频文件

1.使用mp4box

https://github.com/gpac/gpac/wiki/MP4Box

2.应用

<input type="file" @change="fileChange">
import MP4Box from 'mp4box'

async fileChange(e) {
  console.log(e);
  let result;
  await this.checkVideoCode(e.target.files[0]).then((res) => {
    result = res;
    console.log(result); // 其他格式需要实际实验判断
  });
  if (result.mime.indexOf("hvc") !== -1) {
    console.log("格式不支持");
  }
},
checkVideoCode(file) {
  return new Promise((resolve, reject) => {
    const mp4boxFile = MP4Box.createFile();
    const reader = new FileReader();
    reader.readAsArrayBuffer(file);
    reader.onload = function (e) {
      const arrayBuffer = e.target.result;
      arrayBuffer.fileStart = 0;
      mp4boxFile.appendBuffer(arrayBuffer);
    };
    mp4boxFile.onReady = function (info) {
      resolve(info);
    };
    mp4boxFile.onError = function (info) {
      reject(info);
    };
  });
},

相关文章

网友评论

      本文标题:使用mp4box校验文件视频文件解码类型

      本文链接:https://www.haomeiwen.com/subject/blbarrtx.html