第一部分:

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

最新文章

  1. 个人项目制作(PSP)
  2. go json null字段的转换
  3. CSS3小分队——进击的border-radius
  4. iOS开发网络篇—GET请求和POST请求(转)
  5. VS2008调试技巧收集备用
  6. Java HashMap实例源码分析
  7. 教程:30分钟学会Adobe Premiere
  8. unity节目素材ProceduralMaterial采用
  9. 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”的解决方法!
  10. 51nod1649- 齐头并进-最短路
  11. vue自定义键盘事件
  12. 《转》完美解决微信video视频隐藏控件和内联播放问题
  13. mybatis-generator 自动生成查询Vo
  14. MVC _Ajax的使用【七】
  15. sql 表,字段(列),表数据(行)相关命令
  16. apiCloud 上拉加载
  17. binlog开启和查看
  18. 1-QT-文件操作
  19. super深究
  20. java在CMD窗口执行程序的时候输入密码(隐藏一些敏感信息)

热门文章

  1. 阶段5 3.微服务项目【学成在线】_day05 消息中间件RabbitMQ_17.RabbitMQ研究-与springboot整合-消费者代码
  2. Apache 2.4下配置Apache和PHP,使之协同工作
  3. Windows下Tesseract-OCR的安装
  4. centos(linux)-maven配置
  5. 【POJ - 3046】Ant Counting(多重集组合数)
  6. Spring A 标签链接使用
  7. POI锁定列并设置Cell文本格式
  8. 六扇门团队作业 ——《DorMi宿舍管理系统需求分析》
  9. hdoj1711(kmp算法)
  10. RxJava基本使用