第一种方案:ffmpeg+nginx

新的ffmpeg已经支持HLS。(本人也参与了代码供献,给自己做个广告:))

点播:

生成hls分片:

ffmpeg -i <媒体文件> -c:v libx264 -c:a aac -f hls /usr/local/nginx/html/test.m3u8

直播:

ffmpeg -i udp://@:1234 -c:v libx264 -c:a aac -f hls -hls_list_size 5 -hls_wrap 5 /usr/local/nginx/html/test.m3u8

建立web服务器:

默认配置就可以。

server {
        listen       80;
        server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
            root   html;
            index  index.html index.htm;
        }

}

启动nginx。

客户端访问:http://IP/test.m3u8

在windows上可以用vlc播放。

第二个方案,用nginx-rtmp-module

  1. rtmp {
  2.  
  3. server {
  4.  
  5. listen 1935;
  6.  
  7. chunk_size 4000;
  8.  
  9. #HLS
  10.  
  11. # For HLS to work please create a directory in tmpfs (/tmp/app here)
  12. # for the fragments. The directory contents is served via HTTP (see
  13. # http{} section in config)
  14. #
  15. # Incoming stream must be in H264/AAC. For iPhones use baseline H264
  16. # profile (see ffmpeg example).
  17. # This example creates RTMP stream from movie ready for HLS:
  18. #
  19. # ffmpeg -loglevel verbose -re -i movie.avi -vcodec libx264
  20. # -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
  21. # -f flv rtmp://localhost:1935/hls/movie
  22. #
  23. # If you need to transcode live stream use 'exec' feature.
  24. #
  25. application hls {
  26. live on;
  27. hls on;
  28. hls_path /tmp/app;
  29. hls_fragment 5s;
  30. }
  31. }
  32. }
  33.  
  34. http {
  35.  
  36. server {
  37.  
  38. listen 80;
  39. location /hls {
  40. # Serve HLS fragments
  41. types {
  42. application/vnd.apple.mpegurl m3u8;
  43. video/mp2t ts;
  44. }
  45. alias /tmp/app;
  46. expires -1;
  47. }
  48. }
  49. }

1        功能:

1.1         视频、音频直播流(Live streaming of video/audio)

1.2         Flv、mp4视频需求,从本地或HTTP播放(Video ondemand FLV/MP4, playing from local filesystem or HTTP)

1.3         支持分布式流中继:推或拉模式(Stream relay support for distributed streaming: push & pullmodels)

1.4         录制FLVS流(Recording streams in multiple FLVs)

1.5         支持H264/AAC

1.6         在线用ffmpeg转码(Online transcoding with FFmpeg)

1.7         HLS (HTTP Live Streaming) 支持

1.8         基于http的操作(发布、播放、录制)(HTTP callbacks (publish/play/record/update etc))

1.9         在一定的事件中执行应用程序(Running external programs on certain events (exec))

1.10      HTTP control module forrecording audio/video and dropping clients

1.11      高级内存管理技术,快速流和低内存占用(Advanced buffering techniques to keep memory allocations at aminimum level for faster streaming and low memory footprint)

1.12      实践证明可以在下列产品中工作: Wirecast,FMS,Wowza, JWPlayer,FlowPlayer,StrobeMediaPlayback,ffmpeg,avconv,rtmpdump,flvstreamer and many more

1.13      Statistics in XML/XSL in machine-& human- readable form

1.14      Linux/FreeBSD/MacOS/Windows

2        代码下载:

Nginx:

官网:http://nginx.org/

下载:hg clone http://hg.nginx.org/nginx

nginx-rtmp-module:

官网:https://github.com/arut/nginx-rtmp-module

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

3        编译:

3.1         Linux下:

进入nginx源码根目录:

auto/configure--add-module=<path-to-nginx-rtmp-module>

make -f objs/Makefile

make -f objs/Makefile install

增加:http_ssl_module:

auto/configure--add-module=<path-to-nginx-rtmp-module> --with-http_ssl_module

3.2   windows下:

3.2.1 官网提供的编译方法:

http://nginx.org/en/docs/howto_build_on_win32.html

3.2.1.1 预备:

l  Microsoft Visual C compiler.Microsoft Visual Studio® 8 and 10

l  Msys

l  Perl(如果要编译OpenSSL并且nginx支持SLL),例如:ActivePerl 或 Strawberry Perl.

l  PCRE,zlib and OpenSSLlibraries sources.

3.2.1.2    编译步骤:

l  设置MSYS、Perl、VC环境变量

运行vc设置环境变量脚本vcvarsall.bat(默认安装路径:C:\Program Files\MicrosoftVisual Studio 9.0\VC)

l  开始MSYS

l  建立编译和库目录

mkdir objs

mkdir objs/lib

cd objs/lib

tar -xzf ../../pcre-8.32.tar.gz

tar -xzf ../../zlib-1.2.7.tar.gz

tar -xzf ../../openssl-1.0.1e.tar.gz

l  运行配置脚本:

auto/configure --with-cc=cl --builddir=objs--prefix= \

--conf-path=conf/nginx.conf--pid-path=logs/nginx.pid \

--http-log-path=logs/access.log--error-log-path=logs/error.log \

--sbin-path=nginx.exe--http-client-body-temp-path=temp/client_body_temp \

--http-proxy-temp-path=temp/proxy_temp \

--http-fastcgi-temp-path=temp/fastcgi_temp\

--with-cc-opt=-DFD_SETSIZE=1024--with-pcre=objs/lib/pcre-8.32 \

--with-zlib=objs/lib/zlib-1.2.7--with-openssl=objs/lib/openssl-1.0.1e \

--with-select_module --with-http_ssl_module--with-ipv6

运行脚本:

nmake –f objs/Makefile

3.2.2 Cygwin下:

linux

4        Windows下的限制:

Windows下下列功能不支持:

l  execs

l  static pulls

l  auto_push

windows下用的是select模式:

events{

worker_connections  30; #默认为(1024),windows默认为64,所以需要修改此值小于64

}

5        访问URL格式:

rtmp://rtmp.example.com/app[/name]

app-应该是配置文件中的application块

name-可以为空

6        配置:

在源码要目下有个test目录。其中有测试配置文件和脚本。

6.1         点播配置:

l  环境:

服务器IP为:192.168.10.4。

安装根路径:/usr/local/nginx

在你的配置时,需要把IP换成你的服务器IP或域名。

l  建立媒体文件夹:

mkdir /usr/local/nginx/vod/flvs

l  准备媒体文件:

把媒体文件 a.flv 复制到 /usr/local/nginx/vod/flvs目录下。

l  准备网页

下载jwplayer:http://www.longtailvideo.com/players/jw-flv-player/

下载后,解压到:/usr/local/nginx/html/

建立测试页面test.html,也放到上面目录下。

<html>

<head>

<scriptsrc="/jwplayer/jwplayer.js"></script>

</head>

<body>

<divid='my-video'></div>

<scripttype='text/javascript'>

jwplayer('my-video').setup({

file:'rtmp://192.168.10.4/vod/a.flv',

width:'50%',

aspectratio:'3:2',

fallback:'false',

primary:'flash'

});

</script>

</body>

</html>

l  在nginx中配置http

#配置事件工作线程数

events {

worker_connections  30; #默认为(1024),windows默认为64,所以需要修改此值小于64

}

#配置http

http {

include       mime.types;

default_type application/octet-stream;

#配置访问web页

server {

listen       80;

server_name  localhost;

#charset koi8-r;

#access_log logs/host.access.log  main;

location / {

root   html;

index  index.html index.htm;

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

#配置rtmp状态页

server {

listen      8080;

location /stat {

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

root /usr/local/nginx/nginx-rtmp-module/;  #在nginx-rtmp-module源码根目录

}

}

}

#rtmp点播配置

rtmp {

server {

listen 1935;

chunk_size 4000;

application  vod {

play /usr/local/nginx/vod/flvs;  #点播媒体文件存放目录

}

}

}

l  启动nginx

./nginx

l  从客户端访问网页:

http://192.168.10.4/test.html

l  访问rtmp状态页(非必须):

http://192.168.10.4:8080/stat

6.2         直播配置:

l

l  在配置文件nginx.conf中加入

#rtmp直播配置

rtmp {

server {

listen 1935;

chunk_size 4000;

application  live {

live on;

}

}

}

#配置访问web页

http {

include       mime.types;

default_type application/octet-stream;

#配置访问web页

server {

listen       80;

server_name  localhost;

#charset koi8-r;

#access_log logs/host.access.log  main;

location / {

root   html;

index  index.html index.htm;

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

#配置rtmp状态页

server {

listen      8080;

location /stat {

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

root /usr/local/nginx/nginx-rtmp-module/;  #在nginx-rtmp-module源码根目录

}

}

}

l  访问rtmp状态页(非必须):

http://192.168.10.4:8080/stat

可以查看rtmp流的统计情况

l  准备网页

下载jwplayer:http://www.longtailvideo.com/players/jw-flv-player/

下载后,解压到:/usr/local/nginx/html/

建立测试页面test.html,也放到上面目录下。

<html>

<head>

<scriptsrc="/jwplayer/jwplayer.js"></script>

</head>

<body>

<divid='my-video'></div>

<scripttype='text/javascript'>

jwplayer('my-video').setup({

file:'rtmp://192.168.0.128/live/test', #live是applicatioin,test是直播缓存流文件

width:'50%',

aspectratio:'3:2',

fallback:'false',

primary:'flash'

});

</script>

</body>

</html>

l  启动服务

nginx

l  推流

用ffmpeg产生一个模拟直播源,向rtmp服务器推送

ffmpeg –i/usr/local/nginx/vod/flvs/a.flv-strict -2 -c:v libx264 -c:a aac -f flv rtmp://192.168.10.4/live/test

注意,源文件必须是H.264+AAC编码的。

192.168.10.4是运行nginx的服务器IP,l

ive是applicatioin,

test是直播缓存流文件,需要与配置文件中的直播缓存文件名一样。

l  从客户端访问网页:

http://192.168.10.4/test.html

nginx + ffmpeg的更多相关文章

  1. 【原创+史上最全】Nginx+ffmpeg实现流媒体直播点播系统

    #centos6.6安装搭建nginx+ffmpeg流媒体服务器 #此系统实现了视频文件的直播及缓存点播,并支持移动端播放(支持Apple和Android端) #系统需要自行安装,流媒体服务器配置完成 ...

  2. 收藏:视频网站(JavaEE+FFmpeg)/Nginx+ffmpeg实现流媒体直播点播系统

    FFmpeg安装(windows环境)http://www.cnblogs.com/xiezhidong/p/6924775.html 最简单的视频网站(JavaEE+FFmpeg)http://bl ...

  3. Nginx+ffmpeg的HLS开源服务器搭建配置及开发详

    本文概述: 至目前为止,HLS 是移动平台上非常重要并十分流行的流媒体传输协议.做移动平台的流媒体开发,不知道它不掌握它 ,真是一大遗憾.而HLS的平台搭建有一定的难度,本文针对对该方向有一定了解的朋 ...

  4. Nginx+ffmpeg的HLS开源server搭建配置及开发具体解释

    本文概述: 至眼下为止.HLS 是移动平台上很重要并十分流行的流媒体传输协议.做移动平台的流媒体开发,不知道它不掌握它 .真是一大遗憾.而HLS的平台搭建有一定的难度,本文针对对该方向有一定了解的朋友 ...

  5. Windows10环境下 Nginx+ffmpeg自搭服务器制作RTMP直播流

    Windows10环境下 Nginx+ffmpeg自搭服务器制作RTMP直播流学习笔记 所需条件: nginx-rtmp-module(带rtmp模块) ,链接:https://link.jiansh ...

  6. Nginx+FFmpeg实现RTSP转RTMP

    RTSP转RTMP 本次转流采用Centos+Nginx+FFmpeg实现,具体实现如下: 1. 安装Ngxin 安装详细略(可以选择安装阿里的Tengine,官方[下载路径](Download - ...

  7. linux系统中Nginx+FFmPeg+vlc实现网页视频播放配置过程

    linux系统中Nginx+FFmPeg实现网页监控视频播放配置过程 1.安装好的nginx上添加模块nginx-http-fiv-module-master 此模块是rtmp模块的升级版,有它所有的 ...

  8. 转:Nginx+ffmpeg的HLS开源服务器搭建配置及开发详解

    转:http://itindex.net/detail/51186-nginx-ffmpeg-hls 本文概述: 至目前为止,HLS 是移动平台上非常重要并十分流行的流媒体传输协议.做移动平台的流媒体 ...

  9. nginx+ffmpeg搭建rtmp转播rtsp流的flash服务器

    本文概要: nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择.本文介绍了一种简易方法快速搭建rtmp流媒体服务器,也叫rtsp转播,数据源不是读取文件,而是采用 ...

  10. 10.nginx+ffmpeg上搭建HLS切片

    1.首先介绍一下HLS协议: (1)简介 这个协议是由苹果公司提出并推广使用的,维基百科介绍如下: HTTP Live Streaming(缩写是HLS)是一个由苹果公司提出的基于HTTP的流媒体网络 ...

随机推荐

  1. InnoDB: Warning: a long semaphore wait 解决办法

    http://blog.csdn.net/wulantian/article/details/37560849

  2. oracle 查看各表空间剩余量

    1.查看所有表空间大小.剩余量: select dbf.tablespace_name,dbf.totalspace "总量(M)",dbf.totalblocks as 总块数, ...

  3. Qt5.1.1实现调用google地图显示

    1.调用google地图工程文件 QT +=webkit QT +=webkitwidgets QT += core gui greaterThan(QT_MAJOR_VERSION, ): QT + ...

  4. [MFC]选择目录对话框和选择文件对话框 [转]

      在MFC编程中经常会需要用到选择目录和选择文件的界面,以下总结一下本人常用的这两种对话框的生成方法: 选择目录对话框 {    char szPath[MAX_PATH];     //存放选择的 ...

  5. java线程中Exchanger使用

    有时我们须要对元素进行配对和交换线程的同步点,使用exchange方法 返回其伙伴的对象,这时我们就须要使用线程类中的Exchanger类了, 我通过一个实例 来简单说明一下他的用法及其作用: imp ...

  6. hql 时间

    1.hql中时间格式转换 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String d ...

  7. spoj 1811 LCS - Longest Common Substring (后缀自己主动机)

    spoj 1811 LCS - Longest Common Substring 题意: 给出两个串S, T, 求最长公共子串. 限制: |S|, |T| <= 1e5 思路: dp O(n^2 ...

  8. dos alias/cname address

    diego@localhost sdk/include/Poco/Net]# dig b.wpss.cn ; <<>> DiG - <<>> b.wps ...

  9. ListView中button监听器 设置 及 优化

    在应用开发中常常会用到ListView,而且每个Item里面都会有button之类的须要进行事件监听的控件.在给button加入OnClickListener的时候,一開始非常下意识的会想在ListV ...

  10. 【Sprint3冲刺之前】项目完成时间表

    Sprint2冲刺成果——项目完成时间表 项目完成时间表 经过Sprint2小组总结会议的探讨,我们决定一起约定项目alpha版本,beta版本,release版本的发布时间,发布形式及预计完成效果 ...