@rg070836rg
2017-02-12T17:55:36.000000Z
字数 6230
阅读 1577
未分类
sudo apt-get update
目的是为了 保持ubuntu的依赖正确
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
sudo apt-get install gcc make automake bzip2 unzip patch subversion libjpeg62-dev
cd ~
mkdir working
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar zxvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make && make install
cd ~/working
如果遇到权限不够 切换root chmod 777 加权限
保证下面的安装都在 working目录下
apt-get remove ffmpeg x264
wget -c http://www2.mplayerhq.hu/MPlayer/releases/codecs/essential-amd64-20071007.tar.bz2
tar xvjf essential-amd64-20071007.tar.bz2
mkdir /usr/local/lib/codecs
cp -Rvp essential-amd64-20071007/* /usr/local/lib/codecs/
编辑下面文件
vim /etc/ld.so.conf
添加以下两行到上面的文件里
/usr/lib
/usr/local/lib
sudo apt-get install make automake g++ bzip2 python unzip patch subversion ruby build-essential git-core checkinstall yasm texi2html libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libvdpau-dev libvorbis-dev libvpx-dev libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev
sudo git clone git://git.videolan.org/x264.git
cd x264
sudo ./configure --enable-shared --prefix=/usr/local
sudo make
sudo make install
cd ~/working
cd ~/working
下载 libvpx-1.4.0,
http://download.csdn.net/download/lsc1818/8929949
tar xvjf libvpx-1.4.0.tar.bz2
cd libvpx-1.4.0
sudo ./configure --enable-shared --prefix=/usr/local
make && make install
cd ~/working
cd ~/working
wget http://ffmpeg.org/releases/ffmpeg-2.7.2.tar.bz2
tar xvjf 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-libxvid --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
make && make install
cd ~/working
让动态链接库被系统共享
ldconfig
apt-get install libmp3lame-dev
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
cd mplayer/
./configure
make && make install
sudo apt-get install ruby
gem install flvtool2
sudo apt-get install mencoder
查看所有所支持的音频编码
mencoder -oac help
查看所有所支持的视频编码
mencoder -ovc help
先安装各种依赖(nginx需要pcre支持,yamdi用来为flv创建关键帧才能随意拖动)
sudo apt-get install gcc g++ libssl-dev zlib1g-dev libpcre3-dev yamdi
下载所需的nginx模块
第一个是nginx_mod_h264_streaming,让nginx支持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
注意:先要修改一下源码,注释掉
nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c
的158到161行
sudo gedit nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c
/* TODO: Win32 */
//if (r->zero_in_uri)
// {
// return NGX_DECLINED;
// }
第二个是nginx-rtmp-module,让nginx支持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.8.0.tar.gz
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./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
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d nginx defaults
sudo service nginx start//开启
sudo service nginx stop //停止,列出
开启后,浏览localhost
编辑/usr/local/nginx/conf/nginx.conf文件
sudo gedit /usr/local/nginx/conf/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/video;
mp4;
limit_conn addr 20;
limit_rate 200k;
}
location /hls {
# Serve HLS fragments
alias /mnt/media/app;
}
access_log logs/nginxflv_access.log access;
}
}
注意 如果启动不了,是文件权限错误。手动建立文件夹
/mnt/media/video -> 存放原始视频
/mnt/media/vod -> 存放转换后的flv和mp4视频,供http或rtmp访问
git clone https://github.com/johnf/m3u8-segmenter.git
直接找到m3u8-segmenter.c 所在目录
cd m3u8-segmenter/
gcc -Wall -g m3u8-segmenter.c -o segmenter -lavformat -lavcodec -lavutil
拷贝至软件目录
cp segmenter /usr/bin/
切片势力 原文件为 vp5.flv 转换为vp5.ts
ffmpeg -i vp5.flv -acodec copy -vcodec libx264 vp5.ts
segmenter 转换为m3u8 :
segmenter -i vp5.ts -d 10 -p onedemo -m vp5.m3u8 -u http://localhost/videox/
-p one demo 是分片的名字
-u 是访问的链接 比如现在的网站ip是 192.168.2.107 那么填写 http://192.168.2.107/video/
最后把ts文件与M3U8文件拷贝到网站对应的目录下 即可
未解决问题:
1 网页播放m3u8,原计划使用ckplayer 但是一直有错,没有成功
2 据观察,m3u8同样能够下载?