最近研究关于视频服务器在线转换,以前都是用的windows,自己写过一个小工具,进行实时转换视频,现在切换到linux环境中,所以win32的程序就报废了,所以研究了一下linux监控的问题。但是自己对linux下的shell脚本实在不熟,弄了好久才弄好,现在说明一下我的配置过程吧。
首先安装ffmpeg及相关解码器
#1、lame-3.97.tar.gz
wget http://sourceforge.net/project/showfiles.php?group_id=290&package_id=309
tar -zxvf lame-3.97.tar.gz
cd lame-3.97
./configure –enable-shared –prefix=/usr
make
make install
#2、libogg libogg-1.1.3.tar.gz
wget http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
./configure –prefix=/usr
make
make install
#3、libvorbis libvorbis-1.1.2.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.1.2.tar.gz
./configure –prefix=/usr
make
make install
#4、xvid xvidcore-1.1.3.tar.gz
wget http://downloads.xvid.org/downloads/xvidcore-1.1.3.tar.gz
tar zvxf xvidcore-1.1.3.tar.gz
cd xvidcore-1.1.3/build/generic
./configure –prefix=/usr
make
make install
#5、x264 x264-snapshot-20071107-2245.tar.bz2
#Url:http://www.videolan.org/developers/x264.html
#要压hq1080,ipod和psp影片,x264是少不了的,需要安装x264,就需要yasm来编译
wget http://www.tortall.net/projects/yasm/releases/yasm-0.8.0.tar.gz
./configure –prefix=/usr/local/yasm
make;make install
export PATH="$PATH:/usr/local/yasm/bin"
vi /etc/profile
export PATH="$PATH:/usr/local/yasm/bin"
wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20090428-2245.tar
bunzip2 x264-snapshot-20090428-2245.tar
tar xvf x264-snapshot-20090428-2245.tar
cd x264-snapshot-20090428-2245
./configure –prefix=/usr –enable-shared
make
make install
#6、libdts libdts-0.0.2.tar.gz
wget http://download.videolan.org/pub/videolan/libdca/0.0.2/libdca-0.0.2.tar.gz
tar zxvf libdts-0.0.2.tar.gz
cd libdts-0.0.2
./configure –prefix=/usr
make
make install
#7、a52 a52dec-0.7.4.tar.gz
#http://liba52.sourceforge.net/downloads.html
wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
./configure –prefix=/usr
make
make install
#8、faad2 faad2-2.6.1.tar.gz
#http://www.audiocoding.com/downloads.html
wget http://downloads.sourceforge.net/faac/faad2-2.7.tar.gz
autoreconf -vif
./configure –prefix=/usr –with-mp4v2 –enable-shared
make
make install
9、faac faac-1.26.tar.gz
#http://linux.softpedia.com/progDownload/FAAC-Download-554.html
wget http://nchc.dl.sourceforge.net/sourceforge/faac/faac-1.26.tar.gz
tar zxvf faac-1.26.tar.gz
cd faac
./bootstrap
./configure –prefix=/usr
make
make install
#10、amr-nb amrnb-6.1.0.4.tar.bz2
wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-6.1.0.4.tar.bz2
tar xvf amrnb-6.1.0.4.tar.bz2
cd amrnb-6.1.0.4
./configure –prefix=/usr
make
make install
#11、amr-wb amrwb-7.0.0.1.tar.bz2
wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-7.0.0.1.tar.bz2
tar xvf amrwb-7.0.0.1.tar.bz2
cd amrwb-7.0.0.1
./configure –prefix=/usr
make
make install
如果前面的安装一切顺利的话,恭喜你,可以安装ffmpeg了
wget http://www.ffmpeg.org/releases/ffmpeg-0.5.tar.bz2
tar vxf ffmpeg-0.5.tar.bz2
cd ffmpeg-0.5
./configure –prefix=/usr –enable-gpl –enable-shared –enable-libmp3lame –enable-libvorbis –enable-libamr-nb –enable-libamr-wb –enable-libxvid –enable-libx264 –enable-libfaac –enable-libfaad –enable-libfaadbin –enable-pthreads –disable-ffserver –disable-ffplay –enable-nonfree
make
make install
或者使用svn
不支持svn可以安装
wget http://subversion.tigris.org/downloads/subversion-1.3.2.tar.gz
tar zvxf subversion-1.3.2.tar.gz
cd subversion-1.3.2
./configure –with-apr=/usr/local/apr-httpd –with-apr-util=/usr/local/apr-util-httpd/
make
make install
svn://svn.mplayerhq.hu/ffmpeg/trunk /usr/local/src/ffmpeg
cd /usr/local/src/ffmpeg
./configure –prefix=/usr –enable-gpl –enable-shared –enable-libmp3lame –enable-libvorbis –enable-libamr-nb –enable-libamr-wb –enable-libxvid –enable-libx264 –enable-libfaac –enable-libfaad –enable-libfaadbin –enable-pthreads –disable-ffserver –disable-ffplay –enable-nonfree
转换实例:
/usr/bin/ffmpeg -vhook "/usr/lib/vhook/watermark.so -m 1 -t 222222 -f /var/www/1.jpg" -i "7.wmv" -vcodec libx264 -y -ab 32 -ar 22050 -b 800000 -s 640*480 7.flv
上面是个转换flv的命令格式,vhook是加水印
/usr/bin/ffmpeg -vhook "/usr/lib/vhook/watermark.so -m 1 -t 222222 -f /var/www/1.jpg" -i "7.wmv" -vcodec libx264 7.mp4
下面这个是转换mp4的用h264压制。
再次要下载inotify-tools
这是个实时监控的工具。首先下载,地址在
http://inotify-tools.sourceforge.net/
*安装
tar zxvf inotify-tools-3.13.tar.gz
cd inotify-tools-3.13
./configure –prefix=/usr/local/inotify
make
make install
安装完成只有会在
/usr/local/inotify/bin/有两个文件
下面开始写监控的脚本
使用监控的命令格式是
/usr/local/inotify/bin/inotifywait -mrq -e create,move,delete,modify /var/soft
其中参数
-m 是保持一直监听
-r 是递归查看目录
-q 是打印出事件~
-e create,move,delete,modify
监听 创建 移动 删除 写入 事件
然后我们开始组合写监控脚本
vi ffmpeg.sh
#!/bin/sh
/usr/local/inotify/bin/inotifywait -mrq -e create,modify /var/soft | while read A B C;do #返回值赋值给A B C,分别代表文件路径,操作,文件名
>finfo=$A$C #文件全路径
>ext=`echo $finfo|cut -d. -f2` #读取文件后缀名,-d为分隔符,-f是选取第几段
>newfile=`echo $finfo|cut -d. -f1`
>if [ "$ext" = "wmv" ] ; then #这里要特别注意,[]两边一定保留空格,否则语法错误
>/usr/bin/ffmpeg -vhook "/usr/lib/vhook/watermark.so -m 1 -t 222222 -f /var/www/1.jpg" -i "$finfo" -vcodec libx264 "$newfile.mp4"
>fi
>done
ok,完成。加入自启动嘛,我就不说了。