概述
在虚拟机vmware6(版本比较旧了)中,安装centos6,不多说了。
vmware虚拟工具安装前,需要安装如下内容
yum -y install kernel-devel
yum -y install kernet-headers
yum -y install gcc
yum -y upgrade kernel kernel-devel
下面2个是在Centos上使用的
Centos 准备安装删除已安装包
yum erase ffmpeg x264 x264-devel
Centos 安装各种依赖包
yum install gcc make nasm pkgconfig wget curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64 pcre.i386 pcre.x86_64 pcre-devel.i386 pcre-devel.x86_64
整个过程中可能还需要 g++ gcc git svn 等工具 自己随便下下就可以了
centos 的 gcc g++ 安装方法 yum install gcc gcc-c++ 。
该连接可下载下面所有的包 http://pan.baidu.com/s/1eQvHauu
首先安装ffmpeg和他的组件
1.1 安装nasm编译器支持汇编优化(lame库需要)
防止因为时间不对,修改一下为北京时间
1.如果提示command not found,那说明ntp没有安装,使用如下命令进行安装
yum -y install ntpdate ntp
2、ntpdate us.pool.ntp.org
3、设置硬件时间和软件时间的一致并校准
/sbin/hwclock --systoh
wget http://www.nasm.us/pub/nasm/releasebuilds/2.11.05/nasm-2.11.05.tar.bz2
tar xvf nasm-2.11.05.tar.bz2
cd nasm-2.11.05
配置安装目录为/usr/bin:
./configure --prefix=/usr
编译并安装:
make && make install
1.2 安装yasm编译器支持汇编优化(ffmpeg库需要)
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
解压:
tar xvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
配置安装目录为/usr/bin:
./configure --prefix=/usr
编译并安装:
make && make install
1.3 安装lame库支持mp3音频
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --enable-nasm
make && make install
1.4 安装faac库支持mpeg4 aac音频
wget http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
tar xvf faac-1.28.tar.gz
cd faac-1.28
./configure --with-mp4v2
这里需要修改:
vim common/mp4v2/mpeg4ip.h
从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
make && make install
1.5 安装libogg库支持ogg音频
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz
tar xvf libogg-1.3.1.tar.gz
cd libogg-1.3.1
./configure
make && make install
1.6 安装theora库
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
tar xvf libtheora-1.1.1.tar.gz
cd libtheora-1.1.1
./configure
make && make install
1.7 安装x264库支持h.264视频转码
执行以下命令获取x264的最新源代码
git clone git://git.videolan.org/x264.git
cd x264
./configure --enable-shared
make && make install
1.8 安装xvid库支持mpeg4视频转码
wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
获取最新的xvid mpeg4编×××源代码
tar xvf xvidcore-1.3.2.tar.gz
cd xvidcore/build/generic
./configure
make && make install
1.9 安装libnut
该软件需要用svn获取源代码,svn可以直接用yum install svn来装。
先下载:
svn co svn://svn.mplayerhq.hu/nut/src/trunk libnut
下载后代码保存在新建立的libnut目录下,对于64位Linux需要修改配置文件:
cd libnut
vim config.mak
在最后一个CFLAGS下一行增加:
CFLAGS += -fPIC
(或者修改CFLAGS += -Os -fomit-frame-pointer -g -Wall -fPIC
make libnut
make prefix=/usr install-libnut)
然后编译安装:
make && make install
1.10 libvpx
git clone http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure --enable-shared
make && make install
1.11 FAAD2
wget http://downloads.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
tar zxvf faad2-2.7.tar.gz
cd faad2-2.7
./configure
make && make install
1.12 安装vorbis库
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
tar xvf libvorbis-1.3.4.tar.gz
cd libvorbis-1.3.4
./configure
make && make install
1.13 修改链接环境变量
上面的媒体支持库安装完后,可以设置下环境准备编译ffmpeg了。不过在此之前必须修改环境变量
vim /etc/ld.so.conf
在文件末增加一行:
/usr/local/lib
然后生效之:
ldconfig -v
2 编译ffmpeg
执行以下命令获取ffmpeg源代码
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --enable-version3 --enable-libvpx --enable-libfaac --enable-libmp3lame --enable-libvorbis --enable-libx264 --enable-libxvid --enable-shared --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --enable-libnut --enable-libtheora
***需要保证 --enable-libx264能执行
make && make install
ldconfig -v
分割器分2种(本人选第一种m3u8-segmenter)
3. TS流分割器segmenter的安装与使用
第一个 m3u8-segmenter
git clone https://github.com/johnf/m3u8-segmenter
下载m3u8-segmenter 下载后不要用它的反复编译,直接取m3u8-segmenter.c文件。
执行
gcc -Wall -g m3u8-segmenter.c -o segmenter -lavformat -lavcodec -lavutil
cp segmenter /usr/bin/
第二个 segmenter
svn co http://httpsegmenter.googlecode.com/svn/trunk segmenter
cd segmenter
gcc -Wall -g segmenter.c -o segmenter -lavformat -lavcodec -lavutil -std=c99
cp segmenter /usr/bin/
nginx的安装
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
git clone git://github.com/arut/nginx-rtmp-module.git
wget http://sourceforge.net/projects/pcre/files/pcre/8.32/pcre-8.32.tar.gz
tar zxvf pcre-8.32.tar.gz
cd pcre-8.32
./configure --prefix=/usr/local/pcre
make && make install
下载nginx-1.5.3安装包
wget http://nginx.org wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
groupadd www
useradd -g www www
cd ..
cd nginx_mod_h264_streaming-2.2.7/src
vi ngx_http_streaming_module.c
将以下内容注释掉或删掉
/* TODO: Win32 */
if (r->zero_in_uri)
{
return NGX_DECLINED;
}
安装zlib
wget http://www.zlib.net/ zlib-1.2.8.tar.gz 下载到/usr/local/
tar xzvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib
make && make install
编译nginx
./configure --prefix=/usr/local/nginx --add-module=../nginx_mod_h264_streaming-2.2.7 --with-http_ssl_module --with-pcre=../pcre-8.32 --with-zlib=../zlib-1.2.8 --user=www --group=www --with-http_flv_module --with-http_stub_status_module --add-module=../nginx-rtmp-module
make && make install
初频配置nginx
vi /usr/local/nginx/conf/nginx.conf
默认配置
server {
listen 80;
server_name 10.65.160.102;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
启动nginx: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
客户端vlc打开网络串流中访问:http://10.65.160.102/文件名.m3u8
在windows上可以用vlc播放。
下面给2个超简单的执行例子
直接转成ts
ffmpeg -i vp5.flv -acodec copy -vcodec libx264 vp5.ts
分割转成ts 一秒为单位
ffmpeg -ss 0 -t 30 -i vp5.flv -acodec copy -vcodec libx264 1.ts
ffmpeg -ss 30 -t 60 -i vp5.flv -acodec copy -vcodec libx264 2.ts
合并
ffmpeg -i "concat:1.ts|2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4
切割
m3u8-segmenter -i test.ts -d 10 -p segmenter_test -m test.m3u8 -u http://127.0.0.1:8080/Video/
实际中,我下面命令做切片,没有任何报错。
点播切片:
ffmpeg -i cctv.ts -c copy -map 0 -f segment -segment_list /home/sunrc/cctv/cctv.m3u8 -segment_time 10 /home/sunrc/cctv/cctv%03d.ts
直播切片:(udp的暂且没试)vlc架设直播服务器,
客户端用vlc输入http://10.65.160.102/src.m3u8观看
ffmpeg -i rtsp://10.65.160.111:8554/1 -c copy -map 0 -f segment -segment_list /home/sunrc/zhibo/src.m3u8 -segment_time 10 /home/sunrc/zhibo/src%03d.ts
这样就可以切片出m3u8文件 直接使用hls
安装mpayer播放器(以此文无关,装着玩)
wget http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
yum install rpmfusion-free-release-6-1.noarch.rpm epel-release-6-8.noarch.rpm
yum -y install mplayer*
wget http://www1.mplayerhq.hu/MPlayer/releases/codecs/essential-20071007.tar.bz2
tar -xjvf essential-20071007.tar.bz2
cd /usr/local/lib/
mkdir codecs
cd /home/sunrc/
mv essential-20071007/* /usr/local/lib/codecs/
yum install mplayer-gui
gmplayer 运行
以下是网上查的命令,没测试明白,我装的hls有问题,以后慢慢查问题所在
点播:
生成hls分片:
ffmpeg -i <媒体文件> -c:v libx264 -c:a -f hls /usr/local/nginx/html/test.m3u8
直播:
ffmpeg -i udp://@:1234 -c:v libx264 -c:a -f hls /usr/local/nginx/html/test.m3u8
转载于:https://blog.51cto.com/sunrc/1565129
最后
以上就是大意火龙果为你收集整理的centos+ffmpeg安装配置+切片的全部内容,希望文章能够帮你解决centos+ffmpeg安装配置+切片所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复