前段时间搭了个RTMP的环境,简单介绍下(主要是ffmpeg编译):
Yasm(NASM汇编,支持X86和AMD64指令集,支持NAS和GNU汇编器语法)
-
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
-
tar xzvf yasm-1.2.0.tar.gz
-
cd yasm-1.2.0
-
./configure
-
make –j 4
-
make install
lame,mp3编码器 (最新版本3.99.5)
点击(此处)折叠或打开
-
wget http://sourceforge.net/projects/lame/files/latest/download?source=directory
-
tar zxvf lame-3.99.5.tar.gz
-
cd lame-3.99.5
-
./configure --enable-shared --prefix=/usr
-
make -j 4
-
make install
libogg,用于处理ogg多流传输格式的开发库,独立解码器(最新版本1.3.2)
-
wget
-
tar zxvf libogg-1.3.2.tar.gz
-
cd libogg-1.3.2
-
./configure
-
make -j 4
-
make install
libvoris,通用音频解码器,(最新版本1.3.5)
点击(此处)折叠或打开
-
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz
-
tar zxvf libvorbis-1.3.5.tar.gz
-
cd libvorbis-1.3.5
-
./configure
-
make -j 4
-
make install
XviD,MPEG-4视频编解码器
点击(此处)折叠或打开
-
wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
-
tar zxvf xvidcore-1.3.2.tar.gz
-
cd xvidcore
-
./build/generic/configure
-
cd build/generic/
-
make -j 4
-
make install
x264,开源的H264/MPEG-4 AVC视频编码函数库
-
wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
-
bzip2 -d last_x264.tar.bz2
-
tar xvf last_x264.tar
-
cd x264-snapshot-20160106-2245/
-
./configure --enable-shared --enable-static --prefix=/usr
-
make
-
make install
libdts,DTS编码库
点击(此处)折叠或打开
-
wget http://download.videolan.org/pub/videolan/libdca/0.0.5/libdca-0.0.5.tar.bz2
-
bzip2 -d libdca-0.0.5.tar.bz2
-
tar xvf libdca-0.0.5.tar
-
cd libdca-0.0.5
-
./configure
-
make
-
make install
liba52,符合ATSC A/52标准的流媒体音频解码标准的程序软件包
-
wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
-
tar zxvf a52dec-0.7.4.tar.gz
-
cd a52dec-0.7.4
-
./configure
-
make -j 4
-
make install
faad2,用作MPEG-2和AAC格式的解码
-
wget http://downloads.sourceforge.net/faac/faad2-2.7.tar.gz
-
tar zxvf faad2-2.7.tar.gz
-
cd faad2-2.7
-
./configure
-
make -j 4
-
make install
faac,AAC音频编码器
点击(此处)折叠或打开
-
wget http://downloads.sourceforge.net/faac/faac-1.28.tar.gz
-
tar zxvf faac-1.28.tar.gz
-
cd faac-1.28
-
./configure --prefix=/usr
-
make -j 4
-
make install
注:遇到../../depcomp: line 512: exec: g++: not found提示时,需要安装gcc-c++软件包,yum –y install gcc-c++
已安装结束后,make可能会遇到错误:
点击(此处)折叠或打开
-
mpeg4ip.h:126: error: new declaration‘char* strcasestr(const char*, const char*)’
-
/usr/include/string.h:369: error: ambiguates old declaration‘const char* strcasestr(const char*, const char*)’
-
In file included from mp4common.h:29, from atom_avc1.cpp:22:
需要进行如下改动:
点击(此处)折叠或打开
-
从123行开始修改此文件mpeg4ip.h,到129行结束。
-
修改前:
-
#ifdef __cplusplus
-
extern "C" {
-
#endif
-
char *strcasestr(const char *haystack, const char *needle);
-
#ifdef __cplusplus
-
}
-
#endif
-
-
修改后:
-
#ifdef __cplusplus
-
extern "C++" {
-
#endif
-
const char *strcasestr(const char *haystack, const char *needle);
-
#ifdef __cplusplus
-
}
-
#endif
amr-nb,语音编码算法,自适应多速率编码
点击(此处)折叠或打开
-
wget http://www.penguin.cz/~utx/ftp/amr/amrnb-11.0.0.0.tar.bz2
-
bzip2 -d amrnb-11.0.0.0.tar.bz2
-
tar xvf amrnb-11.0.0.0.tar
-
cd amrnb-11.0.0.0/
-
./configure
-
make -j 4
-
make install
amr-wb,语音编码算法,自适应多速率编码
点击(此处)折叠或打开
-
wget http://www.penguin.cz/~utx/ftp/amr/amrwb-11.0.0.0.tar.bz2
-
bunzip2 amrwb-11.0.0.0.tar.bz2
-
tar xvf amrwb-11.0.0.0.tar
-
cd amrwb-11.0.0.0/
-
./configure
-
make
-
make install
FFmpeg
-
wget http://ffmpeg.org/releases/ffmpeg-2.8.4.tar.bz2
-
bunzip2 -d ffmpeg-2.8.4.tar.bz2
-
tar xvf ffmpeg-2.8.4.tar
-
cd ffmpeg-2.8.4/
-
./configure --prefix=/usr/local/ffmpeg2 --enable-libmp3lame --enable-libvorbis --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libxvid --enable-postproc --enable-ffserver --enable-ffplay
提示
ERROR: libopencore_amrnb not found,需要安装opencore-amr
-
wget ftp://ftp.linux.ro/gentoo/distfiles/opencore-amr-0.1.3.tar.gz
-
tar zxvf opencore-amr-0.1.3.tar.gz
-
cd opencore-amr-0.1.3
-
./configure --prefix=/usr
-
make -j 4
-
make install
再次编译FFmpeg
点击(此处)折叠或打开
-
./configure --prefix=/usr/local/ffmpeg2 --enable-libmp3lame --enable-libvorbis --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libxvid --enable-postproc --enable-ffserver --enable-ffplay
-
make -j 4
-
make install
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
还需要测试一下,用了nginx搭建个web服务(nginx需要增加nginx_rtmp_module模块的支持),rtmp的配置和nginx的配置比较简单:
点击(此处)折叠或打开
-
worker_processes 1;
-
daemon on;
-
error_log logs/error.log debug;
-
-
events {
-
worker_connections 3000;
-
}
-
-
rtmp {
-
server {
-
listen 1935;
-
chunk_size 4000;
-
-
application test {
-
live on;
-
}
-
}
-
}
-
-
http {
-
include mime.types;
-
default_type application/octet-stream;
-
-
server {
-
listen 80;
-
server_name vmware-hw-01;
-
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root html;
-
}
-
-
location / {
-
root /root/nginx/install/html;
-
}
-
}
-
}
准备一个test.html文件,里面嵌入了jwplayer的播放器:
点击(此处)折叠或打开
-
<html>
-
<head>
-
<script src="/jwplayer/jwplayer.js"></script>
-
</head>
-
-
<body>
-
<div id="my-video"></div>
-
<script type="text/javascript">
-
jwplayer('my-video').setup({
-
flashplayer: "/jwplayer/jwplayer.flash.swf",
-
file:"rtmp://2.1.1.10/test/live_test",
-
width:"50%",
-
aspectratio:"3:2",
-
fallback:"false",
-
primary:"flash"
-
});
-
</script>
-
</body>
-
</html>
附件jwplayer.tgz在/root/nginx/install/html下直接解压即可。最后还需要用新编译的ffmpeg进行编码转换和推流:
点击(此处)折叠或打开
-
#!/bin/bash
-
-
while true; do
-
/usr/local/ffmpeg2/bin/ffmpeg -re -i test.mp4 -f flv "rtmp://2.1.1.10/test/live_test"
-
done
由于视频文件比较小,进行了循环播放。启动Nginx,ffmpeg脚本开始推流,客户端可以访问test.html观看直播视频了。
阅读(1753) | 评论(0) | 转发(0) |