iPhone HTTP Streaming with FFMpeg and an Open Source Segmenter
由于项目需要,需要搭建一个手机流媒体服务器,之前有做过流媒体服务器,不过都是PC客户端的•首选的是 flash media server。但是这次客户端是手机,手机客户端的种类很多,Nokia,iphone, android,他们没有一个支持 rtmp协议的而且支持的格式也很少,后来查询google,得知 android 支持rtsp,又是一路的 google 后来锁定在 live555 和 feng stream server,经过试验•用VLC 播放是可以的,在android上rtsp播放就是个废物不给力,也许是我研究的不够透彻,也在网上看其他网站的手机视频,时光网直接给的是http协议mp4•没有做任何处理•这样有一个弊端就是客户端与服务端建立连接一直下载视频,占用服务器带宽和资源,好处是解决各个手机客户端的不兼容问题。就在准备直接使用http 协议播放mp4的时候,有同事提到视频切片,就在google 上搜索,搜索到 一篇老外的文章,通过ffmpeg把视频转码,转成TS流文件,而后通过开源的 segmenter 把流文件切割成几个TS流文件,生成一个播放列表维护切成的散文件。经过试验,效果不错•该作者的 ffmpeg 参数是专门真多 iphone做了优化•在vlc上播放的效果远不如iphone上的效果~下面我把我安装过程与遇到的一些小问题都记录下来•
在nginx 官网上浏览这些日子nginx 的更新,看到 更新了Split Clients 的模块·然后就看了一下·发现官网wiki的几点问题·写帮助文档的人有些不负责,我编译安装后,按照wiki的方法配置nginx.conf 报错。 官网wiki : http://wiki.nginx.org/HttpSplitClientsModule http { split-clients “${remote-addr}AAA” $variant { 0.5% .one; 2.0% .two; – “”; } server { location / { index index${variant}.html; 我实际的代码是: http { split_clients “${remote_addr}AAA” $variant { 0.5% .one; 2% .two; 3% .eric; 4% .yang; 50% .thr; * “”; } server { location / { [...]
新增功能:
增加 BasicAuth 认证功能,
去掉了显示:serveraccepts handled requests
只显示主要的: ActiveConn reading writing waiting
优化代码可以省去不需要的参数。
源码:
# -*- coding: utf-8 -*-
#!/usr/bin/python
# check_nginx is a Nagios to monitor nginx statu
# my blog: http://www.nginxs.com
# The version is 1.0.1
# MSN: yangzi2008@126.com
import string
import urllib2
import getopt
import sys
def usage():
print """check_nginx is a Nagios to monitor nginx status
Usage:
check_nginx [-h|--help][-u|--url][-p|--path][-w|--warning][-c|--critical]
Options:
--help|-h)
FreeBSD, network card: Intel fxp, port: 100Мбит, polling, http accept-filter. in sysctl: sysctl kern.maxfiles=90000 sysctl kern.maxfilesperproc=80000 sysctl net.inet.tcp.blackhole=2 sysctl net.inet.udp.blackhole=1 sysctl kern.polling.burst_max=1000 sysctl kern.polling.each_burst=50 sysctl kern.ipc.somaxconn=32768 sysctl net.inet.tcp.msl=3000 sysctl net.inet.tcp.maxtcptw=40960 sysctl net.inet.tcp.nolocaltimewait=1 sysctl net.inet.ip.portrange.first=1024 sysctl net.inet.ip.portrange.last=65535 sysctl net.inet.ip.portrange.randomized=0 in nginx configuration: worker_processes 1; worker_rlimit_nofile 80000; events { worker_connections 50000; } server_tokens off; log_format IP `$remote_addr’; [...]
nginx 错误日志: 转帖: 错误 accept() failed (53: Software caused connection abort) [error] 25361#0: accept() failed (53: Software caused connection abort) while accepting new connection on 0.0.0.0:80 [error] 25361#0: accept() failed (53: Software caused connection abort) while accepting new connection on 0.0.0.0:80 [error] 25365#0: accept() failed (53: Software caused connection abort) while accepting new connection on [...]
闲的蛋疼学习python urllib2模块,想到了可以写nginx status模块,就试着写了一下,随后测试下了,比shell写的执行速度要快些,数据如下
第一次: 第二次:
check_nginx.sh check_nginx.sh
real 0m0.453s real 0m0.264s
user 0m0.020s user 0m0.030s
sys 0m0.030s sys 0m0.020s
check_nginx.py check_nginx.py
real 0m0.244s real 0m0.244s
user 0m0.030s user 0m0.020s
sys 0m0.020s sys 0m0.010s
由此可以看出 python速度要快些。
下面帖源码:
由于本人对PHP了解有限,读起 README来有些慢·不过还是看明白了点·先写下上传,和得到文件的fileid,同理也可以下载·呵呵。其实很简单函数有说明的。接上文的安装完毕后,在nginx 上编译php-fpm,让其支持php. 1.编译php-fpm nginx $> wget http://cn2.php.net/get/php-5.2.14.tar.bz2/from/cn.php.net/mirror nginx $> wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz nginx $> tar jxvf php-5.2.14.tar.bz2 nginx $> gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1 nginx $> cd php-5.2.14 nginx $> ./configure –prefix=/usr/local/php –enable-fastcgi –enable-fpm –enable-force-cgi-redirect nginx $> make nginx $> make install nginx $> cp php.ini-dist /usr/local/php/etc/ 2.编译fastdfs_client.so php扩展模块 nginx $> cd [...]
很长时间没有关注FastDFS了,第一次使用FastDFS 是在 08年的时候11月的时候,那个时候是为了解决公司的数据存储~那时候可能是对Fastdfs了解不深,功能还不算太健全,最后选择了lustre。再回过头来看FastDFS更新很快,还看到fastdfs-nginx-module_v1.01.tar.gz nginx模块,所以今天在一台测试机上测试了·测试几天看稳定不稳定,在考虑换掉浪费资源的 lustre !
环境:
storage1:192.168.6.100
storage2:192.168.6.101
tracker:192.168.6.102
1. 在每个机器上,下载安装 FastDFS
nginx $> wget http://fastdfs.googlecode.com/files/FastDFS_v2.04.tar.gz
# 解压
nginx $> tar zxvf FastDFS_v2.04.tar.gz
nginx $> cd FastDFS
# 因为我是给nginx添加fastdfs模块,所以不需要fastdfs支持 http 所以我就不需要去掉 #WITH_HTTPD=1 前的注释了,直接编译
nginx $> ./make.sh
nginx $> ./make.sh install
2.修改tracker 和 storage 的配置文件
# tracker 的修改
tracker $> vim /etc/fdfs/tracker.conf
disabled=false
#配置是否生效
bind_addr=192.168.6.102
#绑定IP
port=22122
#服务端口
connect_timeout=30
#连接超时时间
network_timeout=60
# tracker server的网络超时,单位为秒。
base_path=/home/yangzi
#目录地址,里面会创建data(存放存储服务器信息)、logs,日志文件
max_connections=256
#系统提供服务最大连接数
work_threads=4
#线程数,通常设置CPU数
store_lookup=2
上传组(卷) 的方式 0:轮询方式 1: 指定组 2: 平衡负载(选择最大剩余空间的组(卷)上传)
这里如果在应用层指定了上传到一个固定组,那么这个参数被绕过
store_group=group1
当上一个参数设定为1 时 (store_lookup=1,即指定组名时),必须设置本参数为系统中存在的一个组名。如果选择其他的上传方式,这个参数就没有效了
store_server=0
选择哪个storage server 进行上传操作(一个文件被上传后,这个storage server就相当于这个文件的storage server源,会对同组的storage server推送这个文件达到同步效果)
# 0: 轮询方式
# 1: 根据ip 地址进行排序选择第一个服务器(IP地址最小者)
# 2: 根据优先级进行排序(上传优先级由storage server来设置,参数名为upload_priority)
store_path=0
我的VPS,内存是 512的,开始的时候呢php-fpm 开的进程是20个,后来加上APC,重启之后访问速度蛮快的,但没有过几天,访问blog的时候,感觉相应速度比较慢,就连访问纯静态的页面也是,登录VPS,键入top命令查看,显示 Mem 还是有 free的,但是 Swap used 也是有波动的,肯定是内存的问题,之前我设置的 APC 占用 64的内存的,打开 apc的监控页面,发现 Used 很少,Free很多,因为我只是一个blog没有多少动态页面需要缓存的。所以分配这么内存是浪费的。至于php-fpm的进程也没有必要20个进程,只要优化的合理 12个进程就可以(访问量也小么),好了,现在开始优化
shell $> vim /usr/local/php/etc/php-fpm.conf
<value name="max_children">20</value>
改为
<value name="max_children">12</value>
shell $> vim /usr/local/php/etc/php.ini
添加
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
上次写了一篇nginx+php-fpm优化上传,一位博友留言介绍了,第三方nginx upload module
http://www.grid.net.ru/nginx/upload.en.html
看了一下,功能蛮强大的,所以就记录下来·基本没什么变化,在原有的例子上稍加了下修改,加了一个限速功能。
在 0.8.X 版本上编译出出错,他官方也有写:
For nginx versions other than 0.7.44-51
但是我在最新版本 nginx-0.7.67.tar.gz 编译也没问题。
下载nginx:wget http://www.nginx.org/download/nginx-0.7.67.tar.gz
下载模块:wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.12.tar.gz
1.下载编译安装nginx_upload_module
nginx $> tar zxvf nginx-0.7.67.tar.gz
nginx $> tar zxvf nginx_upload_module-2.0.12.tar.gz
nginx $> cd nginx-0.7.67
#关掉不需要的模块,节省资源开支俗话说越简洁越稳定~
nginx $> ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --without-http_memcached_module --without-http_empty_gif_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --add-module=/root/nginx_upload_module-2.0.12
nginx $> make
nginx $> make install
近期评论