php启动ffmpeg直播,搭建dash直播, ffmpeg开启dash demutex

搭建dash直播

搭建dash直播和hls直播差不多, 都是用nginx和nginx-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查看是否有推流

512cb67e35d1

截图_2018-07-28_21-30-25.png

然后我们找一个支持dash的播放器测试下能不能播放, VLC(3.0.2版本)是支持dash的.

512cb67e35d1

截图_2018-07-28_21-36-01.png

512cb67e35d1

截图_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直播

512cb67e35d1

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值