Windows 11实现录屏直播,搭建Nginx的rtmp服务
时间:2021-12-23 作者:linnuo
先!下载几个工具呗
官方下载FFmpeg:http://域名
官方下载nginx-rtmp-module:https://域名/arut/nginx-rtmp-module
Nginx Gryphon下载:https://域名/s/18qULuaTYIzYGs1OPKa-g_w 提取码:35a1
1、在D盘创建D:\live目录,将FFmpeg、Nginx Gryphon解压到该目录下
2、配置环境
打开Win 11控制面板,系统》关于》高级系统设置》环境变量
在系统变量双击Path,新建,将 D:\live\ffmpeg-N-104969-g18ad360648-win64-gpl-shared\bin 和 D:\live\nginx-域名.3-Gryphon 添加到 Path
3、 启动Nginx服务
调出CMD命令窗口进入 Nginx 目录,启动 Nginx命令:
域名 -c conf\nginx-域名
4、FFmpeg 推流
桌面推流:
域名 -f gdigrab -i desktop -f flv rtmp://127.0.0.1:1935/live
视频推流:
域名 -re -i .\林诺好帅.mp4 -vcodec libx264 -acodec aac -f flv rtmp://127.0.0.1:1935/video
摄像头推流:
域名 -f dshow -i video="相机名" -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f flv rtmp://127.0.0.1:1935/camera #相机名在设备里查询
5、写个Web页面 D:\live\nginx-域名.3-Gryphon\html 目录,修改 域名
<!DOCTYPE html> <html lang="en"> <head> <title>HTML5 直播</title> <link href="http://域名/域名/video-域名" rel="stylesheet"> <script src="http://域名/域名/域名"></script> <script src="https://域名/npm/videojs-flash@2/dist/videojs-域名"></script> </head> <body> <video id="myvideo" class="video-js vjs-default-skin" controls preload="auto" width="1280" height="720" poster="http://域名/v/域名" data-setup="{}"> <source src="rtmp://127.0.0.1:1935/live" type="rtmp/flv"> <p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://域名/html5-video-support/" target="_blank">supports HTML5 video</a> </p> </video> </body> </html>
此时,输入本地IP就能看到录屏直播了
OK,大业已成~
如果提示:No compatible source was found for this media. 开启Flash 插件即可
6、关闭 Nginx,误操作开多了、需要结束等操作
taskkill /f /t /im 域名
7、考虑一下以下几个问题:
a、配置账号密码,不允许所有人访问
b、没开直播的时候放个图片在窗口