欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

linux 安装系统部署ffmpeg视频转码环境及使用方法

linux系统部署ffmpeg视频转码环境及使用方法

方法/步骤

 
  1. 环境:CentOS 6.2 64位 CentOS 5.8 64位

    部署过程

    建立yum源文件

    cat << EOF > /etc/yum.repos.d/ffmpeg.repo

    [dag]

    name=Dag RPM Repository for Red Hat Enterprise Linux

    baseurl=http://apt.sw.be/redhat/el\$releasever/en/\$basearch/dag

    gpgcheck=0

    enabled=1

    EOF

    安装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

    部署完成lamp兄弟连

     

     

    以下是使用方法和以前遇到的问题及解决方法

    转码方法:(加水印)

    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

    提取影版时间方法:lamp兄弟连

    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



    来自 http://jingyan.baidu.com/article/e9fb46e19fb4137521f766c8.html


普通分类: