摄像设备+nginx+rtmp服务器

news2024/10/7 18:27:40

前言

由于html中的video现在不支持rtmp协议(需要重写播放器框架,flash被一刀切,360浏览器还在支持flash),遂用rtmp作为桥梁,实际是hls协议在html中起作用. 在此推荐一款前端播放器,.ckplayer 简直了,写点页面,一直循环,洗脑神曲 dream it possible.

搭建nginx服务器

环境准备

1.下载环境

nginx包: nginx包 RTMP模块包:nginx-http-flv-module 模块包

2.依赖项

yum -y install unzip
yum -y install gcc-c++ 
yum -y install pcre pcre-devel  
yum -y install zlib zlib-devel 
yum -y install openssl openssl-devel

3.安装

新建nginx路径

mkdir /usr/local/nginx

将下载的模块包复制到nginx目录下,并解压

cp /opt/toos/nginx-http-flv-module-1.2.6.zip  /usr/local/nginx/nginx-http-flv-module
cd /usr/local/nginx
unzip nginx-http-flv-module

安装nginx服务器

tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx  --add-module=/usr/local/nginx/nginx-http-flv-module
make && make install

【免费分享】音视频学习资料包、大厂面试题、技术视频和学习路线图,资料包括(C/C++,Linux,FFmpeg webRTC rtmp hls rtsp ffplay srs 等等)有需要的可以点击788280672加群免费领取~

nginx服务器配置文件

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
   worker_connections  1024;
}


rtmp {
   server {
       allow publish all;
       listen 1935;
       ping 30s;
       notify_method get;

       application myapp {
           live on;

           # sample play/publish handlers
           #on_play http://localhost:8080/on_play;
           #on_publish http://localhost:8080/on_publish;

           # sample recorder
           #recorder rec1 {
           #    record all;
           #    record_interval 30s;
           #    record_path /tmp;
           #    record_unique on;
           #}

           # sample HLS
           hls on;
           hls_path /tmp/hls;
           # hls_sync 100ms;
           hls_fragment 5s; 
           hls_cleanup off;
           record all;

           record_path /tmp/record;
           record_unique on;
       }
        
       # Video on demand
       application vod {
       #    play /var/Videos;
            play /usr/local/video;
       }

       # Video on demand over HTTP
       #application vod_http {
       #    play http://localhost:8080/vod/;
       #}
   }
}
http {
   include       mime.types;
   default_type  application/octet-stream;

   #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
   #                  '$status $body_bytes_sent "$http_referer" '
   #                  '"$http_user_agent" "$http_x_forwarded_for"';

   #access_log  logs/access.log  main;

   sendfile        on;
   #tcp_nopush     on;

   #keepalive_timeout  0;
   keepalive_timeout  65;

   #gzip  on;

server {
   listen       80;
   server_name  localhost;

   #charset koi8-r;

   #access_log  logs/host.access.log  main;

      


  # location / {
   #    root   /tmp/hls;
   #    
   #}


   #HLS配置开始,这个配置为了`客户端`能够以http协议获取HLS的拉流
   location / {
   add_header Access-Control-Allow-Origin *;
   	add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
   	add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

       index  index.html index.htm;
       # Serve HLS fragments
       types {
           application/vnd.apple.mpegurl m3u8;
           video/mp2t ts;
       }
       root /tmp/hls;
       add_header Cache-Control no-cache;
   }
   #HLS配置结束

   # rtmp stat
   location /stat {
       rtmp_stat all;
       rtmp_stat_stylesheet stat.xsl;
   }
   location /stat.xsl {
       # you can move stat.xsl to a different location
       # root /usr/build/nginx-rtmp-module;
       root /usr/local/src/nginx-rtmp-module-1.2.1;
   }

   # rtmp control
   location /control {
       rtmp_control all;
   }


   #error_page  404              /404.html;

   # redirect server error pages to the static page /50x.html
   #
   error_page   500 502 503 504  /50x.html;
   location = /50x.html {
       root   html;
   }

}


   # another virtual host using mix of IP-, name-, and port-based configuration
   #
   #server {
   #    listen       8000;
   #    listen       somename:8080;
   #    server_name  somename  alias  another.alias;

   #    location / {
   #        root   html;
   #        index  index.html index.htm;
   #    }
   #}


   # HTTPS server
   #
   #server {
   #    listen       443 ssl;
   #    server_name  localhost;

   #    ssl_certificate      cert.pem;
   #    ssl_certificate_key  cert.key;

   #    ssl_session_cache    shared:SSL:1m;
   #    ssl_session_timeout  5m;

   #    ssl_ciphers  HIGH:!aNULL:!MD5;
   #    ssl_prefer_server_ciphers  on;

   #    location / {
   #        root   html;
   #        index  index.html index.htm;
   #    }
   #}

4.ffmpeg推码

下载ffmpeg模块包 ffmpeg模块包:ffmpeg

查询设备

ffmpeg -list_devices true -f dshow -i dummy

测试录像设备可用

ffplay -f dshow -i video="BisonCam, NB Pro"  

ffmpeg -f dshow -i video="BisonCam, NB Pro" -vcodec libx264 -vf scale=320:240 -preset:v ultrafast -tune:v zerolatency -f flv rtmp://[ip地址]/[你的application,我上面的application写的[myapp]]myapp/[文件名称]wechat

跨域问题(在nginx中添加跨域)

add_header Access-Control-Allow-Origin *;
    	add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    	add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

5. 在html中访问。

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>前端播放m3u8格式视频</title>
    <link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet">
    <script src='https://vjs.zencdn.net/7.4.1/video.js'></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js"
        type="text/javascript"></script>
    <!-- videojs-contrib-hls 用于在电脑端播放 如果只需手机播放可以不引入 -->
</head>

<body>
    <style>
        .video-js .vjs-tech {
            position: relative !important;
        }
    </style>
    <div>
        <video id="myVideo" class="video-js vjs-default-skin vjs-big-play-centered" controls preload="auto"
            data-setup='{}' style='width: 100%;height: auto'>
            <source id="source"
                src="http://[你的ip地址]/[你的文件名称]wechat.m3u8"
                type="application/x-mpegURL">
            </source>
        </video>
    </div>
    <div class="qiehuan"
        style="width:100px;height: 100px;background: red;margin:0 auto;line-height: 100px;color:#fff;text-align: center">
        切换视频</div>
</body>

<script>
    // videojs 简单使用
    var myVideo = videojs('myVideo', {
        bigPlayButton: true,
        textTrackDisplay: false,
        posterImage: false,
        errorDisplay: false,
    })
    myVideo.play()
    var changeVideo = function (vdoSrc) {
        if (/\.m3u8$/.test(vdoSrc)) { //判断视频源是否是m3u8的格式
            myVideo.src({
                src: vdoSrc,
                type: 'application/x-mpegURL' //在重新添加视频源的时候需要给新的type的值
            })
        } else {
            myVideo.src(vdoSrc)
        }
        myVideo.load();
        myVideo.play();
    }
    var src = 'http://[你的ip地址]/[你的文件名称].m3u8';
    document.querySelector('.qiehuan').addEventListener('click', function () {
        changeVideo(src);
    })
</script>

原文链接 摄像设备+nginx+rtmp服务器 - 掘金

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1460014.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Springboot 中使用 Redisson+AOP+自定义注解 实现访问限流与黑名单拦截

&#x1f3f7;️个人主页&#xff1a;牵着猫散步的鼠鼠 &#x1f3f7;️系列专栏&#xff1a;Java全栈-专栏 &#x1f3f7;️个人学习笔记&#xff0c;若有缺误&#xff0c;欢迎评论区指正 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&…

美团外卖商超销量数据

字段内容&#xff1a; shop_id varchar(50) NOT NULL, shop_id_str varchar(50) NOT NULL, shop_name varchar(400) DEFAULT NULL, shop_min_price varchar(10) DEFAULT NULL, shop_score varchar(10) DEFAULT NULL, shop_wm_score varchar(10) DEFAULT NU…

《Solidity 简易速速上手小册》第9章:DApp 开发与 Solidity 集成(2024 最新版)

文章目录 9.1 DApp 的架构和设计9.1.1 基础知识解析更深入的理解实际操作技巧 9.1.2 重点案例&#xff1a;去中心化社交媒体平台案例 Demo&#xff1a;创建去中心化社交媒体平台案例代码SocialMedia.sol - 智能合约前端界面 测试和验证拓展功能 9.1.3 拓展案例 1&#xff1a;去…

2024云服务器ECS_云主机_服务器托管_e实例-阿里云

阿里云服务器ECS英文全程Elastic Compute Service&#xff0c;云服务器ECS是一种安全可靠、弹性可伸缩的云计算服务&#xff0c;阿里云提供多种云服务器ECS实例规格&#xff0c;如ECS经济型e实例、通用算力型u1、ECS计算型c7、通用型g7、GPU实例等&#xff0c;阿里云服务器网al…

springboot+flowable 使用方式

创建flowble制定流程图 登录flowalbe 制定流程图 进入建模器应用程序 创建流程图 分配用户 下载流程图 使用springboot 调用flowable /*** 导入流程图老师流程*/Testvoid startTeacherApprover(){Deployment deploy repositoryService.createDeployment().addClasspathRes…

IDEA的版本控制Local Changes和settings按钮显示问题

经常用idea的小伙伴应该对标题的这两个功能不陌生&#xff0c;特别是Local Changes 周日刚开工&#xff0c;我的idea就过期了&#xff0c;索性就下载了一个2023.3.3版本的&#xff0c;安装好打开一看&#xff0c;发现Local Changes 和 settings的按钮消失了&#xff0c;虽然说…

【Git】:分支管理

分支管理 一.概念二.分支管理基本操作三.分支管理策略1.noff模式2.分支策略 一.概念 在版本回退⾥&#xff0c;你已经知道&#xff0c;每次提交&#xff0c;Git都把它们串成⼀条时间线&#xff0c;这条时间线就可以理解为是⼀个分⽀。截⽌到⽬前&#xff0c;只有⼀条时间线&…

超平面介绍

超平面公式 (1) 超平面是指n维线性空间中维度为n-1的子空间。它可以把线性空间分割成不相交的两部分。比如二维空间中&#xff0c;一条直线是一维的&#xff0c;它把平面分成了两部分&#xff1b;三维空间中&#xff0c;一个平面是二维的&#xff0c;它把空间分成了两部分。(2…

斐讯插座DC1指示灯不亮按钮不能打开开关维修方法

故障现象 当时入了2个插座&#xff0c;时至今年2个插座都坏了&#xff0c;表现为wifi灯不亮&#xff0c;三个插孔对应的开关按了没反应。2个插座同样的问题应该是通病&#xff0c;在这里分享一下维修经验。斐讯插座市面上应该有很多&#xff0c;说多都是泪。 故障分析 在图片…

Prometheus+influxdb1.8实现高可用监控系统

背景 Prometheus是业内有名的开源监控工具&#xff0c;我所在的公司也是采用PrometheusGrafana方式构建监控系统&#xff0c;并且不只是监控运维层面的数据&#xff0c;业务层面的服务状态也通过Java代码的客户端micrometer向Prometheus提交数据并在Grafana上配置出图&#xf…

word中插入公式,公式和文字不在一条线上,怎么解决?

本解决方案以word2013为版本&#xff0c;其余版本大同小异。 在word文本编辑的时候我们避免不了需要进行文本、公式的同时编辑&#xff0c;在编辑公式存在两种情况&#xff1a;1、公式单独成为一行&#xff1b;2、公式和中英文存在同一行。经常会出现以下问题。 很多人不知所措…

【Unity】【VR开发】如何创建让物体透明的Material

【背景】 在VR开发中&#xff0c;如果遇到需要锚点传送移动的场景&#xff0c;作为锚点的目标往往需要设置为透明。本篇介绍简单设置Material使3D GameObject便透明的方法。 【操作方法】 新建一个Material对象选中Material对象后&#xff0c;在Inspector面板中重选Shader属…

【Flink】FlinkSQL读取hive数据(批量)

一、简介: Hive在整个数仓中扮演了非常重要的一环,我们可以使用FlinkSQL实现对hive数据的读取,方便后续的操作,本次例子为Flink1.13.6版本 二、依赖jar包准备: 官网地址如下: Overview | Apache Flink 1、我们需要准备相关的jar包到Flink安装目录的lib目录下,我们需…

重铸安卓荣光——上传图片组件

痛点&#xff1a; 公司打算做安卓软件&#xff0c;最近在研究安卓&#xff0c;打算先绘制样式 研究发现安卓并不像前端有那么多组件库&#xff0c;甚至有些基础的组件都需要自己实现&#xff0c;记录一下自己实现的组件 成品展示 一个上传图片的组件 可以选择拍照或者从相册中…

php反序列化原理常见的魔术方法

序列化是什么&#xff1f; 要想了解反序列化&#xff0c;就先要知道序列化是什么。下面是是一串序列化数组&#xff1a; a:2:{s:4:"name";s:6:"cike_y";s:3:"age";i:18;}a表示array&#xff08;数组&#xff09;&#xff0c;2表示这个数组有两…

计算机网络Day1--计算机网络体系

1.三网合一 电信网络、广播电视网络、计算机网络&#xff08;最基础最重要发展最快&#xff09; 2.Internet 名为国际互联网、因特网&#xff0c;指当前全球最大的、开放的、由众多网络相互连接而成的特定互连网&#xff0c;采用TCP/IP 协议族作为通信的规则&#xff0c;前…

NoSQL 数据库管理工具,搭载强大支持:Redis、Memcached、SSDB、LevelDB、RocksDB,为您的数据存储提供无与伦比的灵活性与性能!

NoSQL 数据库管理工具&#xff0c;搭载强大支持&#xff1a;Redis、Memcached、SSDB、LevelDB、RocksDB&#xff0c;为您的数据存储提供无与伦比的灵活性与性能&#xff01; 【官网地址】&#xff1a;http://www.redisant.cn/nosql 介绍 直观的用户界面 从单一应用程序中同…

设计模式----开题

简介&#xff1a; 本文主要介绍设计模式中的六大设计原则。开闭原则&#xff0c;里氏代换原则&#xff0c;依赖倒转原则&#xff0c;接口隔离原则&#xff0c;迪米特原则和合成复用原则。这几大原则是设计模式使用的基础&#xff0c;在使用设计模式时&#xff0c;应该牢记这六大…

IDEA 如何运行SpringBoot项目(手把手超详细截图)

IDEA 如何运行SpringBoot项目&#xff08;手把手超详细截图&#xff09; 第一章:github 导入项目 在GitHub上面找到我们需要部署项目的URL&#xff0c;并且复制粘贴到IDEA中&#xff0c;如下图所示。 第二章&#xff1a;Maven的准备与部署 由于idea自带Maven环境&#xff0c…

利用vite快速搭建vue3项目

1、选择一个文件夹&#xff0c;在vscode终端打开&#xff0c;输入命令【npm create vitelatest】 npm create vitelatest 2、提示你输入项目名称之后&#xff0c;我这里设置的是【rookiedemo】 3、回车之后&#xff0c;出现选择框架的提示&#xff0c;我们选择【vue】回车 4、…