标签:
平台:centos6.5 x86_64最小化安装
1安装rmpforge源
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
安装epel源
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
2更新
yum update -y
3安装相关的库
yum install -y automake autoconf make gcc gcc-c++ libtool libvpx bzip2 subversion libjpeg-devel zlib zlib-devel curl curl-devel alsa-lib alsa-lib-devel gettext gettext-devel expat expat-devel libogg theora libtheora-devel xvidcore xvidcore-devel vorbis libvorbis-devel faac-devel lame-devel amrnb-devel opencore-amr-devel amrwb-devel perl-devel git
4安装yasm汇编器
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make && make install
5安装mplayer编码库(仅限64位系统)
wget http://www2.mplayerhq.hu/MPlayer/releases/codecs/essential-amd64-20071007.tar.bz2
tar xjvf essential-amd64-20071007.tar.bz2
mkdir -p /usr/local/lib/codecs
cp -Rvp essential-amd64-20071007/* /usr/local/lib/codecs/
vi /etc/ld.so.conf
添加
/usr/lib
/usr/local/lib
6安装x264
wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/last_stable_x264.tar.bz2
tar jxvf last_stable_x264.tar.bz2
cd x264-snapshot-20150825-2245-stable/ (日期是你当前日期,ls看一下)
./configure --enable-shared --enable-pic
make && make install
7安装libvpx
wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.4.0.tar.bz2
tar jxvf libvpx-v1.4.0.tar.bz2
cd libvpx-v1.4.0
./configure --enable-shared --enable-pic
make && make install
8安装pkgconfig
curl http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz -o pkgconfig.tgz
tar -zxf pkgconfig.tgz && cd pkg-config-0.28
./configure --with-internal-glib
make && make install
export PKG_CONFIG_PATH=/usr/local/bin/pkg-config:$PKG_CONFIG_PATH
9安装ffmpeg
wget http://ffmpeg.org/releases/ffmpeg-2.7.2.tar.bz2
tar jxvf ffmpeg-2.7.2.tar.bz2
cd ffmpeg-2.7.2
./configure --enable-gpl --enable-version3 --enable-shared --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264
make && make install
10安装mencoder编码器(可选,支持转换rmvb为avi)
yum install -y mplayer mencoder flvtool2
mencoder -oac help 查看音频的
mencoder -oac help 查看视频的
11安装nginx
准备相关模块
yum install -y openssl-devel pcre pcre-devel yamdi
12安装支持flv/mp4播放模块
wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
cd nginx_mod_h264_streaming-2.2.7
修改下源码,注释掉158行到161行
vi ./src/ngx_http_streaming_module.c
/* TODO: Win32 */
//if (r->zero_in_uri)
// {
// return NGX_DECLINED;
// }
13下载支持rtmp/hls协议的模块
wget -O nginx-rtmp-module.zip https://github.com/arut/nginx-rtmp-module/archive/master.zip
unzip nginx-rtmp-module.zip
下载缓存模块
wget -O ngx_cache_purge.zip https://github.com/FRiCKLE/ngx_cache_purge/archive/master.zip
unzip ngx_cache_purge.zip
安装最新的nginx
wget http://nginx.org/download/nginx-1.9.4.tar.gz
tar zxvf nginx-1.9.4.tar.gz
cd nginx-1.9.4
./configure --user=daemon --group=daemon --prefix=/usr/local/nginx/ --add-module=../nginx-rtmp-module-master --add-module=../ngx_cache_purge-master --add-module=../nginx_mod_h264_streaming-2.2.7 --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_flv_module
make && make install
/usr/local/nginx/sbin/nginx -V 查看安装的模块是否正确
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bk
建立存放视频目录
mkdir /mnt/media/vod /mnt/media/app /mnt/media/vedio
vi /usr/local/nginx/conf/nginx.conf
#filename:nginx.conf
#user nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
rtmp {
server {
listen 1935;
chunk_size 4000;
# video on demand
application vod {
play /mnt/media/vod;
}
# HLS
# HLS requires libavformat & should be configured as a separate
# NGINX module in addition to nginx-rtmp-module:
# ./configure … –add-module=/path/to/nginx-rtmp-module/hls …
# For HLS to work please create a directory in tmpfs (/tmp/app here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
#
# Incoming stream must be in H264/AAC/MP3. For iPhones use baseline H264
# profile (see ffmpeg example).
# This example creates RTMP stream from movie ready for HLS:
#
# ffmpeg -loglevel verbose -re -i movie.avi -vcodec libx264
#-vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
#-f flv rtmp://localhost:1935/hls/movie
#
# If you need to transcode live stream use ‘exec’ feature.
#
application hls {
hls on;
hls_path /mnt/media/app;
hls_fragment 10s;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
#log format
log_format access ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;
#定义一个名为addr的limit_zone,大小10M内存来存储session
limit_conn_zone $binary_remote_addr zone=addr:10m;
server {
listen 8080;
server_name localhost;
# HTTP can be used for accessing RTMP stats
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /mnt/soft/nginx-rtmp-module-master;
}
location /control {
rtmp_control all;
}
location / {
root /mnt/soft/nginx-rtmp-module-master/test/rtmp-publisher;
}
}
server {
listen 80;
server_name localhost;
location / {
root /mnt/wwwroot;
index index.html;
}
location ~ \.flv$ {
root /mnt/media/vod;
flv;
limit_conn addr 20;
limit_rate 200k;
}
location ~ \.mp4$ {
root /mnt/media/vod;
mp4;
limit_conn addr 20;
limit_rate 200k;
}
location /hls {
# Serve HLS fragments
alias /mnt/media/app;
}
access_log logs/nginxflv_access.log access;
}
}
14安装切片工具segmenter
git clone https://github.com/johnf/m3u8-segmenter.git
cd m3u8-segmenter/
gcc -Wall -g m3u8-segmenter.c -o segmenter -lavformat
cp segmenter /usr/bin/
15测试
上传MP4文件到/mnt/media/video/
将MP4转换为flv格式
cd /mnt/media/video/
ffmpeg -i movie1.mp4 -y -vcodec libx264 -vf scale="640:-1" -r 15 -acodec libfaac ../vod/movie1.flv
cd ../vod
mv movie1.flv movie1-src.flv
添加关键帧以支持拖动播放
yamdi -i movie1-src.flv -o movie1.flv
将flv转换成ts文件
mkdir /mnt/media/app/movie1
还在vod目录下
ffmpeg -y -i movie1.flv -f mpegts -c:v copy -c:a copy -vbsf h264_mp4toannexb /mnt/media/app/movie1/main.ts
切片
cd /mnt/media/app/movie1/
segmenter -i main.ts -d 10 -p movie1 -m movie1.m3u8 -u http://YOURSERVERIP/hls/movie1/
测试
http://YOURSERVERIP/hls/movie1/movie1.m3u8
本文参考
http://hdu104.com/294
标签:
原文地址:http://my.oschina.net/u/2404183/blog/496822