13、解決線上100M以上視頻循環(huán)播放倒是頁面卡死的情況

線上播放是視頻是160M以上的mp4視頻,經(jīng)過查看發(fā)現(xiàn)是視頻一直不斷的發(fā)送請求,下面就是根據(jù)這個找到的解決方案,經(jīng)過查找,發(fā)現(xiàn)video不適合在視頻很大的情況下使用,所以使用了把mp4視頻轉(zhuǎn)化為m3u8的方法:

1、mp4視頻轉(zhuǎn)為m3u8

1.1、安裝FFmpeg

1.1.1 下載

FFmpeg官網(wǎng)下載,

image.png

image.png

1.1.2解壓到本地

image.png

設(shè)置環(huán)境變量,搜索環(huán)境變量


image.png

在里面新建一條然后把bin的路徑放在里面保存

1.1.3驗證安裝是否成功

ffmpeg –version
image.png

出現(xiàn)這個就是安裝成功

1.2、代碼轉(zhuǎn)換

ffmpeg -i  C:\Users\PC\Downloads\test.mp4 -c:v libx264 -c:a aac -map 0 -f hls -hls_time 10 -hls_list_size 0 C:\Users\PC\Downloads\test.m3u8

在上面的命令中,input.mp4是要切片的文件名,-hls_time表示每個切片的持續(xù)時間(這里設(shè)置為10秒),-hls_list_size表示M3U8播放列表中切片文件的最大數(shù)量(這里設(shè)置為0,表示沒有限制),output.m3u8是M3U8播放列表的文件名

2、代碼使用

2.1、下載依賴

npm install video.js --save // 視頻播放器插件
npm install videojs-contrib-hls --save // 播放hls流插件

2.2、頁面使用

<template>
<video ref="videoPlayer" class="video-js vjs-big-play-centered"></video>
</template>
<script>
import videojs from 'video.js';
import 'video.js/dist/video-js.css';
import 'videojs-contrib-hls';
import zhCN from 'video.js/dist/lang/zh-CN.json';
videojs.addLanguage('zh-CN', zhCN);
</script>export default {
  name: 'WaterQuality',
  components: { VueQr },
  props: {},
  data() {
    return {
      videoSrc: 'http://2.0.0.1:8082/xxx.m3u8',
      options: {
        autoplay: false,
        controls: true,
        fill: true,
        loop: true,
        preload: true
      }
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initPlayer();
    });
  },
  beforeDestroy() {
    if ( this.player) {
      this.player.dispose();
    }
  },
  methods: {
    initPlayer() {
      let ref = this.$refs.videoPlayer;
      if (!ref) {
        return;
      }
      this.options.sources = [{ src: this.videoSrc, type: 'application/x-mpegURL' }];
      this.player = videojs(ref, this.options, () => {});
      this.player.language('zh-CN');
      this.player.play();
    },
  }
};
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容