环境:

centos7.4 64位

下载nginx和rtmp-module:

cd /home/yourname

wget http://nginx.org/download/nginx-1.15.8.tar.gz

tar xvf nginx-1.15.8.tar.gz

wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

unzip master.zip

安装依赖:

yum install openssl-devel

编译:

cd nginx-1.15.8

./configure --add-module=../nginx-rtmp-module-master --prefix=/opt/nginx-install

make

make install

启动:

cd /opt/nginx-install/

vim conf/nginx.conf

修改一下端口

增加rtmp配置,参考https://github.com/arut/nginx-rtmp-module的文档,这个配置文件里有http 的配置,如果在nginx.conf上修改的花,可以只加上rtmp的配置。

rtmp {server {listen 1935;chunk_size 4000;# TV mode: one publisher, many subscribersapplication mytv {# enable live streaminglive on;# record first 1K of streamrecord all;record_path /tmp/av;record_max_size 1K;# append current timestamp to each flvrecord_unique on;# publish only from localhostallow publish 127.0.0.1;deny publish all;#allow play all;}# Transcoding (ffmpeg needed)application big {live on;# On every pusblished stream run this command (ffmpeg)# with substitutions: $app/${app}, $name/${name} for application & stream name.## This ffmpeg call receives stream from this application &# reduces the resolution down to 32x32. The stream is the published to# 'small' application (see below) under the same name.## ffmpeg can do anything with the stream like video/audio# transcoding, resizing, altering container/codec params etc## Multiple exec lines can be specified.exec ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec flv -acodec copy -s 32x32-f flv rtmp://localhost:1935/small/${name};}application small {live on;# Video with reduced resolution comes here from ffmpeg}application webcam {live on;# Stream from local webcamexec_static ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an-f flv rtmp://localhost:1935/webcam/mystream;}application mypush {live on;# Every stream published here# is automatically pushed to# these two machinespush rtmp1.example.com;push rtmp2.example.com:1934;}application mypull {live on;# Pull all streams from remote machine# and play locallypull rtmp://rtmp3.example.com pageUrl=www.example.com/index.html;}application mystaticpull {live on;# Static pull is started at nginx startpull rtmp://rtmp4.example.com pageUrl=www.example.com/index.html name=mystream static;}# video on demandapplication vod {play /var/flvs;}application vod2 {play /var/mp4s;}# Many publishers, many subscribers# no checks, no recordingapplication videochat {live on;# The following notifications receive all# the session variables as well as# particular call arguments in HTTP POST# request# Make HTTP request & use HTTP retcode# to decide whether to allow publishing# from this connection or noton_publish http://localhost:8080/publish;# Same with playingon_play http://localhost:8080/play;# Publish/play end (repeats on disconnect)on_done http://localhost:8080/done;# All above mentioned notifications receive# standard connect() arguments as well as# play/publish ones. If any arguments are sent# with GET-style syntax to play & publish# these are also included.# Example URL:#   rtmp://localhost/myapp/mystream?a=b&c=d# record 10 video keyframes (no audio) every 2 minutesrecord keyframes;record_path /tmp/vc;record_max_frames 10;record_interval 2m;# Async notify about an flv recordedon_record_done http://localhost:8080/record_done;}# HLS# For HLS to work please create a directory in tmpfs (/tmp/hls here)# for the fragments. The directory contents is served via HTTP (see# http{} section in config)## Incoming stream must be in H264/AAC. For iPhones use baseline H264# profile (see ffmpeg example).# This example creates RTMP stream from movie ready for HLS:## ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264#    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1#    -f flv rtmp://localhost:1935/hls/movie## If you need to transcode live stream use 'exec' feature.#application hls {live on;hls on;hls_path /tmp/hls;}# MPEG-DASH is similar to HLSapplication dash {live on;dash on;dash_path /tmp/dash;}}
}# HTTP can be used for accessing RTMP stats
http {server {listen      8080;# This URL provides RTMP statistics in XMLlocation /stat {rtmp_stat all;# Use this stylesheet to view XML as web page# in browserrtmp_stat_stylesheet stat.xsl;}location /stat.xsl {# XML stylesheet to view RTMP stats.# Copy stat.xsl wherever you want# and put the full directory path hereroot /path/to/stat.xsl/;}location /hls {# Serve HLS fragmentstypes {application/vnd.apple.mpegurl m3u8;video/mp2t ts;}root /tmp;add_header Cache-Control no-cache;}location /dash {# Serve DASH fragmentsroot /tmp;add_header Cache-Control no-cache;}}
}

./sbin/nginx -c conf/nginx.conf

推流命令:

ffmpeg -y -i "url" -acodec copy -b:a 64k -vcodec libx264 -b:v 1024k -bsf:a aac_adtstoasc -f flv rtmp://ip:1937/mypush/gaoliwen

播放命令:

ffplay rtmp://ip:1937/mypush/gaoliwen

nginx rtmp 服务搭建相关推荐

  1. Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务

    1. 背景 不知不觉来到流媒体部门已经一年半多了,也算积攒了不少的流媒体知识,平时工作比较忙,到没有对流媒体技术进行系统性的梳理:最近刚完成一个Git实用指南的技术专栏,放松一周之后,觉得还是得让自己 ...

  2. Nginx+rtmp+ffmpeg搭建视频转码服务

    第一步,安装nginx-rtmp-module 模块 因为nginx搭建流媒体服务需要用到 nginx-rtmp-module 模块,所以先安装nginx-rtmp-module # cd /root ...

  3. nginx+rtmp+OBS搭建音视频直播服务

    文章目录 OBS Nginx-rtmp docker方式 野生方式 推流 hls单码流 rtmp多码流 拉流 OBS 下载地址: http://www.obsproject.com.cn/downlo ...

  4. python搭建流媒体服务器_Linux自建直播服务器一:使用Nginx+rtmp模块搭建流媒体服务器...

    技术服务于生活.当在日常遇到问题的时候,需要经常去思考如何解决这个问题. 最近网易的逆水寒开测了,非常荣幸拿到一个资格号,可以来体验一下这款国产巅峰级网游,一个会呼吸的江湖.作为一个极度业余的主播(一 ...

  5. nginx rtmp 服务建立 全套代码,含直播、播放、录制、转码

    有关nginx和rtmp编译这里就不介绍,本文仅记录有关rtmp模块的有关配置 配置环境在Centos下 服务配置 在nginx.conf中插入 rtmp {server {listen 1935;# ...

  6. 服务器搭建和使用 ubuntu_Ubuntu中使用Nginx+rtmp搭建流媒体直播服务

    一.背景 本篇文章是继上一篇文章<Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务>文章而写,在上一篇文章中我们搭建了一个点播服务器,在此基础上我们再搭建一个直播服务器, ...

  7. nginx RTMP FFmpeg 视频直播

    /***************************************************************************** nginx RTMP FFmpeg 视频直 ...

  8. linux搭建直播步骤,Linux 下 nginx + rtmp 搭建直播服务

    简单粗暴直接上步骤吧: 注 : 以下示例使用的是nginx(版本1.15.3) rtmp(版本1.2.1) 下载nginx和rtmp模块 下载nginx 解压 ​ tar xvf nginx-1.15 ...

  9. 使用nginx结合nginx-rtmp-module搭建rtmp流媒体服务器

    环境:centos7.nginx 1.15.2.nginx-rtmp-module(nginx模块).win7主机,vmvare虚拟机(已安装号centos7系统) 安装前提:centos已安装Ope ...

最新文章

  1. Android p2p service,android – WifiP2pDnsSdServiceInfo.newInstance中的可用服务类型
  2. 计算机视觉与深度学习 | 基于Matlab提取SIFT特征点(源代码)
  3. java条件触发,条件事件触发Anylogic
  4. 内存泄露严重吗_内存泄漏–测量频率和严重性
  5. Linux cat命令:连接文件并打印输出到标准输出设备
  6. HDU 4893 Wow! Such Sequence!(2014年多校联合 第三场 G)(线段树)
  7. java泛型中?和T有什么区别
  8. [BZOJ5286][HNOI2018]转盘(线段树)
  9. 异步FIFO中空满信号如何产生?
  10. Laravel-事件简单使用
  11. TSS ESS RSS
  12. mysql根据外键多条件查询_MySQL练习-主外键多表查询
  13. 如何在Byte[]和String之间进行转换
  14. 用 new 还是用 alloc/init
  15. HDU6072 Logical Chain
  16. MySQL 数据库性能优化之缓存参数优化
  17. 串口液晶屏和并口液晶屏的区别
  18. AppleAlc 工具 dump-coeff的使用方法
  19. u盘插在电脑上灯亮没有反应_U盘插入电脑指示灯一直闪烁却不显示的解决方法...
  20. GD32F10x的窗口看门狗定时器

热门文章

  1. 向左转移测试需要团队的努力
  2. 一份开源领域知识的学习清单
  3. 【汇正财经】什么是复盘?
  4. 电脑很流畅,但是一登qq就特别卡
  5. Python函数之迭代器
  6. HCIP实验3-1:IBGP与EBGP
  7. vue3.0修改浏览器title
  8. 百度网盘登录电脑管理
  9. 处理python问题之append
  10. PTA测试 彩虹瓶问题