Nginx+rtmp+ffmpeg搭建流媒体服务器

说明:

  nginx搭建流媒体服务需要用到 nginx-rtmp-module 模块

具体操作步骤:

安装nginx

(1)下载第三方扩展模块nginx-rtmp-module

# mkdir module && cd module          //创建一个存放模块的目录
# wget https://github.com/arut/nginx-rtmp-module/archive/master.zip //下载模块
# unzip master.zip         //解压
# ls nginx-rtmp-module-master/ //查看模块目录

(2)编译安装nginx说明:此处由于我这边已有lnmp运行项目的环境,直接动态添加的 nginx-rtmp-module模块; 动态参加可参考这里

# yum -y install pcre-devel openssl openssl-devel        //安装依赖
# wget http://nginx.org/download/nginx-1.12.2.tar.gz //下载nginx包
# tar xf nginx-1.12..tar.gz
# ./configure --prefix=/opt/nginx-1.9. --add-module=/root/module/nginx-rtmp-module-master --with-http_ssl_module //编译安装nginx,并指定上面下载的模块路径
# make
# make install

(3)修改nginx配置文件,添加如下内容并重新载入配置文件

# vim nginx.conf
rtmp {
server {
listen ; #监听的端口号
application myapp { #自定义的名字
live on;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 1s;
hls_playlist_length 3s;
}
}
}
# /etc/init.d/nginx reload
user  root;
worker_processes ;
worker_cpu_affinity ;
worker_rlimit_nofile ; #error_log logs/error.log warn;
pid /var/run/nginx.pid; events {
worker_connections ;
use epoll;
} rtmp {
server {
listen ;
application myapp {
live on;
}
application hls {
live on;
hls on;
hls_path /tmp/rtmp/hls;
hls_fragment 1s;
hls_playlist_length 3s;
}
}
} http { limit_req_zone $binary_remote_addr zone=req_one:10m rate=1r/s; autoindex off;
include /opt/nginx-1.9./conf/mime.types;
default_type application/octet-stream; log_format main '$remote_addr [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for $request_length $request_time "$upstream_response_time" "$upstream_addr" $host $server_addr'; #access_log logs/access.log main;
server_tokens off;
sendfile on;
#tcp_nopush on; keepalive_timeout ; gzip on;
gzip_min_length 1K;
gzip_buffers 16K;
gzip_comp_level ;
gzip_http_version 1.0;
gzip_types application/json text/javascript text/plain application/x-javascript text/css application/xml text/xml;
#gzip_types application/json text/javascript text/plain application/x-javascript text/css application/xml text/xml image/jpeg image/gif image/png;
gzip_disable "MSIE [1-6]\.";
client_max_body_size 500M; #server {
# listen default;
# return ;
#} include /opt/nginx-1.9./conf/conf.d/*.conf; }

完整nginx.conf

安装ffmpeg

ffmpeg命令参考这位朋友的文章:https://www.jianshu.com/p/049d03705a81

(1)安装依赖

# yum install yasm -y

(2)下载ffmpeg并安装

# git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg    //下载ffmpeg
# cd ffmpeg
# ./configure --prefix=/usr/local/ffmpeg
# make
# make install

(3)拷贝命令到/usr/bin(方便后面调用)

# ls /usr/local/ffmpeg/        //查看安装目录生成的文件
bin include lib share
# cp /usr/local/ffmpeg/bin/* /usr/bin/

测试

(1)启用ffmpeg进行推流

# ffmpeg -i rtsp://192.168.1.175:554/11 -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 96k -r 25 -b:v 500k -s 640*480 -f flv rtmp://192.168.1.11:1935/myapp/23
-i 要处理视频文件的路径,此处地址是一个监控摄像头
-s 像素
rtmp://192.168.1.11:1935/myapp/23 说明:rtmp://IP:PORT/ myapp指nginx配置文件中自定义的,22指输出文件的名字
-f 强迫采用flv格式
别的参数参考上面那位老兄的

(2)打开VLC 媒体——>流——>网络

(3)进入服务器查看输出的位置可以发现已生成文件

# ll /tmp/hls/
total
-rw-r--r-- root root Mar : -.ts
-rw-r--r-- root root Mar : -.ts
-rw-r--r-- root root Mar : -.ts
-rw-r--r-- root root Mar : -.ts
-rw-r--r-- root root Mar : .m3u8

(4)还可以使用浏览器这样访问 http://192.168.1.11/hls/22.m3u8

至此就搭建完成了,至于别的操作后续再写

Linux-Nginx+rtmp+ffmpeg搭建流媒体服务器的更多相关文章

  1. centos7+nginx+rtmp+ffmpeg搭建流媒体服务器(保存流目录与http目录不要随意配置,否则有权限问题)

    搭建nginx-http-flv-module升级代替rtmp模块,详情:https://github.com/winshining/nginx-http-flv-module/blob/master ...

  2. (转)Nginx+rtmp+ffmpeg搭建流媒体服务器

    (1)下载第三方扩展模块nginx-rtmp-module # mkdir module && cd module //创建一个存放模块的目录 # wget https://githu ...

  3. centos7+nginx+rtmp+ffmpeg搭建流媒体服务器

    1.安装前需要的工具 #net-tool 查本地IP #wget 下载安装包 #unzip 解压zip包 #gcc gcc-c++ perl 编译软件包用 yum install -y net-too ...

  4. 使用nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器

    参考: 1,使用nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器笔记(一)http://blog.csdn.net/xdwyyan/article/details/4319 ...

  5. nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器

    参照网址: [1]http://blog.csdn.net/redstarofsleep/article/details/45092147 [2]HLS介绍:http://www.cnblogs.co ...

  6. 流媒体技术学习笔记之(一)nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器

    参照网址: [1]http://blog.csdn.net/redstarofsleep/article/details/45092147 [2]HLS介绍:http://www.cnblogs.co ...

  7. nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器[转]

    转 :http://redstarofsleep.iteye.com/blog/2123752 Nginx本身是一个非常出色的HTTP服务器,FFMPEG是非常好的音视频解决方案.这两个东西通过一个n ...

  8. Nginx+rtmp+ffmpeg 搭建推流服务器

    1. 安装nginx服务器 1.1 clone $ brew tap denji/homebrew-nginx 1.2 安装 $ brew install nginx-full --with-rtmp ...

  9. Ubuntu下使用nginx和nginx-rtmp-module搭建流媒体服务器的正确姿势

    之前在使用nginx和nginx-rtmp-module搭建流媒体服务器的时候遇到一个很尴尬的问题,就是在把nginx-rtmp-module模块添加到nginx中去的时候,我最开始采取的做法是先卸载 ...

随机推荐

  1. python3 Flask -day2

    flask 实战第二天,url传参 当我们访问网站/的时候,会执行hell_world函数,并把这个函数的返回值返回给浏览器,这样浏览器就显示hello world了 @app.route('/') ...

  2. js中console使用2

    接着上一篇js中console使用1,本片继续介绍js中console的用法 测试代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 ...

  3. Doctype的作用?严格模式与混合模式,如何触发者这两种模式,区分它们有何意义?

    Doctype作用?严格模式与混合模式,如何触发者这两种模式,区分它们有何意义? 1.1 Doctype作用 <!DOCTYPE>声明叫做文件类型定义(DTD),声明的作用为了告诉浏览器该 ...

  4. 常见的7种XSS

    1. URL Reflection 当URL以某种方式反映在源代码中时,我们可以添加自己的XSS向量/有效负载.对于PHP页面,可以使用斜杠字符(/)在页面名称之后添加任何内容 http://brut ...

  5. arcgis api 3.x for js 入门开发系列十八风向流动图(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...

  6. [Python] wxPython 高防Windows10记事本 (end...)

    1.开始 接触Python 也有一段时间了,o.o ,断断续续加起来没几天. 一般新学习一门新语言,除了必先输出一个 Hello World 外,都会以模拟 Windows 记事本来写一个结合自己想法 ...

  7. MySQL 基础知识梳理学习(六)----锁

    1.什么是锁: 对共享资源进行并发访问控制,提供数据的完整性和一致性. 2.锁的区别: 类型 lock latch 对象 事务 线程 保护 数据库内容 内存数据结构 持续时间 整个事务过程 临界资源 ...

  8. C#多线程和线程池 【转】

    1.概念  1.0 线程的和进程的关系以及优缺点 windows系统是一个多线程的操作系统.一个程序至少有一个进程,一个进程至少有一个线程.进程是线程的容器,一个C#客户端程序开始于一个单独的线程,C ...

  9. 应用wavesurfer.js绘制音频波形图小白极速上手总结

    一.简介 1.1  引   人生中第一份工作公司有语音识别业务,需要做一个web网页来整合语音引擎的标注结果和错误率等参数,并提供人工比对的语音标注功能(功能类似于TranscriberAG等),(博 ...

  10. 工作中遇到的一些linux常用命令总结

    零.查看历史命令,linux中可按“↑” “↓”查找之前输入的命令,亦可用 history 命令查看之前的输入,linux中的亦有“Tab”键可联想输入 一.root权限: 1.su 之后输入root ...