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

来源:互联网 发布:淘宝网店实战宝典txt 编辑:程序博客网 时间:2024/05/21 08:04

nginx配置

worker_processes  1;error_log  logs/error.log debug;events {    worker_connections  1024;}rtmp {    server {        listen 1935;        application hls {             live on;  #启用rtmp直播                       #地址为rtmp://[server]:[rtmp_port]/[app]/[stream]             on_publish http://127.0.0.1/auth_client.php;              hls on;   #启用hls直播                       #地址为http://[server]:[http_port]/[app]/[stream].m3u8                       #需要配合下面http段设置使用             hls_path nginx-rtmp-module/tmp/app/;             hls_fragment 5s;             recorder rec {  #启用录制               record all manual;  #手动控制录制启停               record_suffix _rec.flv;               record_path nginx-rtmp-module/tmp/rec/;  #录制保存地址               record_unique on;           }       }       application vod2{  #rtmp点播               play nginx-rtmp-module/tmp/rec/;           }    }}http {    server {        listen      80;        location /stat {  #服务器状态            rtmp_stat all;            rtmp_stat_stylesheet stat.xsl;        }        location /stat.xsl {            root nginx-rtmp-module/;        }        location /control { #控制器            rtmp_control all;        }            location /hls/ {  #hls直播地址           #server hls fragments           types{             application/vnd.apple.mpegurl m3u8;             video/mp2t ts;           }           alias nginx-rtmp-module/tmp/app/;           expires -1;        }        location /vod/{  #hls点播地址            alias nginx-rtmp-module/tmp/rec/;        }        location / {            root nginx-rtmp-module/test/www/;        }        location ~ \.mp4$ {            mp4;        }        location ~ \.php$ {            root /usr/local/nginx/html;            fastcgi_pass 127.0.0.1:9000;            fastcgi_index index.php;            fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;            include fastcgi_params;        }    }}

测试

开始录制

http://127.0.0.1:18080/control/record/start?app=hls&name=mystream&rec=rec

停止录制

http://127.0.0.1:18080/control/record/stop?app=hls&name=mystream&rec=rec

推流地址:

rmtp://127.0.0.1:1935/hls/yourname

直播地址:

rmtp://127.0.0.1:1935/hls/yournamehttp://127.0.0.1:18080/hls/youname.m3u8

MP4拖动播放

.mp4?start=60.mp4?start=60&end=180

auth_client.php

// ?user=user&pass=pass$user = isset($_GET['user']) ? $_GET['user'] : '';$pass = isset($_GET['pass']) ? $_GET['pass'] : '';if (empty($user) || empty($pass)) {    echo "wrong query input";    header('HTTP/1.0 404 Not Found');    exit();}$saveuser = user;$savepass = pass;if (strcmp($user, $saveuser) == 0 && strcmp($pass, $savepass) == 0) {    echo "Username and Password OK";} else {    echo "Username or Password wrong";    header('HTTP/1.0 404 Not Found');    exit();}

阅读全文
0 0
原创粉丝点击