资讯专栏INFORMATION COLUMN

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

YanceyOfficial / 2452人阅读

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

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

一、安装nginx+rtmp

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

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.执行命令:

brew tap denji/nginx

3.执行命令:

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

查看nginx安装信息:

brew info nginx-full

可看到如下信息:

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

- Tips -
Run port 80:
 $ sudo chown root:wheel /usr/local/Cellar/nginx-full/1.15.6/bin/nginx
 $ sudo chmod u+s /usr/local/Cellar/nginx-full/1.15.6/bin/nginx
Reload config:
 $ nginx -s reload
Reopen Logfile:
 $ nginx -s reopen
Stop process:
 $ nginx -s stop
Waiting on exit process
 $ nginx -s quit

nginx安装位置:

/usr/local/Cellar/nginx-full/

nginx配置文件位置:

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

nginx服务器根目录位置:

/usr/local/var/www

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

nginx

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

二、安装ffmpeg

1.安装ffmpeg,执行命令:

brew install ffmpeg

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

ffmpeg

显示信息如下:

ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
  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
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
三、配置nginx

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

/usr/local/etc/nginx/

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

open nginx.conf -a atom

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

http {
    ...
}
#在http节点后面加上rtmp配置
rtmp {
    server {
      # 监听端口
      listen 1935;
      # 分块大小
      chunk_size 4000;

      # RTMP 直播流配置
      application rtmplive {
        # 开启直播的模式
        live on;
        # 设置最大连接数
        max_connections 1024;
      }

      # hls 直播流配置
      application hls {
        live on;
        hls on;
        # 分割文件的存储位置
        hls_path /usr/local/var/www/hls;
        # hls分片大小
        hls_fragment 5s;
      }
    }
}

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

http {
    ...
    server {
        ...
        location / {
            root   html;
            index  index.html index.htm;
        }

        location /hls {
          # 响应类型
            types {
              application/vnd.apple.mpegurl m3u8;
              video/mp2t ts;
            }
            root /usr/local/var/www;
            # 不要缓存
            add_header Cache-Control no-cache;
        }
        ...
    }
    ...
}

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

四、测试

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

nginx -s stop

再打开:

nginx

或者直接执行reload:

nginx -s reload

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

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推流的话只需要以上命令稍作修改:

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”的二进制文件。
输入以下命令启动:

open server

然后会看到

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

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

nginx -s stop

重新启动server:

open server

这时候看到以下内容:

SungdeMacBook-Pro:~ admin$ /Users/admin/Downloads/project/github/h5live/server/server ; exit;
2018/12/08 15:22:51 main.go:106: start livego, version 0.0.4
2018/12/08 15:22:51 main.go:30: listen tcp :7002: bind: address already in use
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...96 completed.

[进程已完成]

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

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
  • MacOS安装Nginx+ffmpegrtmp直播务器搭建

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

    miguel.jiang 评论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元查看
<