分布式直播系统(九)【nginx-rtmp控制台暂停、录像控制】

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主AI工具!学习进阶更高效! 阅读详情

转载请注明出处:https://blog.csdn.net/impingo
项目地址:https://github.com/im-pingo/
项目官网:http://pingos.io

控制台接口

一个成熟的媒体服务器需要有跟业系统对接的能力,例如允许开发者开发自己的控制台系统,通过http接口控制当前直播流的暂停与播放,录像功能的暂停与继续等操作。
本项目支持多种控制台控制接口和流信息获取接口。

配置

配置项

配置项参数类型默认值描述
rtmp_control选项allall: 开启所有控制接口。record: 只开启录像控制接口。drop:只开启关闭连接控制接口。redirect:只开启重定向控制接口。pause:只开启暂停接口。 resume:只开启恢复接口

配置模板

user  root;
daemon on;
master_process on;
worker_processes  1;
#worker_rlimit 4g;
#working_directory /usr/local/openresty/nginx/logs;

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

worker_rlimit_nofile 102400;
worker_rlimit_core   2G;
working_directory    /tmp;

#pid        logs/nginx.pid;

events {
    use epoll;
    worker_connections  1024;
    multi_listen unix:/tmp/http 80;
}

stream_zone buckets=1024 streams=4096;

rtmp {
    log_format log_json '{$remote_addr, [$time_local]}';
    access_log logs/rtmp.log trunc=2s;
    server {
        listen 1935;
        serverid 000;
        out_queue 2048;

        application live {
            rtmp_auto_pull on;
            rtmp_auto_pull_port unix:/tmp/rtmp;
#            live_record on;
#            live_record_path /tmp/record;
#            live_record_interval  1m;
            record all;
            record_path /tmp/record;

#            exec_publish_done bash -c  "ffmpeg -i /tmp/record/$name.flv -c copy /tmp/record/$basename.mp4";
#            exec_publish bash -c "ffmpeg -i rtmp://127.0.0.1/live/$name -c copy -movflags faststart /tmp/record/$name-$starttime.mp4";
            idle_streams on;
#
#            oclp_pull http://127.0.0.1/p1;

#            push rtmp://120.132.13.108/live;

            live on;
            hls on;
            hls_type live;
            hls_path /tmp/hls;
            hls_fragment 5000ms;
            hls_max_fragment 8000ms;
            hls_playlist_length 15000ms;

#            live_record on;
#            live_record_path /tmp/record;
#            live_record_interval 2m;
#            live_record_min_fragment 10s;
#            live_record_max_fragment 30s;

            hls2memory on;
            mpegts_cache_time 20s;

            hls2_fragment 1000ms;
            hls2_max_fragment 1300ms;
            hls2_playlist_length 3000ms;

            wait_key on;
            wait_video on;
            cache_time 3s;
            low_latency off;
            fix_timestamp 0s;
# h265 codecid, default 12
            hevc_codecid  12;
        }
    }
}

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" "$http_X-Real-IP" "$host"';


    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #reset_server_name www.test1.com www.test2.com;
    #gzip  on;
    server {
         listen 80;
         location /ts {
             ts_live 1935 app=live;
         }
        location /control {
            rtmp_control all;
        }
        location /rtmp_stat {
            rtmp_stat all;
            rtmp_stat_stylesheet /stat.xsl;
        }

        location /xstat {
            rtmp_stat all;
        }

        location /sys_stat {
            sys_stat;
        }

     location /live {
            flv_live 1935;
         }
         
         location /files {
	         alias /tmp/record;
	        #Nginx日志目录
	         autoindex on;
	         #打开目录浏览功能
	         autoindex_exact_size off;
	         #默认为on,显示出文件的确切大小,单位是bytes
	         #显示出文件的大概大小,单位是kB或者MB或者GB
	         autoindex_localtime on;
	         #默认为off,显示的文件时间为GMT时间。
	         #改为on后,显示的文件时间为文件的服务器时间
	         add_header Cache-Control no-store;
         }
         location /hls {
            # Serve HLS fragments
             types {
                 application/vnd.apple.mpegurl m3u8;
                 video/mp2t ts;
             }
             root /tmp;
             expires -1;
             add_header Cache-Control no-cache;
         }

        location /hls2 {
             hls2_live 1935 app=live;
         }
         location / {
             chunked_transfer_encoding on;
             root html/;
         }

         location /hls0/ {
             types{
                 application/vnd.apple.mpegurl m3u8;
                 video/mp2t ts;
             }
             expires -1;
         }
    }
}

控制接口说明

接口名请求回复描述
暂停推流/${location}/pause/publisher?srv=${serverid}&app=${app}&name=${name}参考 http ack服务器停止转发收到的直播流
恢复推流/${location}/resume/publisher?srv=${serverid}&app=${app}&name=${name}参考 http ack服务器恢复转发收到的直播流
暂停录像/${location}/record/stop?srv=${serverid}&app=${app}&name=${name}&rec=${recorder}参考 http ack暂停某条流的录像
恢复录像/${location}/record/start?srv=${serverid}&app=${app}&name=${name}&rec=${recorder}参考 http ack恢复某条流的录像

JS控制台示例

为了更好地帮助大家理解上述接口的使用方法,我专门写了一个简单的js控制台,仅仅实现了暂停、播放、录像和停止录像的基本控制。
在这里插入图片描述
源码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<script>
    function pause() {
		var name=document.getElementById('value').value;
		var ip=document.getElementById('ip').value;
        var url = 'http://'+ ip + '/control/pause/publisher?srv=000&app=live&name='+name;
        var request = new XMLHttpRequest();
        request.open("Get", url, true);
        request.send()
    }

    function resume() {
		var name=document.getElementById('value').value;
		var ip=document.getElementById('ip').value;
        var url = 'http://' + ip + '/control/resume/publisher?srv=000&app=live&name='+name;
        var request = new XMLHttpRequest();
        request.open("Get", url, true);
        request.send()
    }

    function pauseRecord(){
		var name=document.getElementById('value').value;
		var ip=document.getElementById('ip').value;
        var url = 'http://' + ip + '/control/record/stop?srv=000&app=live&name='+name+'&rec=r1';
        var request = new XMLHttpRequest();
        request.open("Get", url, true);
        request.send()
    }

    function resumeRecord(){
		var name=document.getElementById('value').value;
		var ip=document.getElementById('ip').value;
        var url = 'http://'+ip+'/control/record/start?srv=000&app=live&name='+name+'&rec=r1';
        var request = new XMLHttpRequest();
        request.open("Get", url, true);
        request.send()
    }

    function finalize(){
		var name=document.getElementById('value').value;
		var ip=document.getElementById('ip').value;
        var url = 'http://'+ip+'/control/drop/publisher?srv=000&app=live&name='+name;
        var request = new XMLHttpRequest();
        request.open("Get", url, true);
        request.send()
    }
</script>

    <span id="car_control" class="car">
		server ip:
        <input type="text" id="ip" placeholder=""/><br/>
		stream name:
        <input type="text" id="value" placeholder=""/><br/>
        <button class="top" onclick="pause()">暂停直播</button>
        <button class="left" onclick="resume()">继续直播</button>
        <button class="right" onclick="pauseRecord()">暂停录像</button>
        <button class="bottom" onclick="resumeRecord()">继续录像</button>
        <button class="bottom" onclick="finalize()">结束直播</button>
    </span>
</body>
</html>

录像文件查看接口

生成的录像文件会存在固定目录下,通过http接口(http://ip/files/)可以在浏览器中看到其文件列表。
在这里插入图片描述

获取流信息

通过接口(http://ip/xstat)可请求到所有在线流的信息,内容如下

<?xml version="1.0" encoding="utf-8" ?>
<rtmp>
    <nginx_version>1.17.1</nginx_version>
    <nginx_rtmp_version>1.1.4</nginx_rtmp_version>
    <compiler>gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) </compiler>
    <built>Oct 24 2019 16:26:06</built>
    <pid>20853</pid>
    <uptime>176258</uptime>
    <naccepted>3</naccepted>
    <bw_in>0</bw_in>
    <bytes_in>171403</bytes_in>
    <bw_out>0</bw_out>
    <bytes_out>172549</bytes_out>
    <server>
        <serverid>000</serverid>
        <live>
            <stream>
                <name>0</name>
                <time>3225</time>
                <bw_in>0</bw_in>
                <bytes_in>168524</bytes_in>
                <bw_out>0</bw_out>
                <bytes_out>165725</bytes_out>
                <bw_audio>0</bw_audio>
                <bw_video>0</bw_video>
                <client>
                    <id>455</id>
                    <address>0.0.0.0:1935</address>
                    <remote_address>127.0.0.1</remote_address>
                    <time>3056</time>
                    <flashver>LNX 9,0,124,2</flashver>
                    <dropped>0</dropped>
                    <avsync>0</avsync>
                    <timestamp>0</timestamp>
                    <active/>
                </client>
                <client>
                    <id>454</id>
                    <address>0.0.0.0:1935</address>
                    <remote_address>127.0.0.1</remote_address>
                    <time>3413</time>
                    <flashver>FMLE/3.0 (compatible; Lavf58.26.101)</flashver>
                    <dropped>0</dropped>
                    <avsync>11</avsync>
                    <timestamp>3219</timestamp>
                    <publishing/>
                    <active/>
                </client>
                <meta>
                    <video>
                        <width>1920</width>
                        <height>1080</height>
                        <frame_rate>24</frame_rate>
                        <codec>H264</codec>
                        <profile>High</profile>
                        <compat>0</compat>
                        <level>4.0</level>
                    </video>
                    <audio>
                        <codec>AAC</codec>
                        <profile>LC</profile>
                        <channels>6</channels>
                        <sample_rate>48000</sample_rate>
                    </audio>
                </meta>
                <nclients>2</nclients>
                <publishing/>
                <active/>
            </stream>
            <nclients>2</nclients>
        </live>
    </server>
</rtmp>

本项目支持的接口远不止此,更多控制接口请继续关注后续的文章或者进群交流。

QQ交流群:697773082

带你吃透RTMP title: 带你吃透RTMP date: 2016-03-06 19:26:00tag: [RTMP, 协议]RTMP协议是Real Time Message Protocol(实时信息传输协议)的缩写,它是由Adobe公司提出的一种应用层的协议,用来解决多媒体数据传输的多路复用(Multiplexing)和分包(packetizing)的问题。随着VR技术的发展,视频直播等领域逐渐活跃起来, 阅读详情

相关推荐

ngx_rtmp_control_module 模块解读

1、模块功能描述 本模块主要提供了外部接口控制rtmp状态的接口,通过这些接口进行一些断,录制,名重定向等以下接口: record 录制功能 drop 断功能,涉黄涉暴力的话可以通过这个方式断开服务端的 redirect 对进行重定向功能 1.1 配置示例 http { server { listen 88; server...

wu5215080的专栏 2511

流媒体协议

RTP(Real-time Transport Protocol)是一种用于实时传输音频和视频数据的网络协议。它设计用于在IP网络中通过UDP传输实时媒体,并为实时应用提供时间同步、传输和媒体数据统计。RTP通常与RTCP(RTP Control Protocol)一起使用,RTCP用于传输控制信息和反馈报告,以支持实时媒体的监控和质量控制。RTP协议提供了以下功能:序列化和分段化:将音频和视频数据分割成小的RTP数据包以便传输。

feng123999的博客 449

nginx-rtmp】02、调试日志(Debug log)

有时候你需要解决一些流媒体问题,需要查看日志,这个要重新配置nginx 使用 --with-debug 标识,如: cd nginx-X.Y.Z ./configure --add-module=/path/to/nginx-rtmp-module --with-debug ... 编译完成后(make),在 nginx.conf 配置文件中设置nginx的日志等级为 d

EnVon的专栏 2297

docker nginx zip_Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务

1. 背景不知不觉笔者来到流媒体部门已经一年半多了,积攒了不少的流媒体知识,但平时工作也比较忙,很少进行总结性的梳理,最近准备花几个周末时间写一个流媒体系列的实践文章,也算是给自己做总结的同时帮助有需要的开发者;在这一节中我们主要是通过nginx+rtmp模块搭建一个点播服务,就是你有很多视频文件,想让其他人观看就可以参考这篇文章,和笔者之前的一篇文章 使用PHP结合Ffmpeg快速搭建流媒体服务...

weixin_39822629的博客 499

流媒体RTMP——librtmp测试

文章目录一:LibRTMP测试二:时间控制三:FFMPEG从MP4文件解析出H264四:LibRTMP的使用4.1 发送Metadata4.2 发送视频4.2.1 发送视频信息包4.2.2 发送视频数据包4.3 发送音频4.3.1 发送音频信息包4.3.2 发送音频数据包 作者:一步(Reser) 日期:2019.10.9 一:LibRTMP测试 测试使用 FFMPEG 从MP4文件中解...

一步的专栏 4596

分布式直播系统(二)【搭建单点rtmp\http-flv\hls流媒体服务器】

使用nginx-rtmp-module搭建http-flv、rtmp、hls、http-ts、hls+(内存切片或虚拟切片)直播服务器

impingo的博客 1万+

RTSP/RTMP/HTTP/HLS协议视频流媒体播放器EasyPlayer-RTSP安卓版本,切换视频黑屏怎么办?

EasyPlayer视频流媒体播放器支持RTSP、RTMP、HTTP、HLS、UDP、RTP、File等多种流媒体协议播放、支持本地文件播放,支持本地抓拍、本地录像、播放旋转、多屏播放、倍数播放等多种功能特性。使用了TSINGSEE青犀视频产品的小伙伴都知道,EasyNVR、EasyDSS内都集成了EasyPlayer.JS版本。 当然了,EasyPlayer-RTSP、EasyPlayer-RTMP也经受了众多用户的使用考验,表现出了强大的播放和调用性能。 我们比较细心的测试专员在对EasyPla

TSINGSEE青犀视频官方技术博客 879

Nginx RTMP源码分析--ngx_rtmp_control_module

ngx_rtmp_control_module RTMP控制模块主要包括录制指令、关闭指令、重定向指令三个控制命令。和其他RTMP有所不同的地方是:RTMP控制模块是注册在HTTP模块下的,它是通过在HTTP配置域下进行控制配置,并通过HTTP Get请求来实现外部对RTMP服务的控制功能。 源码分析 注册HTTP回调 static char * ngx_rtmp_control(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_c

xiaofeilong89的专栏 952

nginx-rtmp】01、控制模块(Control module)

控制模块(Control module) 控制模块是http模块,可在外部通过http对rtmp模块进行控制,下面是启用控制模块的示例: http { ...     server {         listen      8080;         server_name  localhost;         ....         location /

EnVon的专栏 3376

基于obs的rtmp源码分析之RTMP_Connect(rtmp连接)

最近在研究OBS源码,里面有一个很重要的模块是模块,OBS是使用RTMP进行的,源码里面也有RTMP的源码,翻了一下目前网上没有详细的RTMP源码注释,所以这里基于OBS项目,来详细讲一下RTMP源码包括内核数据结构、公共函数接口功能。关于具体的RTMP协议,网上有很多RTMP协议可以找到这里只做简单介绍,重点是代码的注释分析。接口比较多写的比较细,耐心看哈哈哈。 这里所有的实际测试操作均为向斗鱼上(因为我一直用它看直播哈) RTMP协议是应用层协议,是要靠底层可靠的传输层协议(通常是TCP

一个大龄程序员的博客 1507

直播平台源码搭建教程之音视频学习 () 基于 Nginx 搭建(rtmp、http)直播服务器

直播平台源码搭建教程之音视频学习 () 基于 Nginx 搭建(rtmp、http)直播服务器 直播协议介绍 国内常见公开的直播协议有几个:RTMP、HLS、HDL(HTTP-FLV)、RTP,我们来逐一介绍。 RTMP 它是 Adobe 的专利协议,现在大部分国外的 CDN 已不支持。在国内行度很高。原因有几个方面: 1、开源软件和开源库的支持稳定完整。如斗鱼主播常用的 OBS 软件,开源的 librtmp 库,服务端有 nginx-rtmp 插件。 2、播放端安装率高。只要浏览器支持 F

云豹直播源码 1499

【python】自动化ffmpegrtmp + 进程停止

解决ffmpeg命令可实现自动化,一般在执行之后,由于python的自上而下执行,后续代码逻辑无法执行问题

darlingmz的博客 4236

Nginx控制record开始或停止

Nginx record录制配置 rtmp_control all: 开启所有控制接口。 record: 只开启录像控制接口。 drop: 只开启关闭连接控制接口。 redirect:只开启重定向控制接口。 pause: 只开启暂停接口。 resume:只开启恢复接口。 rtmp { server { application camera { live on; recorder all { record all manual; //不自动启动录制,使用控制接口

佳佳鸽的博客 957

Docker中使用nginx-rtmp拉网络摄像头视频

通过配置nginx文件,在docker中搭建流媒体服务器拉网络摄像头视频

今天好像忘写了 2081

nginx搭建RTMP服务

本文介绍了搭建基于NginxRTMP流媒体服务器的完整程。首先需要准备Nginx、FFmpeg和nginx-rtmp-module插件,然后配置Nginx支持RTMP直播和HLS切片功能,设置服务端口、视频存储路径等参数。接着通过FFmpeg命令实现视频,包括RTSP转换和本地视频循环。最后创建HTML页面使用video.js播放器展示直播,并提供统计页面查看状态。整个方案实现了从视频采集、到播放的完整程,支持HLS协议和实时监控功能。

yiqiu_0130的专栏 701

windows下nginx配置rtmp模块

使用的是windows下的nginx 1.7.11.3 Gryphon版本,进行windows下nginx配置rtmp模块。

学以致用 知行合一 3887

基于ffmpeg+nginx+UscreenCapture的局域网直播系统搭建

本文的创作灵感是由Windows screen recording with FFmpeg UScreenCapture and NGINX RTMP module而来,笔者建议大家可以先去原文看一下大致的内容,但需要一定的英文阅读能力,本文并不是照搬翻译,而是根据原文成功搭建直播系统的基础上增加了服务器录制和本地录制的内容: 系统环境:...

weixin_34204722的博客 368

Nginx+Nginx-rtmp-module做在线直播服务器及在线录播

nginx配置 worker_processes 1; error_log logs/error.log debug; events { worker_connections 1024; } rtmp { server { listen 1935; application hls { live on; #启

StoneNotes的专栏 2119
上一篇: H264编码入门(二)I 帧和 IDR 帧的区别
下一篇: 分布式直播系统(十)【一条配置搞定流量计费】
im-pingo
博客等级 码龄7年 304粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值