推荐方案三:超级简单

方案一.hls (缺陷:需要花很多时间切片)

1.Distributor ID: Ubuntu
  Description: Ubuntu 16.04.3 LTS
  Release: 16.04
 Codename: xenial

2.Linux 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

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

安装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;
}

#allows us to host some webpages which can show our videos: "http://my-ip/my-page.html"
location / {
root html;
index index.html index.htm;
}
}
}

!!记得将本地内网地址换成你实际使用的哦!!

启动nginx服务

sudo service nginx start

安装ffmpeg

sudo apt-get install ffmpeg

一.推流开始

1.ffmpeg -re -i test.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost/mobile/haha   /*将本地视频文件test.mp4转码推流到本地服务器*/

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

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

这种方法很不可靠,本身切片就很耗费cpu资源的

二.可以先将视频文件切换成片段保存到服务器上然后再播放:

1.在服务器端:ffmpeg -i test.mp4 -f hls test.m3u8 (此test.m3u8保存在/HLS/mobile/目录下,这种切片方法是错误的,生成的test.m3u8文件总是只有最新的ts片段,导致只能播放一个片段,几秒钟就没了)

正确做法如下:

ffmpeg -i test.mp4 -codec:v libx264 -codec:a mp3 -map 0 -f ssegment -segment_format mpegts -segment_list test.m3u8 -segment_time 10 out%04d.ts
解析参数:
-i 指定输入文件
ssegment的一些参数: -segment_format mpegts 指定输出格式为mpegts;-segment_list test.m3u8 指定配置输出的列表文件名;-segment_time 10 指定切片时长为10秒

2.直接在浏览器上输入http://your-ip/mobile/test.m3u8即可播放视频

方案二.apache+php+mysql

1.安装apache

sudo apt-get install apache2

2.安装php

sudo apt-get install php

3.安装mysql

sudo apt-get install mysql-server

此方案未做完

方案三.emby media server

1.ubuntu16.04不能从不安全的仓库安装软件,因此使用以下命令添加emby秘钥

wget -nv http://download.opensuse.org/repositories/home:emby/xUbuntu_16.04/Release.key -O Release.key

sudo apt-key add - < Release.key

sudo apt-get update

2.sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/emby/xUbuntu_16.04/ /' > /etc/apt/sources.list.d/emby-server.list"

sudo apt-get update

sudo apt-get install emby-server

启动emby-server

sudo systemctl start emby-server

设置开机启动emby-server

sudo systemctl enable emby-server

访问localhost:8096进行设置

												

在ubuntu16.04上搭建视频服务器的更多相关文章

  1. Ubuntu 18.04上搭建FTP服务器

    1.准备工作需要安装并运行的Ubuntu Server 18.04系统.当然还需要一个具有sudo权限的账号. 2.安装VSFTPVSFTP程序位于标准存储库中,因此可以使用单个命令删除安装.打开终端 ...

  2. Ubuntu14.04上搭建FTP服务器

    Ubuntu上常用的Ftp服务器是vsFTPd.安装前检查下是否已经装好了.用 sudo service vsftpd restart,如果提示重启成功之类的信息,说明此服务器已经安装好了vsFTPd ...

  3. Ubuntu16.04 下搭建git服务器及gitweb+nginx配置

    本文转自:http://blog.csdn.net/water_horse/article/details/68958140 1.安装所需软件 fengjk@water:~$ sudo apt-get ...

  4. 四条命令快速在Ubuntu16.04上配置DNS服务器

    1. apt install dnsmasq -y 2. vim /etc/dnsmasq.d/resolv.conf address=/xxx.yyy.com/21.xx.xx.x 3. servi ...

  5. Ubuntu 16.04上搭建CDH5.16.1集群

    本文参考自:<Ubuntu16.04上搭建CDH5.14集群> 1.准备三台(CDH默认配置为三台)安装Ubuntu 16.04.4 LTS系统的服务器,假设ip地址分布为 192.168 ...

  6. Mac上搭建直播服务器Nginx+rtmp

    简介 nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择,本人在网上整理了安装流程,分享给大家并且作备忘. 步骤安装 1.安装Homebrow Homebrew简 ...

  7. Ubuntu 14.04快速搭建SVN服务器及日常使用【转】

    转自:http://www.linuxidc.com/Linux/2015-05/117735.htm 1.介绍  Subversion是一个自由,开源的版本控制系统,这个版本库就像一个普通的文件服务 ...

  8. 微软.NET年芳15:我在Azure上搭建Photon服务器(C#.NET)

    网上火热的“微软.NET年芳15”文章,我也得写点什么嘛,毕竟我还是现任的微软MVP. 摘录网上的“.NET 15周年”信息如下: 微软的 .NET 框架本周迎来了 15 岁生日..NET 的第一个版 ...

  9. Ubuntu 14.04快速搭建SVN服务器及日常使用

    1.介绍  Subversion是一个自由,开源的版本控制系统,这个版本库就像一个普通的文件服务器,不同的是,它可以记录每一次文件和目录的修改情况.这样就可以很方面恢复到以前的版本,并可以查看数据更改 ...

随机推荐

  1. [LeetCode] 168. Excel Sheet Column Title_Easy tag: Math

    Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...

  2. linux命令:帮助命令

    帮助命令:man 命令名称:man 命令英文原意:manual 命令所在路径:/usr/bin/man 执行权限:所有用户 语法:man [命令或配置文件] 功能描述:获得帮助信息 范例:$man l ...

  3. http 同步异步请求

    在用户交互模式下,当你改变表单中某个组件的值时, 譬如你填写名字.修改性别.选择爱好的时候,浏览器和服 务器至今没有发生任何交互,只有当你点击submit的时候, 浏览器才会把你的参数,也就是form ...

  4. Microsoft Interview第一轮

    上来随意交谈了一小会儿,开了点小玩笑,chat了一些关于他们recruter行程的话题,缓和了一下气氛. 进入正题,问了做的research的方向,我说是DLT,然后大概给他讲解了一下具体是什么, 跟 ...

  5. mysql导入数据方法和报错解决

    mysql -u root -p databasename < db.sql 数据库导入数据时,MySQL收到下面异常:ERROR 1153 (08S01): Got a packet bigg ...

  6. mysql BLOB字段转String的方法

    1.通过sql直接转换 select CONVERT(GROUP_CONCAT(XXX) USING utf8 from usertable; 2.通过程序转换(注:本例用的是springmvc包装并 ...

  7. OAuth 白话简明教程 1.简述

    转自:http://www.cftea.com/c/2016/11/6702.asp OAuth 白话简明教程 1.简述 OAuth 白话简明教程 2.授权码模式(Authorization Code ...

  8. SV中的线程

    SV中线程之间的通信可以让验证组件之间更好的传递transaction. SV对verilog建模方式的扩展:1) fork.....join 必须等到块内的所有线程都执行结束后,才能继续执行块后的语 ...

  9. VS2010/MFC编程入门之四十四(MFC常用类:定时器Timer)

    前面一节鸡啄米讲了CTime类和CTimeSpan类的使用,本节继续讲与时间有关的定时器.定时器并不是一个类,主要考虑到,提起时间的话就不能不说定时器,所以就把它放到CTime和CTimeSpan之后 ...

  10. EOJ Monthly 2018.11 猜价格 (模拟)

    分三种情况: 1.k=1.此时每次都说反话,反着二分即可. 2.1<k <= n.那么在前n次问答中一定会出现一次错误,通过不断输出1找出那个错误发生的位置(若回答是>那这就是错误) ...