HTTP方式播放FLV/mp4 :nginx+Yamdi/MP4BOX

摘要:
每次播放都会消耗服务器资源。下面是如何使用nginx构建http视频点播服务器。首先,nginx的安装和配置。1.下载最新的win32版本的nginx并将其解压缩到任何目录。2.打开cmd进入nginx目录。可以使用-c选项指定要使用的配置文件。可以使用nginx–h查看更多参数。)其次,nginx支持flv。1.编辑配置文件confginx.conf,在http块中添加启动gzip的配置gzipon;

【导语】chrome浏览器确实很强,直接支持MP4拖动播放,对于其他播放器,可以使用以下方法来支持拖动播放。拖动的关键在于生成关键帧等元数据信息,便于服务器和播放器支持拖动。

另外,nginx web服务器体验起来,也是很有前途的一个web服务器,值得研究。

flv 视频可以采用两种方式发布:

一、普通的 HTTP 下载方式

二、基于 Flash Media Server 或 Red5 服务器的 rtmp/rtmpt 流媒体方式。

多数知名视频网站都采用的是前一种方式。

两种方式对比如下:

HttpRtmp/rtmpt
生成关键帧后可拖动播放任意拖动播放
下载完成后不再消耗服务器资源无缓存,每次播放都会消耗服务器资源


这里说一下怎么用nginx 搭建http 方式的视频点播服务器,主要分为三步:

一、 nginx 安装及配置

1. 下载nginx 最新win32 版本解压到任意目录

2. 打开cmd 进入nginx 目录,使用命令start nginx 启动nginx (默认使用conf ginx.conf 配置,可用-c 选项指定要使用的配置文件,更多参数可使用nginx –h 查看)

二、 nginx 对flv 的支持

1. 编辑配置文件conf ginx.conf ,加入如下配置:

在http 块加入启动gzip 的配置

gzip on;

gzip_min_length 1100;

gzip_buffers 4 8k;

gzip_types text/plain;

在server 块中加入启用flv 的配置:

limit_rate_after 1m; # 下载1M 后开始限速

limit_rate 100k; # 将速度限制为100k/s

location ~ .flv {

flv;

}

2. 使用命令nginx –s reload 重新加载配置文件

三、 客户端播放器

1. 下载开源的flash 播放器jwplayer

2. 将文件解压到nginx 下的html 目录

3. 访问http://localhost:8080/player.swf?type=http&file=1.flv即可播放视频

注意:现在视频能播放了,但并不支持拖动功能,因为没有给flv 文件添加“关键帧”,可以的工具有“yamdi” 和“flvtool”,以yamdi win32 版为例,下载解压后进入cmd 执行:

yamdi –i src.flv –o dst.flv

意思是将src.flv 添加关键帧,并输出为dst.flv 。

OK ,这时我们再访问http://localhost:8080/player.swf?type=http&file=dst.flv即可自由拖动播放了。

=========================================================================================

This post is a comparison of the performance of different tools available to tag FLV and MP4 containers with specific metadata (e.g. title, keyframes, generator or other custom fields…). For FLV containers flvtool2, flvtool++ and yamdi are compared. For the MP4 container MP4box, AtomicParsley and ffmpeg are compared.

Here are the IMO three most important FLV taggers tested on a 125MB FLV:

NameDurationLarge FilesIn MemoryCustom TagsCommand
flvtool2 1.0.63min 11snonoyesflvtool2 -UP -band:Test -user:Test -date:1995 -genres:pop test.flv
flvtool++ 1.2.13snoyesyesflvtool++ test.flv -tag band “Test” -tag user “Test” -tag date “1995″ -tag genres “pop” test2.flv
yamdi 1.61.5syesnonoyamdi -i test.flv -o test2.flv -c “Test”

The performance of flvtool2 is horrendous. For films of 120min it will take hours to process. Therefore: Do not use it! Use Facebooks flvtool++ instead. I guess the bad performance results from it being built in Ruby. Also notice the “Large File” column indicating large file support which officially only yamdi support (by adding compile flag -D_FILE_OFFSET_BITS=64). Another important point is the “In Memory” column indicating that flvtool++ loads the entire file into memory when tagging, which is problematic when tagging large files. Given this results only yamdi should be used for FLV tagging!

Now for the MP4 tagging. Here you can select between a lot of tools from the net, but only a few of them are command line based and available for Unix. The MP4 test file used is 100MB large.

NameDurationCommand
AtomicParsely0.6sAtomicParsley test.mp4 –artist “Test” –genre “Test” –year “1995″
mp4box0.6sMP4Box -itags Name=Test:Artist=Me:disk=95/100 test.mp4
ffmpeg 0.60.8sffmpeg -i test.mp4 -metadata title=”Test” -metadata artist=”Test” -metadata date=”1995″ -acodec copy -vcodec copy test2.mp4

Given that recent ffmpeg brings the tagging for MP4 out of the box (it doesn’t for FLV though) you do not even need an external tool to add the metadata



自:http://www.aojie.biz/1030

免责声明:文章转载自《HTTP方式播放FLV/mp4 :nginx+Yamdi/MP4BOX》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SQL语句汇总——数据修改、数据查询Spring Cloud实战 | 第五篇:Spring Cloud整合OpenFeign实现微服务之间的调用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

解决ThinkPhp在nginx下404问题

 以宝塔面板为例:  找到宝塔面板域名的nginx配置文件进行编辑增加以下内容 fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastc...

docker部署ASP.NET Core、Nginx、MySQL

2019/10/24, docker 19.03.4, ASP.NET Core 3.0, CentOS 7.6 摘要:ASP.NET Core 3.0 网站项目容器化部署,使用docker-compose编排Nginx容器、MySQL容器、web容器案例代码 依赖结构介绍 整个网站项目取名samplems,一共需要三个容器(按依赖顺序): 1.MySQL...

LNMP安装Let’s Encrypt 免费SSL证书方法:自动安装与手动配置Nginx

前几天介绍了最新StartSSL免费SSL申请与配置,很多人看到部落介绍SSL证书安装时总是推荐了OneinStack,因为OneinStack提供了一键添加和配置Let's Encrypt 免费SSL证书的脚本,你在创建虚拟主机绑定域名就可以一步安装好SSL。 其实LNMP(即LNMP.org版LNMP脚本)更新到了1.4版本后已经增加了增加ssl选项...

Nginx补充

[root@localhost ~]# yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make [root@localhost ~]# useradd -M -s /sbin/nologin nginx [root@localhost ~]# tar xf nginx-1...

使用 Docker + SSH代理 来实现访问内网网站

导览 1. 实现SSH远程代理本地站点命令 2. 简单的可用代码 3. 参考或原理 4. 可恶的问题 magento-in-docker magento-in-docker-ssl 一,实现SSH远程代理本地站点命令 1,查看 docker 日志。 【 查看Nginx请求错误详情 】 docker logs <magento-we...

Solr集群—SolrCloud

  1.   学习计划   1、solr集群搭建   2、使用solrj管理solr集群   3、把搜索功能切换到集群版 2.   什么是SolrCloud    SolrCloud(solr 云)是Solr提供的分布式搜索方案,当你需要大规模,容错,分布式索引和检索能力时使用 SolrCloud。当一个系统的索引数据量少的时候是不需要使用SolrClou...