技术背景:
视频转码是把mpg格式转换为h264编码的flv文件,在linux平台使用开源转码工具ffmpeg,x264等。
操作步骤:
在centos6系统下,把需要的软件包,即附件的压缩文件,解压后为ffmpeg_sources/,放在/root目录下,然后运行脚本ffmpeg_install.sh,一键安装所有的软件和库文件。
安装过程会在目录下生成ffmpeg_install.log的日志文件,有没有安装成功,读日志。
或者按照顺序,首先yum安装依赖包,然后手动编译安装每一个软件,各个源码编译安装的顺序和步骤细节,请参照下面的脚本代码。
安装成功后,会在/root目录下面生成两个目录bin/和ffmpeg_build/,分别存放可执行文件和库文件。
安装完成之后,执行视频转码命令为:ffmpeg -i sourcefile.mpg -threads 4 -y -vcodec libx264 -ab 64 -ar 22050 -b 330000 -r 25 -s 722*406 objectfile.flv
shell脚本代码:(ffmpeg_install.sh)
#!/bin/bash dir_home=/root/ffmpeg_sources dir_fdk_aac=$dir_home/"fdk-aac" dir_ffmpeg=$dir_home/ffmpeg dir_lame=$dir_home/"lame-3.99.5" dir_libogg=$dir_home/"libogg-1.3.1" dir_libvorbis=$dir_home/"libvorbis-1.3.3" dir_libvpx=$dir_home/libvpx dir_opus=$dir_home/"opus-1.0.3" dir_x264=$dir_home/x264 dir_yasm=$dir_home/"yasm-1.2.0" chmod +x -R $dir_home ### Get the Dependencies ############ yum -y install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel if [ $? -eq 0 ];then echo "dependencis install SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "dependencis install FAILD!" >> $dir_home/ffmpeg_install.log exit fi ### Compilation & Installation ######## Yasm ############ cd $dir_home #curl -O http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz #tar xzvf yasm-1.2.0.tar.gz if [ -d $dir_yasm ];then echo "$dir_yasm is exist!" >> $dir_home/ffmpeg_install.log cd $dir_yasm ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" if [ $? -eq 0 ];then echo "configure successful!" >> $dir_home/ffmpeg_install.log make && make install && make distclean && . ~/.bash_profile && echo "yasm installed SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "configure faild!" >> $dir_home/ffmpeg_install.log exit fi else echo "$dir_yasm is not exist!" >> $dir_home/ffmpeg_install.log exit fi ######### x264 ########## #git clone --depth 1 git://git.videolan.org/x264 if [ -d $dir_x264 ];then echo "$dir_x264 is exist!" >> $dir_home/ffmpeg_install.log cd $dir_x264 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static if [ $? -eq 0 ];then echo "configure successful!" >> $dir_home/ffmpeg_install.log make && make install && make distclean && echo "x264 installed SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "configure faild!" >> $dir_home/ffmpeg_install.log exit fi else echo "$dir_x264 is not exist!" >> $dir_home/ffmpeg_install.log exit fi ########## libfdk_aac ######### #git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac if [ -d $dir_fdk_aac ];then echo "$dir_fdk_aac is exist!" >> $dir_home/ffmpeg_install.log cd $dir_fdk_aac autoreconf -fiv ./configure --prefix="$HOME/ffmpeg_build" --disable-shared if [ $? -eq 0 ];then echo "configure successful!" >> $dir_home/ffmpeg_install.log make && make install && make distclean && echo "libfdk_aac installed SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "configure faild!" >> $dir_home/ffmpeg_install.log exit fi else echo "$dir_fdk_aac is not exist!" >> $dir_home/ffmpeg_install.log exit fi ################ libmp3lame ###################### #curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz if [ -d $dir_lame ];then echo "$dir_lame is exist!" >> $dir_home/ffmpeg_install.log cd $dir_lame ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm if [ $? -eq 0 ];then echo "configure successful!" >> $dir_home/ffmpeg_install.log make && make install && make distclean && echo "lame installed SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "configure faild!" >> $dir_home/ffmpeg_install.log exit fi else echo "$dir_lame is not exist!" >> $dir_home/ffmpeg_install.log exit fi ########### libopus ############ #curl -O http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz #tar xzvf opus-1.0.3.tar.gz if [ -d $dir_opus ];then echo "$dir_opus is exist!" >> $dir_home/ffmpeg_install.log cd $dir_opus ./configure --prefix="$HOME/ffmpeg_build" --disable-shared if [ $? -eq 0 ];then echo "configure successful!" >> $dir_home/ffmpeg_install.log make && make install && make distclean && echo "libopus installed SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "configure faild!" >> $dir_home/ffmpeg_install.log exit fi else echo "$dir_opus is not exist!" >> $dir_home/ffmpeg_install.log exit fi ############# libogg ############ #curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz #tar xzvf libogg-1.3.1.tar.gz if [ -d $dir_libogg ];then echo "$dir_libogg is exist!" >> $dir_home/ffmpeg_install.log cd $dir_libogg ./configure --prefix="$HOME/ffmpeg_build" --disable-shared if [ $? -eq 0 ];then echo "configure successful!" >> $dir_home/ffmpeg_install.log make && make install && make distclean && echo "libogg installed SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "configure faild!" >> $dir_home/ffmpeg_install.log exit fi else echo "$dir_libogg is not exist!" >> $dir_home/ffmpeg_install.log exit fi ############## libvorbis ########## #curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz #tar xzvf libvorbis-1.3.3.tar.gz if [ -d $dir_libvorbis ];then echo "$dir_libvorbis is exist!" >> $dir_home/ffmpeg_install.log cd $dir_libvorbis ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared if [ $? -eq 0 ];then echo "configure successful!" >> $dir_home/ffmpeg_install.log make && make install && make distclean && echo "libvorbis installed SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "configure faild!" >> $dir_home/ffmpeg_install.log exit fi else echo "$dir_libvorbis is not exist!" >> $dir_home/ffmpeg_install.log exit fi ############### libvpx ################ #git clone --depth 1 http://git.chromium.org/webm/libvpx.git if [ -d $dir_libvpx ];then echo "$dir_libvpx is exist!" >> $dir_home/ffmpeg_install.log cd $dir_libvpx ./configure --prefix="$HOME/ffmpeg_build" --disable-examples if [ $? -eq 0 ];then echo "configure successful!" >> $dir_home/ffmpeg_install.log make && make install && make clean && echo "libvpx installed SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "configure faild!" >> $dir_home/ffmpeg_install.log exit fi else echo "$dir_libvpx is not exist!" >> $dir_home/ffmpeg_install.log exit fi ############### FFmpeg ######################## #git clone --depth 1 git://source.ffmpeg.org/ffmpeg if [ -d $dir_ffmpeg ];then echo "$dir_ffmpeg is exist!" >> $dir_home/ffmpeg_install.log cd $dir_ffmpeg PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" export PKG_CONFIG_PATH ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --extra-libs="-ldl" --enable-gpl -- enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 if [ $? -eq 0 ];then echo "configure successful!" >> $dir_home/ffmpeg_install.log make&& make install && make distclean && hash -r && . ~/.bash_profile && echo "ffmpeg installed SUCCESSFUL!" >> $dir_home/ffmpeg_install.log else echo "configure faild!" >> $dir_home/ffmpeg_install.log exit fi else echo "$dir_ffmpeg is not exist!" >> $dir_home/ffmpeg_install.log exit fi