资讯专栏INFORMATION COLUMN

MacOS安装Nginx+ffmpeg(rtmp直播服务器搭建)

YanceyOfficial / 2645人阅读

摘要:参考来源相关文章视频直播原理一安装安装需要先在应用商店手动安装,再进行以下操作安装过程中会提示需要安装,但最新场景下安装时已经没有了,需要多带带安装。根据提示在使用命令安装时最后结果是不能安装该软件。

参考来源:https://github.com/denji/home...
相关文章:H5视频直播原理

一、安装nginx+rtmp

1.安装Homebrew:
需要先在应用商店手动安装Xcode,再进行以下操作

</>复制代码

  1. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装过程中会提示需要安装xcode command line tool,但Mac最新场景下安装Xcode时已经没有Command Line了,需要多带带安装。根据提示在使用命令xcode-select --install 安装时最后结果是不能安装该软件

解决方式

登录https://developer.apple.com/d... 然后下载 dmg 安装

2.执行命令:

</>复制代码

  1. brew tap denji/nginx

3.执行命令:

</>复制代码

  1. brew install nginx-full --with-rtmp-module

查看nginx安装信息:

</>复制代码

  1. brew info nginx-full

可看到如下信息:

</>复制代码

  1. Docroot is: /usr/local/var/www
  2. The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
  3. nginx can run without sudo.
  4. nginx will load all files in /usr/local/etc/nginx/servers/.
  5. - Tips -
  6. Run port 80:
  7. $ sudo chown root:wheel /usr/local/Cellar/nginx-full/1.15.6/bin/nginx
  8. $ sudo chmod u+s /usr/local/Cellar/nginx-full/1.15.6/bin/nginx
  9. Reload config:
  10. $ nginx -s reload
  11. Reopen Logfile:
  12. $ nginx -s reopen
  13. Stop process:
  14. $ nginx -s stop
  15. Waiting on exit process
  16. $ nginx -s quit

nginx安装位置:

</>复制代码

  1. /usr/local/Cellar/nginx-full/

nginx配置文件位置:

</>复制代码

  1. /usr/local/etc/nginx/nginx.conf

nginx服务器根目录位置:

</>复制代码

  1. /usr/local/var/www

验证是否安装成功,执行命令:

</>复制代码

  1. nginx

然后浏览器中输入http://localhost:8080,出现以下界面,证明安装成功

二、安装ffmpeg

1.安装ffmpeg,执行命令:

</>复制代码

  1. brew install ffmpeg

windows下安装ffmpeg:https://ffmpeg.zeranoe.com/bu...
安装过程需要一段时间。
2.验证是否安装成功,执行命令:

</>复制代码

  1. ffmpeg

显示信息如下:

</>复制代码

  1. ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
  2. built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
  3. configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gpl --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-opencl --enable-videotoolbox
  4. libavutil 56. 22.100 / 56. 22.100
  5. libavcodec 58. 35.100 / 58. 35.100
  6. libavformat 58. 20.100 / 58. 20.100
  7. libavdevice 58. 5.100 / 58. 5.100
  8. libavfilter 7. 40.101 / 7. 40.101
  9. libavresample 4. 0. 0 / 4. 0. 0
  10. libswscale 5. 3.100 / 5. 3.100
  11. libswresample 3. 3.100 / 3. 3.100
  12. libpostproc 55. 3.100 / 55. 3.100
  13. Hyper fast Audio and Video encoder
  14. usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
三、配置nginx

用IDE打开nginx.conf文件,文件路径:

</>复制代码

  1. /usr/local/etc/nginx/

有atom编辑器的话可以执行以下命令打开:

</>复制代码

  1. open nginx.conf -a atom

编辑内容:
1.在http节点后面加上rtmp配置

</>复制代码

  1. http {
  2. ...
  3. }
  4. #在http节点后面加上rtmp配置
  5. rtmp {
  6. server {
  7. # 监听端口
  8. listen 1935;
  9. # 分块大小
  10. chunk_size 4000;
  11. # RTMP 直播流配置
  12. application rtmplive {
  13. # 开启直播的模式
  14. live on;
  15. # 设置最大连接数
  16. max_connections 1024;
  17. }
  18. # hls 直播流配置
  19. application hls {
  20. live on;
  21. hls on;
  22. # 分割文件的存储位置
  23. hls_path /usr/local/var/www/hls;
  24. # hls分片大小
  25. hls_fragment 5s;
  26. }
  27. }
  28. }

2.在http节点内的server节点内增加配置项:

</>复制代码

  1. http {
  2. ...
  3. server {
  4. ...
  5. location / {
  6. root html;
  7. index index.html index.htm;
  8. }
  9. location /hls {
  10. # 响应类型
  11. types {
  12. application/vnd.apple.mpegurl m3u8;
  13. video/mp2t ts;
  14. }
  15. root /usr/local/var/www;
  16. # 不要缓存
  17. add_header Cache-Control no-cache;
  18. }
  19. ...
  20. }
  21. ...
  22. }

到这里为止,安装和配置工作已经完成,然后下一步操作。

四、测试

1.重启nginx服务,执行命令:
先关闭nginx

</>复制代码

  1. nginx -s stop

再打开:

</>复制代码

  1. nginx

或者直接执行reload:

</>复制代码

  1. nginx -s reload

2.推流
准备一个视频文件(如mp4文件)来测试推流,
在视频文件所在目录下执行以下命令模拟rtmp推流:

</>复制代码

  1. ffmpeg -re -i test.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/rtmplive/rtmp

可以安装一个支持rtmp协议的视频播放器,在Mac下可以用VLC播放器,在VLC的“File--Open Network--URL”里输入“rtmp://localhost:1935/rtmplive/rtmp”,然后点击open选项就可以播放
要进行hls推流的话只需要以上命令稍作修改:

</>复制代码

  1. ffmpeg -re -i test.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/hls/stream

其中最后的stream是你自己取的名字,随便写
然后在sarafi浏览器里输入http://localhost:8080/hls/stream.m3u8 就能正常播放直播流了

也可以用VLC播放器输入“rtmp://localhost:1935/hls/stream”播放

第二种方法集成服务

带server的代码https://github.com/HughieSong...,里面有个名为“server”的二进制文件。
输入以下命令启动:

</>复制代码

  1. open server

然后会看到

</>复制代码

  1. SungdeMacBook-Pro:~ admin$ /Users/admin/Downloads/project/github/h5live/server/server ; exit;
  2. 2018/12/08 14:58:37 main.go:106: start livego, version 0.0.4
  3. 2018/12/08 14:58:37 main.go:40: HLS listen On :7002
  4. 2018/12/08 14:58:37 main.go:58: RTMP Listen On :1935
  5. 2018/12/08 14:58:37 main.go:75: HTTP-FLV listen On :7001

这说明服务被启用了,这时候为了避免将来出现问题,我们先运行以下命令停止nginx服务:

</>复制代码

  1. nginx -s stop

重新启动server:

</>复制代码

  1. open server

这时候看到以下内容:

</>复制代码

  1. SungdeMacBook-Pro:~ admin$ /Users/admin/Downloads/project/github/h5live/server/server ; exit;
  2. 2018/12/08 15:22:51 main.go:106: start livego, version 0.0.4
  3. 2018/12/08 15:22:51 main.go:30: listen tcp :7002: bind: address already in use
  4. logout
  5. Saving session...
  6. ...copying shared history...
  7. ...saving history...truncating history files...
  8. ...completed.
  9. Deleting expired sessions...96 completed.
  10. [进程已完成]

然后在h5live目录下执行推流命令:

</>复制代码

  1. ffmpeg -re -i test.mp4 -c copy -f flv rtmp://localhost:1935/live/movie

进程此时就跑起来了,打开VLC播放器-->File-->Open Network-->URL中输入rtmp://localhost:1935/live/movie-->open就可以播放了

或者sarafi浏览器中输入http://127.0.0.1:7002/live/movie.m3u8 或者http://localhost:7002/live/movie.m3u8 来验证

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/53232.html

相关文章

  • MacOS安装Nginx+ffmpegrtmp直播务器搭建

    摘要:参考来源相关文章视频直播原理一安装安装需要先在应用商店手动安装,再进行以下操作安装过程中会提示需要安装,但最新场景下安装时已经没有了,需要单独安装。根据提示在使用命令安装时最后结果是不能安装该软件。 参考来源:https://github.com/denji/home...相关文章:H5视频直播原理 一、安装nginx+rtmp 1.安装Homebrew:需要先在应用商店手动安装Xco...

    DevTTL 评论0 收藏0
  • MacOS安装Nginx+ffmpegrtmp直播务器搭建

    摘要:参考来源相关文章视频直播原理一安装安装需要先在应用商店手动安装,再进行以下操作安装过程中会提示需要安装,但最新场景下安装时已经没有了,需要单独安装。根据提示在使用命令安装时最后结果是不能安装该软件。 参考来源:https://github.com/denji/home...相关文章:H5视频直播原理 一、安装nginx+rtmp 1.安装Homebrew:需要先在应用商店手动安装Xco...

    Bamboy 评论0 收藏0
  • H5视频直播原理

    摘要:相关文章安装直播服务器搭建直播原理目前各主流浏览器支持的视频格式直播协议协议静态列表全量列表表示点播,表示结束协议协议直播原理总结基础认识准备工作环境下命令行操作安装依赖安装启动进入目录下从远程仓库克隆进入仓库文件夹创建用打开属 相关文章:MacOS安装Nginx+ffmpeg(rtmp直播服务器搭建) 直播原理 showImg(https://segmentfault.com/img...

    MudOnTire 评论0 收藏0
  • H5视频直播原理

    摘要:相关文章安装直播服务器搭建直播原理目前各主流浏览器支持的视频格式直播协议协议静态列表全量列表表示点播,表示结束协议协议直播原理总结基础认识准备工作环境下命令行操作安装依赖安装启动进入目录下从远程仓库克隆进入仓库文件夹创建用打开属 相关文章:MacOS安装Nginx+ffmpeg(rtmp直播服务器搭建) 直播原理 showImg(https://segmentfault.com/img...

    leap_frog 评论0 收藏0

发表评论

0条评论

YanceyOfficial

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<