環境:CentOS 6.2 64位 CentOS 5.8 64位linux
部署過程c++
創建yum源文件vim
cat << EOF > /etc/yum.repos.d/ffmpeg.reporuby
[dag]ide
name=Dag RPM Repository for Red Hat Enterprise Linuxsvn
baseurl=http://apt.sw.be/redhat/el\$releasever/en/\$basearch/dagpost
gpgcheck=0ui
enabled=1atom
EOFurl
安裝ffmpeg及開發包
yum install gcc gmake make libcpp libgcc libstdc++ gcc4 gcc4-c++ gcc4-gfortran subversion ruby ncurses-devel ffmpeg ffmpeg-devel mencoder -y
驗證安裝
輸入命令:ffmpeg (出現如下提示則安裝正常)
FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
built on Dec 4 2010 09:30:59 with gcc 4.4.4 20100726 (Red Hat 4.4.4-13)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
libavutil 50.15. 1 / 50.15. 1
libavcodec 52.72. 2 / 52.72. 2
libavformat 52.64. 2 / 52.64. 2
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.19. 0 / 1.19. 0
libswscale 0.11. 0 / 0.11. 0
libpostproc 51. 2. 0 / 51. 2. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
###############################################################################
添加水印功能:
下載:
svn co svn://svn.ffmpeg.org/ffmpeg/trunk /usr/local/src/ffmpeg
svn co svn://svn.ffmpeg.org/soc/libavfilter /usr/local/src/libavfilter
或者在相關軟件包中找到這兩個軟件包,是從svn下載好後,打包下來的
而後:
cp /usr/local/src/libavfilter/vsrc_movie.c /usr/local/src/ffmpeg/libavfilter/
修改這個文件,並添加如下二行內容:
vim /usr/local/src/ffmpeg/libavfilter/allfilters.c
REGISTER_FILTER (OVERLAY, overlay, vf);
REGISTER_FILTER (MOVIE, movie, vsrc);
修改這個文件,並添加如下二行:
vim /usr/local/src/ffmpeg/libavfilter/Makefile
OBJS-$(CONFIG_OVERLAY_FILTER) += vf_overlay.o
OBJS-$(CONFIG_MOVIE_FILTER) += vsrc_movie.o
加入二個軟件:
yum install xvidcore xvidcore-devel yasm -y
進入ffmpeg目錄,從新編譯安裝:
cd /usr/local/src/ffmpeg
./configure --prefix=/usr --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libmp3lame --enable-libx264 --disable-ffplay --enable-shared --enable-libmp3lame --enable-gpl --enable-pthreads --enable-libfaac --enable-postproc --enable-x11grab --enable-libgsm --enable-libx264 --enable-swscale --enable-nonfree --enable-avfilter --disable-yasm
make
make test
make tools/qt-faststart
cp -a tools/qt-faststart /usr/bin/
打開ld.so.conf文件,添加一行:
vim /etc/ld.so.conf
/usr/bin/qt-faststart
執行:
ldconfig
部署完成
如下是使用方法和之前遇到的問題及解決方法
轉碼方法:(加水印)
ffmpeg -i "/AA/1.mov" -vf "movie=0:png:umelook.png [wm];[in][wm] overlay=20:20:1 [out]" -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow –s 512x288 –r 25 -crf 22 -threads 0 222.mp4
提取影版時間方法:
ffmpeg -i "/root/test.wmv" 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//
ffmpeg -i "7369.rmvb" 2>&1 | grep 'Duration' |awk -F '[ .]+' '{print $3}'
影片截圖方法:
/usr/bin/ffmpeg -ss 00:00:23 -t 00:00:01 -i 1920x1080.mp4 -s 120x90 -r 1 -f mjpeg 20000.jpg
注:
/root/test.wmv 是待轉碼的電影源文件
logo.png是水印圖片,須要指定路徑,不然找不到該圖片
overlay=5:5:1是水印在影片中的位置,從左上角算起,像素,1是透明度
222.mp4是轉成後的mp4電影
-s 512x288:指定分辨率
-r 25:指定幀速率
-ab 128K:指定音頻碼率
-ac 2:指定雙音道
用yum安裝的各類參數
--prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libschroedinger --enable-libtheora --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab --disable-yasm --enable-libopencore-amrwb --enable-libopencore-amrnb
因ffmpeg轉碼成mp4後,把mate data移到了視頻尾部,所以網上看這視頻的時候,須要在線下載完成後才能播放,但咱們能夠用qt-faststart功能,把mata data移到頭部。
修復MP4文件mata dtat信息頭,從尾部移到頭部的相關信息:
信息一:
To install the qt-faststart with ffmpeg refer to the following steps but make sure that you have logged in as a root user.
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
If you receive the following 「Connection timed out」 error message then pelase disable the firewall for installation.
Time out error
Now follow the steps one one by one
cd ffmpeg
./configure
make
make test
make tools/qt-faststart
cp -a tools/qt-faststart /usr/bin/
Now check the qt-faststart path
root@linux7802 [~/ffmpeg]# which qt-faststart
/usr/bin/qt-faststart
執行方式:qt-faststart 源文件名 目標文件名
安裝好後,默認會執行失敗,如提示如下信息:
last atom in file was not a moov atom
請接着看信息二
信息二:
I found the problem. When qt-faststart was installed, it was copied with the name /usr/local/bin/ldconfig , so when you executed ldconfig in fact qt-faststart was been run, which obviously didn't help to fix the shared library issue Renaming the /usr/local/bin/ldconfig to /usr/local/bin/qt-faststart made that the correct ldconfig could be invoked and fixed the missing .so issue.
解決方法:
打開ld.so.conf文件,添加一行:
vim /etc/ld.so.conf
/usr/bin/qt-faststart
執行:
ldconfig