美文网首页
搭建dash直播, ffmpeg开启dash demutex

搭建dash直播, ffmpeg开启dash demutex

作者: 狼爽过羊 | 来源:发表于2018-07-28 21:59 被阅读917次

    搭建dash直播

    搭建dash直播和hls直播差不多, 都是用nginxnginx-rtmp-module, 下面提供路径.

    编译安装

    nginx有一些依赖, 所以configure之前需要先确认下这些依赖是否已经安装

    // openssl
    sudo apt-get install openssl
    sudo apt-get libssl-dev
    
    // prce
    sudo apt-get install libpcre3 
    sudo apt-get install libpcre3-dev
    // zlib
    sudo apt-get install zlib1g-dev
    

    开始编译

    ./configure --prefix=安装路径 ----add-module=rtmp模块路径
    make 
    make install
    

    修改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;
    
    
    events {
        worker_connections  1024;
    }
    
    rtmp {
        server {
            listen 1935;
            chunk_size 4096;
            
            application dash {
                live on;
                dash on;
                dash_path /home/movie/rtmp/dash;
            }
        }
    }
    
    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;
    
            location /stat {
                rtmp_stat all;
                rtmp_stat_stylesheet stat.xsl;
            }
    
            location /stat.xsl {
                root /home/project/nginx-rtmp-module/;
            }
    
           location /dash {
                # Serve DASH fragments
                root /home/movie/rtmp/;
                add_header Cache-Control no-cache;
            }
    
            #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;
            #}
        }
    
    
        # 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;
        #    }
        #}
    
    }
    

    启动测试

    找一个推流工具, 我用的是ffmpeg直接读取mp4文件推流给nginx

    ./ffmpeg -re -i 视频文件路径 -vcodec copy -acodec copy -f flv rtmp://localhost/dash/test
    

    可以在浏览器通过http://localhost/stat查看是否有推流

    截图_2018-07-28_21-30-25.png
    然后我们找一个支持dash的播放器测试下能不能播放, VLC(3.0.2版本)是支持dash的.
    截图_2018-07-28_21-36-01.png 截图_2018-07-28_21-36-15.png

    注意请求路径, 如果请求不到,报404, 可能通过查看nginx安装目录下的log文件去定位错误

    到这里, dash直播就搭建完了, 下面记录一下如何ffmpeg支持dash协议

    ffmpeg开启dash demutex

    ffmpeg是从3.4.2版本开始支持dash的, 老版本不行.

    安装依赖

    ffmpeg是通过libxml2去解析mpd文件的, 所以在configure之前需要先安装libxml2

    sudo apt-get install libxml2 
    sudo apt-get install libxml2-dev
    

    安装之后, 在configure的时候, 加上--enable-libxml2,在configure完成之后,查看config.h文件, 检查CONFIG_DASH_DEMUXER宏是否为1.
    然后make & make install.
    最后用编译完成的ffplay测试下上面搭建的dash直播

    截图_2018-07-28_21-59-02.png

    相关文章

      网友评论

          本文标题:搭建dash直播, ffmpeg开启dash demutex

          本文链接:https://www.haomeiwen.com/subject/fmcamftx.html