標籤:
平台: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/
將nginx添加到系統服務
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
安裝hls流媒體伺服器