第一部分:

mkdir ~/working

切换到~/working目录下

cd ~/working

获取nginx源码:

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

解压

tar xvf nginx-1.13.4.tar.gz

获取最新的nginx-rtmp源码

git clone https://github.com/arut/nginx-rtmp-module.git

切换到nginx目录

cd nginx-1.13.4

配置

./configure --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx-rtmp-module

编译和安装配置有nginx-rtmp模块的nginx

make

sudo make install

# 注意如果make失败:

  那么就是需要装nginx的依赖包

    # 查看zlib是否安装
    dpkg -l | grep zlib
    # 解决依赖包openssl安装
    sudo apt-get install openssl libssl-dev
    # 解决依赖包pcre安装
    sudo apt-get install libpcre3 libpcre3-dev
    # 解决依赖包zlib安装
    sudo apt-get install zlib1g-dev

安装nginx初始化脚本

获取nginx初始化脚本

wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx

将脚本复制到/etc/init.d/目录下

sudo cp nginx /etc/init.d/

修改权限

sudo chmod +x /etc/init.d/nginx

使用update-rc.d进行启动项管理

sudo update-rc.d nginx defaults

创建目录结构

sudo mkdir /HLS

sudo mkdir /HLS/mobile

sudo mkdir /HLS/live

sudo mkdir /video_recordings

sudo chmod -R 777 /video_recordings

配置nginx

备份原来的nginx配置文件

sudo cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.back

sudo gedit /usr/local/nginx/conf/nginx.conf

往/usr/local/nginx/conf/nginx.conf添加以下内容

worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
allow play all;

#creates our "live" full-resolution HLS videostream from our incoming encoder stream and tells where to put the HLS video manifest and video fragments
application live {
allow play all;
live on;
record all;
record_path /video_recordings;
record_unique on;
hls on;
hls_nested on;
hls_path /HLS/live;
hls_fragment 10s;

#creates the downsampled or "trans-rated" mobile video stream as a 400kbps, 480x360 sized video
exec ffmpeg -i rtmp://192.168.1.104:1935/$app/$name -acodec copy -c:v libx264 -preset veryfast -profile:v baseline -vsync cfr -s 480x360 -b:v 400k -maxrate 400k -bufsize 400k -threads 0 -r 30 -f flv rtmp://192.168.1.104:1935/mobile/$;
}

#creates our "mobile" lower-resolution HLS videostream from the ffmpeg-created stream and tells where to put the HLS video manifest and video fragments
application mobile {
allow play all;
live on;
hls on;
hls_nested on;
hls_path /HLS/mobile;
hls_fragment 10s;
}

#allows you to play your recordings of your live streams using a URL like "rtmp://my-ip:1935/vod/filename.flv"
application vod {
play /video_recordings;
}
}
}

http {
include mime.types;
default_type application/octet-stream;

server {
listen 80;
server_name 192.168.1.104;

#creates the http-location for our full-resolution (desktop) HLS stream - "http://my-ip/live/my-stream-key/index.m3u8"
location /live {
types {
application/vnd.apple.mpegurl m3u8;
}
alias /HLS/live;
add_header Cache-Control no-cache;
}

#creates the http-location for our mobile-device HLS stream - "http://my-ip/mobile/my-stream-key/index.m3u8"
location /mobile {
types {
application/vnd.apple.mpegurl m3u8;
}
alias /HLS/mobile;
add_header Cache-Control no-cache;
}

#allows us to see how stats on viewers on our Nginx site using a URL like: "http://my-ip/stats"
location /stats {
stub_status;
}

}
}

启动nginx服务

sudo service nginx start

安装ffmpeg

sudo apt-get install ffmpeg

一.推流开始       (点播)

1。ffmpeg -re -i 01.mp4 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://192.168.32.137:1935/mobile/ha

/*将本地视频文件test.mp4转码推流到本地服务器*/

或者ffmpeg -re -i 01.mp4 -vcodec libx264 -acodec copy -f flv rtmp://192.168.32.137:1935/mobile/ha

2.在本机端打开vlc播放器

输入流地址rtmp://localhost/mobile/ha即可观看视频,不过本地播放有些卡顿,网络播放更卡

二  直播

1.将视频放到  /video_recordings 目录

使用VLC访问     vod是rtmp的application ,点播就可以了

  rtmp://192.168.32.137:1935/vod/2.flv

流媒体服务器搭建 ffmpeg + nginx的更多相关文章

  1. SRS流媒体服务器搭建+ffmpeg推流VLC取流观看

    一.编译SRS https://github.com/winlinvip/simple-rtmp-server 目前有1.0-release.2.0.3.0等版本 2.0官方文档地址:https:// ...

  2. rtmp与hls流媒体服务器搭建:ubuntu下Nginx搭建初探与rtmp-module的添加

    关键词:Nignx(http服务器):rtmp,hls(流媒体服务) 前言:感谢开源,感谢战斗民族.现在在做流媒体服务的一些工作,流媒体服务器搭建的网上教程多入牛毛,但是细细查看,发现很多同志贴上来的 ...

  3. nginx-rtmp流媒体服务器搭建【转】

    nginx-rtmp https://github.com/pengqiuyuan/nginx-rtmp nginx-rtmp 流媒体服务器的搭建(采集桌面,手机直播) 在线Demo,直播自己的pc机 ...

  4. Android视频直播:流媒体服务器搭建

    一.前言 实时视频直播是这两年非常火的技术形态,已经渗透到教育.在线互娱等各种业务场景中.但要搭建一套实时视频直播系统,并非易事,下面针对直播系统的的搭建做一下说明: 1.1 通常的直播系统的技术模型 ...

  5. 流媒体服务器搭建 red5

    简介 1. 流媒体指以流方式在网络中传送音频.视频和多媒体文件的媒体形式.相对于下载后观看的网络播放形式而言,流媒体的典型特征是把连续的音频和视频信息压缩后放到网络服务器上,用户边下载边观看,而不必等 ...

  6. 虚拟机上图片服务器搭建(FastDFS+nginx)

    文件服务器 0.提前建好需要的文件夹(/home/fastdfs) /home/fastdfs/tracker /home/fastdfs/storage /home/fastdfs/storage/ ...

  7. windows server 2012 流媒体服务器搭建(直播与点播)

    IIS Live Smooth Streaming(实时平滑流式处理)是微软下一代流媒体解决方案.该技术是在IIS web中集成媒体传输平台IIS media services,实现利用标准 HTTP ...

  8. 实时监控、直播流、流媒体、视频网站开发方案流媒体服务器搭建及配置详解:使用nginx搭建rtmp直播、rtmp点播、,hls直播服务配置详解

    注意:这里不会讲到nginx流媒体模块如何安装的问题,只研究rtmp,hls直播和录制相关的nginx服务器配置文件的详细用法和说明.可以对照这些命令详解配置nginx -rtmp服务 一.nginx ...

  9. SRS服务器搭建,ffmpeg 本地推流,srs从本地拉流

    参考: https://github.com/ossrs/srs/wiki/v2_CN_SampleFFMPEG git clone https://github.com/ossrs/srs cd s ...

随机推荐

  1. android popupwindow 位置显示

    1.在控件的上方: private void showPopUp(View v) { LinearLayout layout = new LinearLayout(this); layout.setB ...

  2. c++ string构造函数学习

    #include <iostream>#include <string> using namespace std; int main(){ string a1; cout &l ...

  3. Linux Shell列出网络中所有的活跃主机

    因为的的网段是 192.168.1.0/24 , 所以我只需遍历 192.168.1.1 到 192.168.1.255 之间的所有ip然后进行 ping 就可以了: test.sh: #!/bin/ ...

  4. L1、L2正则化详解

    正则化是一种回归的形式,它将系数估计(coefficient estimate)朝零的方向进行约束.调整或缩小.也就是说,正则化可以在学习过程中降低模型复杂度和不稳定程度,从而避免过拟合的危险. 一. ...

  5. WePay-T

    (需先申请微信支付商户账号) 在微信支付中绑定appid,公众号和小程序都一样 微信支付中如下: 微信公众平台如下(公众号与小程序一样): 微擎配置微信支付 appid.appsecret为公众号中对 ...

  6. windows10激活出现0xC0000022

    怎么办?不要担心,先找到了C:\Windows\System32\spp\store 文件夹,查看了下它的权限,如没有sppsvc,则手动添加了NT SERVICE\sppsvc 并给完全控制的权限. ...

  7. KVM虚拟化介绍(1)

    一.虚拟化分类    1.虚拟化,是指通过虚拟化技术将一台计算机虚拟为多台逻辑计算机.在一台计算机上同时运行多个逻辑计算机,每个逻辑计算机可运行不同的操作系统,并且应用程序都可以在相互独 立的空间内运 ...

  8. 关于element中的父子组件的传值问题

    首先讲一下父子组件的传值问题. 这是大家很熟悉的一张图,讲述了父子组件传值的过程.父组件通过prop传值给子组件,子组件通过$emit给父组件发送消息来使父组件的prop发生变化.这都是老生常谈了.下 ...

  9. Spring boot 新建项目pom.xml文件报错 Failure to transfer org.springframework.boot:spring-boot-maven-plugin

    新建项目依赖下载时网络中断导致资源损坏 删除.m2\repository中后缀名为lastUpdated的文件 cd %userprofile%\.m2\repository for /r %i in ...

  10. leveldb单元测试之宏定义源码剖析

    前言 leveldb 是一个库,没有 main() 函数入口, 故非常难理清其中的代码逻辑.但好在库中有非常多的单元测试代码,帮助读者理解其中的各个模块的功能.然而,测试代码个人觉得一开始看时非常费解 ...