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. Spring Aop底层原理详解

    Spring Aop底层原理详解(来源于csdn:https://blog.csdn.net/baomw)

  2. SpringMVC+Spring+Mybatis整合

    SpringMVC+Spring+Mybatis整合 导包 配置jdbc.properties.log4j.properties jdbc.driver=com.mysql.jdbc.Driver j ...

  3. MySQL 字符集和校对

    字符集是指一种从二进制编码到某类字符符号的映射,校对是一组用于某个字符集的排序规则.每一类编码字符都有其对应的字符集和校对规则 MySQL 如何使用字符集 每种字符集都可能有多种校对规则,并且都有一个 ...

  4. 浅谈C#中的for循环与foreach循环

    for循环和foreach循环其实可以算得上是从属关系的,即foreach循环是可以转化成for循环,但是for循环不一定能转换成foreach循环. 下面简单介绍一下两种循环: 1.for循环 代码 ...

  5. JavaScript 中最​​重要的保留字

    JavaScript 保留了一些关键字,这些关键字在当前的语言版本中并没有使用,但在以后 JavaScript 扩展中会用到. abstract else instanceof super boole ...

  6. CSRF & CORS

    下面转的两篇文章分别说明了以下两个概念和一些解决方法: 1. CSRF - Cross-Site Request Forgery - 跨站请求伪造 2. CORS - Cross Origin Res ...

  7. 20190404-transition、transform转换、animation、媒体查询

    目录 1.transition过渡 1.1简写:transiton:transition-property | transition-duration | transition-timing-func ...

  8. Python Learning: 03

    An inch is worth a pound of gold, an inch of gold is hard to buy an inch of time. Slice When the sca ...

  9. name 'reload' is not defined解决方法

    今天在学习scrapy的时候,在网上找了一段代码,运行出了一点问题. 命令行报错: name 'reload' is not defined 原因是,python版本的问题 原代码如下: import ...

  10. mange

    from flask import Flask app = Flask(__name__) manager = Manager(app) 1. 重写Command class ShellCommand ...