网站首页 > 博客文章 正文
安装ffmpeg
安装过程略
安装完成后,检查是否安装成功。比如我这里采用向pili推流的方式,将本地的一个mp4视频推流到七牛pili。
ffmpeg -re -i /tmp/ffmpeg_test.mp4 -vcodec copy -acodec copy -f flv "rtmp://pili-publish.qingkang.echohu.top/qingkang/stream1?key=***"
安装nginx
安装过程略
需要注意的是:一定要添加nginx-rtmp-module模块
git clone https://github.com/arut/nginx-rtmp-module.git
#编译的时候添加nginx-rtmp-module模块
--add-module=path_of_/nginx-rtmp-module
我的nginx编译参数
./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/opt/software/pcre-8.35 --with-zlib=/opt/software/zlib-1.2.8 --with-openssl=/opt/software/openssl-1.0.1i --add-module=/opt/software/nginx-1.8.1/modules/nginx-rtmp-module
修改nginx配置文件nginx.conf
加入rtmp配置
#切换自动推送(多 worker 直播流)模式。默认为 off
rtmp_auto_push on;
#当 worker 被干掉时设置自动推送连接超时时间。默认为 100 毫秒
rtmp_auto_push_reconnect 1s;
rtmp {
server {
listen 1935;
#直播流配置
application myapp {
live on;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
}
application qiniu {
live on;
push 推流地址;
}
application pull {
live on;
pull 拉流地址;
}
#rtmp日志设置
access_log logs/rtmp_access.log ;
}
}
在http中增加一个location配置支持hls
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
完整的nginx.conf如下
#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
#切换自动推送(多 worker 直播流)模式。默认为 off
rtmp_auto_push on;
#当 worker 被干掉时设置自动推送连接超时时间。默认为 100 毫秒
rtmp_auto_push_reconnect 1s;
rtmp {
server {
listen 1935;
#直播流配置
application myapp {
live on;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
}
application qiniu {
live on;
push 推流地址;
}
application pull {
live on;
pull 拉流地址;
}
#rtmp日志设置
access_log logs/rtmp_access.log ;
}
}
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;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root /opt/www/html;
index index.html index.htm;
}
#rtmp状态页面
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /opt/software/nginx-rtmp-module/;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
#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;
}
}
include vhosts/*.conf;
}
这是一个最简单,最基础的配置, rtmp监听1935端口,如果是hls的话用hls on开启hls,并且为hls设置一个临时文件目录hls_path /tmp/hls; 其它更高级的配置可以参看nginx-rtmp-module的readme,里面有比较详细的介绍其它的配置,并且它还提供了一个通过JWPlayer在网页上播放的例子.
重启nginx
nginx -t
nginx -s reload
查看nginx已经监听1935端口
使用ffmpeg推流到nginx
推一个本地的mp4到上面配置的myapp上:
ffmpeg -re -i /tmp/ffmpeg_test.mp4 -vcodec copy -acodec copy -f flv "rtmp://127.0.0.1:1935/myapp/test1"
流播放地址为(10.0.0.6是我本地的IP):rtmp://10.0.0.6:1935/myapp/test1
推一个本地的mp4到hls上
ffmpeg -re -i /tmp/ffmpeg_test.mp4 -vcodec copy -acodec copy -f flv "rtmp://127.0.0.1:1935/hls/test2"
流播放地址为: http://10.0.0.6/hls/test2.m3u8
流媒体播放器:
VLC播放hls流:
需要C/C++ Linux服务器开发学习资料私信“资料”(资料包括C/C++,Linux,golang技术,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,ZK,流媒体,CDN,P2P,K8S,Docker,TCP/IP,协程,DPDK,ffmpeg等),免费分享
猜你喜欢
- 2024-12-19 nginx配置tcp代理
- 2024-12-19 Prometheus快速监控Nginx
- 2024-12-19 Nginx搭建RTMP推拉流服务器
- 2024-12-19 nginx入门——nginx访问日志(六)
- 2024-12-19 nginx配置http和tcp服务负载均衡
- 2024-12-19 解决php因为输出内容太短无法流式(Stream)输出问题
- 2024-12-19 利用Nginx正向代理实现局域网电脑访问外网
- 2024-12-19 使用 Nginx 实现推流搭建自己的流媒体服务器
- 2024-12-19 Nginx模块开发:从源码剖析整个Nginx框架
- 2024-12-19 Linux运维面试nginx都问哪些问题呢?
你 发表评论:
欢迎- 最近发表
-
- 给3D Slicer添加Python第三方插件库
- Python自动化——pytest常用插件详解
- Pycharm下安装MicroPython Tools插件(ESP32开发板)
- IntelliJ IDEA 2025.1.3 发布(idea 2020)
- IDEA+Continue插件+DeepSeek:开发者效率飙升的「三体组合」!
- Cursor:提升Python开发效率的必备IDE及插件安装指南
- 日本旅行时想借厕所、买香烟怎么办?便利商店里能解决大问题!
- 11天!日本史上最长黄金周来了!旅游万金句总结!
- 北川景子&DAIGO缘定1.11 召开记者会宣布结婚
- PIKO‘PPAP’ 洗脑歌登上美国告示牌
- 标签列表
-
- ifneq (61)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)