当前位置:   article > 正文

nginx+nginx-rtmp-module+ffmpeg进行局域网推流rtmp\m3u8_ubuntu nginx实现推流

ubuntu nginx实现推流

局域网推流的简单方式

这里以ubuntu为例

一、先下载安装包 nginx、nginx-rtmp-module,再一起安装

  1. # 下载nginx
  2. # 这里我安装的是 nginx-1.10.3 版本
  3. cd /usr/software
  4. wget http://nginx.org/download/nginx-1.25.0.tar.gz
  5. tar -zxvf nginx-1.25.0.tar.gz
  6. # 下载nginx-rtmp-module
  7. cd /usr/software
  8. git clone https://github.com/arut/nginx-rtmp-module.git
  9. tar -zxvf nginx-rtmp-module
  10. 可能github下载不了,网络问题,下载这个
  11. git clone https://gitee.com/ISSiZheng/nginx-rtmp-module.git
  12. #编译
  13. 进入nginx目录:
  14. cd /usr/software/nginx-1.25.0
  15. ./configure --add-module=/usr/nginx-rtmp-module/nginx-rtmp-module
  16. ./configure --add-module=/usr/software/nginx-rtmp-module-master --with-http_ssl_module
  17. 安装
  18. make && make install
  19. 安装问题时,选装
  20. # yum 安装 openssl
  21. yum -y install openssl openssl-devel
  22. # yum 安装 gcc环境
  23. yum -y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64

装好后,会生成/usr/local/nginx/目录

修改nginx配置文件  conf/nging.conf

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile off;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. server {
  23. listen 80;
  24. server_name localhost;
  25. #charset koi8-r;
  26. #access_log logs/host.access.log main;
  27. location / {
  28. root html;
  29. index index.html index.htm;
  30. }
  31. #error_page 404 /404.html;
  32. # redirect server error pages to the static page /50x.html
  33. #
  34. error_page 500 502 503 504 /50x.html;
  35. location = /50x.html {
  36. root html;
  37. }
  38. # http播放地址,新增的配置
  39. location /hls {
  40. types {
  41. application/vnd.apple.mpegurl m3u8;
  42. video/mp2t ts;
  43. }
  44. #访问权限开启,否则访问这个地址会报403
  45. autoindex on;
  46. root /usr/share/nginx/html;#视频流存放地址,与下面的hls_path相对应,这里root和alias的区别可自行百度
  47. expires -1;
  48. add_header Cache-Control no-cache;
  49. #防止跨域问题
  50. add_header 'Access-Control-Allow-Origin' '*';
  51. add_header 'Access-Control-Allow-Credentials' 'true';
  52. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  53. add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  54. }
  55. }
  56. }
  57. #新增的配置
  58. rtmp {
  59. server {
  60. listen 1935;
  61. chunk_size 4000;
  62. application vod {
  63. play /usr/share/nginx/html/vod/flvs/;#点播媒体存放目录
  64. }
  65. application live {
  66. live on;
  67. }
  68. application hls {
  69. live on;
  70. hls on;
  71. hls_path /usr/share/nginx/html/hls;#视频流存放地址
  72. hls_fragment 5;
  73. hls_playlist_length 30s;
  74. hls_continuous on; #连续模式。
  75. hls_cleanup on; #对多余的切片进行删除。
  76. hls_nested on; #嵌套模式。
  77. hls_fragment_naming system;
  78. hls_fragment_slicing aligned;
  79. }
  80. }
  81. }

 运行nginx

/usr/local/nginx/sbin/nginx

测试时用到,查看进程

ps axu

删除进程

kill xxx

二、安装ffmpeg

sudo apt-get install ffmpeg

三、推流

 ffmpeg -re -i "rtsp://admin:admin123@192.168.197.9/cam/realmonitor?channel=1&subtype=1" -vcodec libx264 -acodec aac -s 368x208 -r 10 -f flv  "rtmp://127.0.0.1:1935/hls/aabbcc"

查看播放结果

rtmp://10.8.0.12:1935/hls/aabbcc

http://10.8.0.12/hls/aabbcc/index.m3u8

参考文档

https://blog.csdn.net/zengliguang/article/details/129584090

nginx-rtmp-module: nginx-rtmp-module

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码架构师/article/detail/60083
推荐阅读
相关标签
  

闽ICP备14008679号