• Nginx + Rtmp 实现rtmp和HLS直播流,同时实现时移(分段录制回放)功能


    #!/bin/sh
    
    if [ $(id -u) != "0" ]; then
        echo "Error: Please use root role to install!"
        exit 1
    fi
    
    clear
    echo "========================================"
    echo ""
    echo "========================================"
    echo "======= nginx_rtmp one key sctipt ======"
    echo "========================================"
    echo ""
    echo "========================================"
    
    get_char()
    {
    SAVEDSTTY=`stty -g`
    stty -echo
    stty cbreak
    dd if=/dev/tty bs=1 count=1 2> /dev/null
    stty -raw
    stty echo
    stty $SAVEDSTTY
    }
    echo ""
    #echo "Press any key to start...or Press Ctrl+c to cancel"
    #char=`get_char`
    
    echo "========================================"
    echo "Start install nginx_rtmp ..."
    echo "========================================"
    yum -y install gcc gcc-c++ autoconf automake
    yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
    
    cur_dir=$(pwd)
    
    cd nginx-1.8.0
    
    echo "========================================"
    echo "configure start ..."
    echo "========================================"
    
     ./configure 
    --prefix=/usr/local/nginx 
    --sbin-path=/usr/local/nginx/nginx 
    --conf-path=/usr/local/nginx/nginx.conf 
    --pid-path=/usr/local/nginx/nginx.pid 
    --error-log-path=/usr/local/nginx/logs/error.log 
    --add-module=../nginx-rtmp-module 
    --with-http_mp4_module
    
    echo "========================================"
    echo "make &install"
    echo "========================================"
    
    make
    make install
    
    echo "========================================"
    echo "Setting start"
    echo "========================================"
    
    cd $cur_dir
    cp nginx.conf /usr/local/nginx/
    cp nginx-rtmp-module/stat.xsl /usr/local/nginx/html/
    cp nginx /etc/rc.d/init.d/
    chmod +x /etc/rc.d/init.d/nginx
    chkconfig --add nginx
    chkconfig nginx on
    service nginx start
    echo "Service Test:"
    echo "service nginx status"
    echo "Result:"
    service nginx status
    
    #cat > /etc/fstab <<EOF
    #tmpfs /usr/local/nginx/html/app tmpfs defaults,size=512M 0 0
    #EOF
    #mount -a
    #echo "tmpfs Test:"
    #df -h
    mount -t tmpfs -o size=512m tmpfs /usr/local/nginx/html/app
    echo "mount -t tmpfs -o size=512m tmpfs /usr/local/nginx/html/app" >> /etc/rc.d/rc.local
    
    
    echo "========================================"
    echo "Firewall config"
    echo "========================================"
    
    iptables -I INPUT -p tcp --dport 6080 -j ACCEPT
    iptables -I INPUT -p tcp --dport 5080 -j ACCEPT
    iptables -I INPUT -p tcp --dport 1935 -j ACCEPT
    service iptables save
    
    echo "========================================"
    echo "Install end."
    echo "========================================"
    

      nginx.conf

    #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;
    worker_rlimit_nofile 51200;
    
    events {
        use epoll;
        worker_connections  1024;
    }
    
    rtmp_auto_push on;
    
    rtmp_auto_push_reconnect 1s;
    
    rtmp {
        server {
    		listen 1935;
    		chunk_size 4096;
    		application live {
    			live on;
    			max_connections 1024;
    		}
    		application hls {
    			live on;
    			hls on;
    			hls_path /usr/local/nginx/html/app;
    			hls_fragment 3s;
    			hls_playlist_length 30s;
    			hls_sync 100ms;			
    			meta copy;
    			recorder chunked {
    				record all;
    				#record_max_size 6200K;
    				record_interval 10s;
    				record_suffix -%Y-%m-%d-%H_%M_%S.flv;
    				record_path /data/www/Upload/Rec/Chunked;
    			}
    			recorder all {
    	                        record all;
    	                        record_suffix -%Y-%m-%d-%H_%M_%S.flv;
    				record_max_size 6200000K;
    	                        record_path /data/www/Upload/Rec;
    			}
    		}
    		application Upload {
    			play /data/www/Upload;
    		}
        }
    }
    
    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       5080;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    
            #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;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
            location /hls {
    			types {
    				#application/vnd.apple.mpegurl m3u8;
    				application/x-mpegurl m3u8;
    				video/mp2t ts;
    			}
    			alias /usr/local/nginx/html/app;
    		}
            location /stat {
                rtmp_stat all;
                rtmp_stat_stylesheet stat.xsl;
            }
            location /stat.xsl {
                root html;
            }
        }
    
    server {
            listen       6080;
            server_name  localhost;
    
            location / {
                root   /data/www/AVA.ResourcesPlatform.AdminUI;
                index  index.html index.htm;
    
    	    mp4;
    	    mp4_buffer_size       1m;
    	    mp4_max_buffer_size   5m;
    	    #mp4_limit_rate        on;
    	    #mp4_limit_rate_after  30s;
    	    limit_rate 1m; # about 2mbit
    	    limit_rate_after 5m;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    	#location ~ .mp4$ {
    	#}
        }
    
    
        # 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;
        #    }
        #}
    
    }
    

      

    Blog都是随笔,只当做笔记,不会有详细介绍,测试请慎重。。。
  • 相关阅读:
    strpos 判断字符串是否存在
    TP 自动验证
    label 标签的用法,点label选中单选、复选框或文本框
    str_replace 替换 小技巧
    数据库文件MDF的空间占满了,没有自动增长是怎么回事?
    (4.7)mysql备份还原——深入解析二进制日志(3)binlog的三种日志记录模式详解
    (4.6)mysql备份还原——深入解析二进制日志(2)binlog参数配置解析
    (1.16)mysql server优化之buffer pool
    COALESCE函数
    linux网络设置和虚拟机克隆转移之后网卡找不到
  • 原文地址:https://www.cnblogs.com/JerryBaxia/p/4776299.html
Copyright © 2020-2023  润新知