前端实现H265编码的m3u8视频流播放

这篇具有很好参考价值的文章主要介绍了前端实现H265编码的m3u8视频流播放。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前言

视频监控是智慧城市、智慧园区等WebGIS类系统中最为常见的硬件对接设备,最常用的监控视频流格式为m3u8格式,但是m3u8格式通常都是h.265编码格式的,我搜遍了几乎所有前端视频播放插件,几乎普通的播放器插件都不支持h.265格式的视频编码。本文就带领大家了解H265视频编码,并实现前端播放H265编码的视频。

m3u8支持h265吗,前端

1. 什么是H.265编码?

目前很多摄像机采用了H.265的编码标准,H.264编码的摄像机逐渐减少,为什么H.265会流行?H.264和H.265有何不同?

m3u8支持h265吗,前端

H.265是ITU-TVCEG继H.264之后所制定的新的视频编码标准。H.265标准围绕着现有的视频编码标准H.264,保留原来的某些技术,同时对一些相关的技术加以改进。新技术使用先进的技术用以改善码流、编码质量、延时和算法复杂度之间的关系,达到最优化设置。具体的研究内容包括:提高压缩效率、提高鲁棒性和错误恢复能力、减少实时的时延、减少信道获取时间和随机接入时延、降低复杂度等。H264由于算法优化,可以低于1Mbps的速度实现标清数字图像传送;H265则可以实现利用1~2Mbps的传输速度传送720P(分辨率1280*720)普通高清音视频传送。

H.265旨在在有限带宽下传输更高质量的网络视频,仅需原先的一半带宽即可播放相同质量的视频。这也意味着,我们的智能手机、平板机等移动设备将能够直接在线播放1080p的全高清视频。H.265标准也同时支持4K(4096×2160)和8K(8192×4320)超高清视频。可以说,H.265标准让网络视频跟上了显示屏“高分辨率化”的脚步。 

H.265虽然有点有很多,但是也有最大劣势。因为大佬级别公司神仙打架凡人遭殃,h265编码的视频不能直接在电脑端浏览器播放(部分电脑端的播放器软件支持播放),手机端(主要是安卓和苹果)是可以在浏览器直接播放的。所以,如果要使用h265编码的视频,你的浏览器端客户只能限制在手机端,电脑端浏览器用户考虑其他方案。

2. 解决Web端播放H265的方法

1. 第一种就是使用ffmpeg(FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案)进行转码,这种方案可能比较稳定,但是成本较高,而且实现比较复杂。

2. 使用前端视频播放插件,我在开发过程中尝试了很多很多前端的视频插件,都无法播放H265编码的视频。终于发现了这个开源免费的前端播放插件EasyPlayer.js。它通过和webassembly结合,实现了web端支持H265视频的播放,使用起来也很简单,GitHub开源地址:

GitHub - tsingsee/EasyPlayer.js: EasyPlayer.js H5播放器,是一款免费的能够同时支持HTTP、RTMP、HTTP-FLV、HLS(m3u8)直播与点播等多种协议,支持H.264、H.265、AAC等多种音视频编码格式,支持mse、asm、wasm等多种解码方式,支持Windows、Linux、Android、iOS全平台终端的H5播放器。EasyPlayer.js H5 Player support HTTP/RTMP/HTTP-FLV/HLS(m3u8) live streaming & vod streaming,support H.264/H.265/AAC video & audio codec,support mse/asm/wasm decode mode,support Windows/Linux/Android/iOS platform,EasyPlayer.js uses leading-edge technology.EasyPlayer.js H5播放器,是一款免费的能够同时支持HTTP、RTMP、HTTP-FLV、HLS(m3u8)直播与点播等多种协议,支持H.264、H.265、AAC等多种音视频编码格式,支持mse、asm、wasm等多种解码方式,支持Windows、Linux、Android、iOS全平台终端的H5播放器。EasyPlayer.js H5 Player support HTTP/RTMP/HTTP-FLV/HLS(m3u8) live streaming & vod streaming,support H.264/H.265/AAC video & audio codec,support mse/asm/wasm decode mode,support Windows/Linux/Android/iOS platform,EasyPlayer.js uses leading-edge technology. - GitHub - tsingsee/EasyPlayer.js: EasyPlayer.js H5播放器,是一款免费的能够同时支持HTTP、RTMP、HTTP-FLV、HLS(m3u8)直播与点播等多种协议,支持H.264、H.265、AAC等多种音视频编码格式,支持mse、asm、wasm等多种解码方式,支持Windows、Linux、Android、iOS全平台终端的H5播放器。EasyPlayer.js H5 Player support HTTP/RTMP/HTTP-FLV/HLS(m3u8) live streaming & vod streaming,support H.264/H.265/AAC video & audio codec,support mse/asm/wasm decode mode,support Windows/Linux/Android/iOS platform,EasyPlayer.js uses leading-edge technology.https://github.com/tsingsee/EasyPlayer.jsm3u8支持h265吗,前端

EasyPlayer.js简介:EasyPlayer.js H5播放器,是一款免费的能够同时支持HTTP、RTMP、HTTP-FLV、HLS(m3u8)直播与点播等多种协议,支持H.264、H.265、AAC等多种音视频编码格式,支持mse、asm、wasm等多种解码方式,支持Windows、Linux、Android、iOS全平台终端的H5播放器。 

3. 使用EsayPlayer.js实现前端播放H.265编码的视频流

1. Vue2项目安装EasyPlayer视频播放插件
  npm install @easydarwin/easyplayer --save
 2. 解压后根据说明文档将文件移动到指定位置

(1)node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer.swf 移动到 静态文件 根目录

(2)node_modules/@easydarwin/easyplayer/dist/component/crossdomain.xml 移动到 静态文件 根目录

(3)node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer-lib.min.js 移动到 静态文件 根目录

(4)特别注意:播放H.265视频需要将:node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer.wasm 到 静态文件 根目录

3. 在项目中引入和使用H5视频播放插件

(1)在index.html文件中引入EasyPlayer-lib.min.js

<script src="./EasyPlayer-lib.min.js"></script>

(2)在组件中使用EasyPlayer播放插件

<template>
    <div class="monitor-container">
        <div class="monitor-list-container">
            <div class="monitor-list-title">
                费县视频监控
            </div>
            <div class="monitor-list-scroll-container">
                <div class="monitor-class-name" @click="monitorShow = !monitorShow">
                    <i class="el-icon el-icon-s-grid"></i>
                    费县森林防火视频监控({{ monitorList.length }})
                    <i class="el-icon  el-icon-arrow-down" style="float:right;margin-top:16px;"></i>
                </div>
                <div v-show="monitorShow">
                    <div class="monitor-item" v-for="(item,index) in monitorList" :key="index" >
                        <i class="el-icon el-icon-video-camera"></i>
                        {{ item.cameraname }}
                    </div>
                </div>

                <div class="monitor-class-name" @click="monitor2Show = !monitor2Show">
                    <i class="el-icon el-icon-s-grid"></i>
                    市应急指挥视频监控({{ monitorList2.length }})
                    <i class="el-icon  el-icon-arrow-down" style="float:right;margin-top:16px;"></i>
                </div>
                <div  v-show="monitor2Show">
                    <div class="monitor-item" v-for="(item,index) in monitorList2" :key="index" @click="playVideo(item,index)">
                        <i class="el-icon el-icon-video-camera"></i>
                        {{ item.jkdmckjg }}
                    </div>
                </div>
                

            </div>
        </div>
        <div class="video-container">
            <div class="layout-container">

            </div>
                <EasyPlayer
                v-for="(item,index) in playArrays" :key="index"
                style="width:450px;height:250px;float:left;margin-right:15px;margin-bottom:15px;"
                :videoUrl="item"
                :aspect="aspect"
                live
                @message="$message"
                :fluent="fluent"
                :autoplay="true"
                stretch
                ></EasyPlayer>
        </div>
    </div>
</template>

<script>
import EasyPlayer from '@easydarwin/easyplayer'
import axios  from 'axios';
import { getMethodCommon } from '../../../api/common';

import 'video.js/dist/video-js.css'
import videojs from "video.js";
import "videojs-contrib-hls";

export default{
    components:{
        EasyPlayer
    },
    data(){
        return {
            videoUrl:"",
            aspect:"16:9",
            fluent:true,
            playArrays:[],
            monitorShow:false,
            monitor2Show:true,
            monitorList:[],
            monitorList2:[],
            player:null,
        }
    },
    created(){
        this.getHKmonitorlist();
        this.getYJmonitorlist();
    }, 
    mounted() {
        let _this = this;
        setTimeout(()=>{
            
        },5000)
    },
 
    methods:{
        getVideo() {
            videojs("myvideo",{
                bigPlayButton: false,
                textTrackDisplay: false,
                posterImage: true,
                errorDisplay: false,controlBar: true
            },
            function() {
                this.play();
            });
        },
        playVideo(item,index){
            if(this.playArrays.find((it,idx)=>{
                return it == "http://***.***.***.***/live/"+item.jkdgbidzlkjg+".m3u8"
            })){
                this.$message({
                    type:"error",
                    message:"已经添加至播放列表"
                })
                return;
            }
            if(this.playArrays.length>=4){
                this.playArrays.shift();
            }
            this.playArrays.push("http://***.***.***.***:7012/live/"+item.jkdgbidzlkjg+".m3u8")
        },

        // 获取海康监控列表
        getHKmonitorlist(){
            axios({
                method:"get",
                url:"http://***.***.***.***:9007/geoserver/ksp/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ksp%3Amonitornest&maxFeatures=10000&outputFormat=application%2Fjson",
            }).then(res=>{
                res.data.features.forEach((item,index)=>{
                    let obj = item.properties;
                    this.monitorList.push(obj);
                    if(index<=3){
                        this.playArrays.push("http://***.***.***.***:7012/live/"+item.jkdgbidzlkjg+".m3u8")
                    }
                })
                
            })
        },
        // 市应急局监控设备
        getYJmonitorlist(){
            getMethodCommon("/YingJiJu/LoadCameraInfo?county=费县&pageIndex=1&pageSize=999").then(res=>{
                if(res.code ==  200){
                    this.monitorList2 = res.data;

                }
            })
        },

    }
}
</script>

<style scoped>

.monitor-container{
    width:100%;
    height:100%;
    background:#30645eaa;
    padding:15px;
    background-image: url(/img/biaohui.png);
    background-size:100% 100%;
}

.monitor-list-container{
    width:240px;
    height:100%;
    float:left;
}

.monitor-list-title{
    width:100%;
    height:60px;
    font-size:20px;
    text-indent:15px;
    color:#fff;
    cursor:pointer;
}

.monitor-list-scroll-container{
    width: calc( 100% - 12px);
    height: calc(100% - 60px);
    overflow-y: auto;
    padding-right:12px;
}

.monitor-class-name{
    width:100%;
    height:42px;
    line-height:42px;
    color:#fff;
}
.monitor-item{
    width:100%;
    height:24px;
    line-height:24px;
    color:#cfcfcf;
    font-size:12px;
    text-indent: 4px;
    overflow: hidden;
    cursor: pointer;
}
.monitor-item:hover{
    background:#30645e;
}

.video-container{
    width: calc( 100% - 240px);
    float:right;
    height:100%;
}

.layout-container{
    width:100%;
    height:50px;
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-thumb {
  border: 0;
}

::-webkit-scrollbar {
  height: 10px;
  width: 10px;
  background: transparent;
  border-radius: 5px;
}

::-webkit-scrollbar-thumb {
  padding-top: 100px;
  -webkit-box-shadow: inset 1px 1px 1px rgba(0, 0, 0, 0.25);
  background-color: rgba(0, 0, 0, 0.4);
  min-height: 28px;
  border-radius: 4px;
  background-clip: padding-box;
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-thumb {
  border: 0;
}

::-webkit-scrollbar-thumb:hover {
    -webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.1),
    inset -1px -1px 0 rgba(0, 0, 0, 0.07);
  background-color: #797979;
}

::-webkit-scrollbar-thumb:active {
  -webkit-box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.35);
  background-color: rgba(0, 0, 0, 0.5);
}
</style>

项目截图:

m3u8支持h265吗,前端文章来源地址https://www.toymoban.com/news/detail-800945.html

到了这里,关于前端实现H265编码的m3u8视频流播放的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Unity WebGL 播放视频流m3u8

    目录 介绍 步骤 1.导入AVProVideo插件,创建场景,创建空物体添加MediaPlayer组件设置m3u8视频地址以及WebGL平台设置  2.在Canvas下创建Avpro Video,为MediaPlayer赋值  3.可以现在编辑器模式下测试视频地址是否可以播放,然后打包  4.打包完成后,将文件hls.min.js复制到Build文件夹下: 5

    2023年04月10日
    浏览(35)
  • 小X通m3u8视频流AES加密分析

    最近有空研究了下小X通的视频协议,下面记录下研究过程 首先我们要了解下m3u8是什么 首先我们需要了解什么时HLS,所谓HLS(HTTP Live Streaming)是一个由苹果公司提出的基于 HTTP 的流媒体网络传输协议。而m3u8是HLS协议的一部分,但是在直播,视频网站等用处很广泛。 HLS协议规定

    2024年02月05日
    浏览(29)
  • Windows上搭建rtsp-simple-server流媒体服务器实现rtsp、rtmp等推流以及转流、前端html与Vue中播放hls(m3u8)视频流

    Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流: Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流_霸道流氓气质的博客-CSDN博客 上面讲了Nginx-http-flv-module+flv.js进行流媒体服务器搭建和前端播放视频流的过

    2024年02月01日
    浏览(39)
  • 关于vue播放flv,m3u8视频流(监控)的方法

    前文: 随着前端大屏页面的逐渐壮大,客户的需求也越来越多,大屏上面展示的事物也越来越丰     富。其中实时播放监控的需求逐步增加,视频流格式也是有很多种,用到最多的.flv、.m3u8。 一、 JessibucaPlayer插件用来播放flv流 1.首先是先把文件放在vue项目的public下面 2.在

    2023年04月15日
    浏览(72)
  • 在AWS Lambda中使用FFmpeg处理m3u8视频流

    在直播里领域,我们经常需要对视频流进行处理。FFmpeg则是该领域中处理的利器。这篇文章,我们将以视频流截图为例,讲解如何在AWS Lambda中对m3u8视频流进行截图。因为Lambda是无服务架构,其本地存储是不可靠的,于是最后我们需要将截图文件上传S3桶。 这块的方案可以见

    2024年02月03日
    浏览(44)
  • 处理前端访问m3u8视频文件出现跨越问题

    一、后端模板渲染的方式,不需要处理,不会存在跨域问题 二、如果是前后端分离项目在 nginx 中配置跨域 1、 m3u8 文件存放在服务器地址为`/home/video-api/public/uploads/video 2、修改 nginx 的配置 3、客户端在 js 代码里面输入视频地址 http://【ip或者域名】/uploads/video/1686034066126185.m3u

    2024年02月09日
    浏览(39)
  • 【vue】前端页面点击按钮弹窗播放m3u8格式视频

    最终效果: 1.表格操作列 2.initVideo方法 3.弹出层代码 4.showAll_dialog样式 5.第2步跳转的video.html页面代码,用dplayer播放的,放在项目根目录的public文件夹即可

    2024年02月04日
    浏览(37)
  • 前端vue播放m3u8、flv、mp4视频的方法

    安装依赖 npm install video.js --save // 视频播放器插件 npm install videojs-contrib-hls --save // 播放hls流插件 页面引入插件 页面中的使用 简介:flv.js是 HTML5 Flash 视频(FLV)播放器,纯原生 JavaScript 开发,没有用到 Flash。由 bilibili 网站开源。 开源地址: https://github.com/Bilibili/flv.js/ 安装依

    2024年02月13日
    浏览(41)
  • Python 实现 m3u8 视频下载

    m3u8 是一种 基于文本的媒体播放列表文件格式 ,通常用于指定流媒体播放器播放在线媒体流。它是一个简单的文本文件,其中包含多个由 URI 引用的媒体资源文件的 URL。m3u8 文件通常包含多个 ts 文件的链接,这些 ts 文件是实际的视频和音频数据文件,通常是通过 HTTP 协议传

    2024年02月07日
    浏览(39)
  • 安卓实现M3U8文件的下载和播放

    现如今网络上的视频大多数都是m3u8格式的,使用m3u8格式有以下好处 1. 方便切换码率,例如从高清转到蓝光 2. 节约流量,m3u8实际切割成一段段的TS后缀视频,传统请求是把整个文件流返回去,网络不好或者文件过大时,都会造成响应缓慢,m3u8则是返回一个个的ts文件,当前

    2023年04月20日
    浏览(43)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包