ffmpeg 音视频的抽取,剪辑,(WebRTC)
ffplay
flashplayer (播放RTMP流)
搭建流媒体服务
准备流媒体服务器Linux或Mac
编译并安装Nginx服务
配置RTMP服务并启动 Nginx 服务
Mac 上 安装 nginx rtmp 流媒体服务
Nginx介绍
Nginx是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。
1.安装nginx
执行安装
brew install nginx-full --with-rtmp-module
2.修改配置文件
查看一下nginx安装在什么地方
brew info nginx-full
nginx配置文件所在位置
/usr/local/etc/nginx/nginx.conf
3.运行nginx
nginx
浏览器地址栏输入:http://localhost:8080
4.配置rtmp
vi /usr/local/etc/nginx/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;
}
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 8080;
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;
#}
}
# 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;
# }
#}
include servers/*;
}
我们需要在 在http节点后面加上rtmp配置
rtmp {
server {
listen 1935;
#直播流配置
application rtmplive {
live on;
#为 rtmp 引擎设置最大连接数。默认为 off
max_connections 1024;
}
application hls{
live on;
hls on;
hls_path /usr/local/var/www/hls;
hls_fragment 1s;
}
}
}
编辑完成之后,执行一下重新加载配置文件命令:
nginx -s reload
重启nginx
sudo /usr/local/opt/nginx-full/bin/nginx -s reload
安装ffmepg工具
1.安装ffmpeg
brew install ffmpeg
2.安装一个支持rtmp协议的视频播放器,Mac下可以用VLC
本地下载一个视频文件路径为
/Users/xx/Desktop/story.mp4
3.执行推流命令
ffmpeg -re -i /Users/xx/Desktop/story.mp4 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1935/rtmplive/room
4.用vlc 然后打开 VLC 中 的 file -- Open Network, 直接输入代码中的 url:
rtmp://localhost:1935/rtmplive/room
然后进行播放.
5.手机推流只需把localhost:8080换成自己电脑的ip地址即可:
rtmp://10.0.0.17:1935/rtmplive/room
https://www.jianshu.com/p/1975dd7ad32a
https://www.jianshu.com/p/a0397c98d907
网友评论