FFMPEG
May 31st, 2006 by song

This tutorial is about transcoding video fom one codec into another using
[url=http://ffmpeg.org/]FFMPEG[/url]
. I got deeper into FFMPEG when I wanted to transcode into FLV (Flash Video) and it works very well. I developed the
[url=http://rivavx.de/?encoder]Riva FLV Encoder[/url]
, a GUI for FFMPEG.


We install the Minimalist GNU for Windows MinGW (Compiler) and MSYS (Minimal SYStem) which is a kind of unix-shell to access the MinGW-commands. Next we download, compile and install Lame, an open-source mp3-codec, with MSYS. Next we install WinCVS and checkout the latest cvs-release of FFMPEG. Finally we compile ffmpeg and I will show a few examples how to work with Flash Video (FLV).



  1. Download
    [url=http://www.mingw.org/]MinGW ” MSYS current releases[/url]
    (Window Exe Binaries MSYS-1.0.10.exe & MinGW-3.1.0-1.exe)
      Install MinGW

      Install MSYS

      HINT: During the Postinstall be sure to set the right path to MinGW with a “/” instead of a Windows-”". If you did it wrong anyway re-install MSYS to the same directory and do the postinstall right (I missed it a few times)

  2. Download and compile
    [url=http://lame.sourceforge.net/download/download.html]Lame[/url]

      Extract Lame to your MSYS home-directory

      Open MSYS and change to your lame-directory (cd ../lame-XXX)

      Enter the following commands:


      [b]CODE:[/b]




      1. ./configure //(takes a few minutes)
      2. make //(lame is being comiled; takes a few minutes, too)
      3. make install

      After installing you will recognize that there are new directories and files in MSYS/local which we will use while compiling ffmpeg with mp3-support

  3. Download WinCVS (http://www.wincvs.org) and install it
      Open the Command-Line window (CTRL-L) and enter the command:

      [b]CODE:[/b]




      1. cvs -z9 -d:pserver:anonymous@mplayerhq.hu:/cvsroot/ffmpeg co ffmpeg

      Select “Execute for directory” and browse to you MSYS-Directory and select your home-directory (“home”)

      Press “OK” and the current cvs release will be checked out into your home-directory


    • Compile FFMPEG
        Change the directory in MSYS to your ffmpeg-directory (cd ../ffmpeg)

        Enter the command:


        [b]CODE:[/b]




        1. ./configure –enable-memalign-hack –enable-mingw32 –enable-mp3lame –extra-cflags=-I/local/include –extra-ldflags=-L/local/lib

        HINT: you can paste into MSYS by pressing your center mouse-button


      1. “–enabled-memalign-hack” is a Windows hack. Without this option ffmpeg always crashs with the message “removing common factors from framerate” when encoding AVIs.
      2. “–enable-mingw32″. I see no difference without it but we compile with MinGW and it would not do a harm when ffmpeg knows this
      3. “–enable-mp3lame”: Enable transcoding audio with the open-source mp3-lame-codec
      4. “–extra-cflags=-I/local/include –extra-ldflags=-L/local/lib”: The cflags- and ldflags-parameter sets the right path to your lame-installation which you did in step 3.d.

        Enter command: make (ffmpeg is being compiled; takes a few minutes)

        With “make install” you could now copy the ffmpeg.exe to c:Program Filesffmpeg. But there is no need to.

    • Use FFMPEG
        Copy your compiled ffmpeg.exe from your MSYS directory to the directory where you like to transcode with ffmpeg

        Open the Dos-Shell and change to the directory where you copied the ffmpeg.exe

        Copy a test.mpg into your directory and enter the following command:


        [b]CODE:[/b]




        1. ffmpeg -i test.mpg -ab 56 -ar 22050 -b 500 -r 15 -s 320×240 test.flv

        Your first FLV should be encoded now

    • Render Images from a Video
        Enter command:


        [b]CODE:[/b]




        1. ffmpeg -an -y -t 0:0:0.001 -i test.flv -f image2 test%d.jpg

        HINT: With -t you set the length of images to be extracted. Above we entered 1 millisecond the extract one image. If you miss this parameter all images of the video will be extracted




    [b]ZLib Support[/b] (e.g. for TSCC and Quicktime codecs). This should be compiled into FFMPEG. It is not an explicit compile in the configure statement. Do the following steps and after configure you should see that zlib is “on”.

    [url=http://www.gzip.org/zlib]Download[/url]
    and compile ZLib
    Extract the files to your mysys directory
    Change the directory in MSYS to that directory
    Enter command ./confugure, make and make install.


    [b]CODE:[/b]




    1. cp /local/lib/libz.a /mingw/lib/.
    2. cp /local/include/zlib.h /mingw/include/.
    3. cp /local/include/zconf.h /mingw/include/.

    [b]AC3 Support[/b]
    Add “–enable-a52 –enable-gpl” to your configure command


    [b]3GP Support[/b]
    If you want to enable 3GP support you have to add the AMR audio codec. Download the TS26.104
    REL-5 V5.1.0 26104-5??.zip
    [url=http://www.3gpp.org/ftp/Specs/latest/Rel-5/26_series]here[/url]
    . Extract the codec into libavcodec/amr_float and add “–enable-amr_nb” to your configure command


    [b]XVID Support[/b] (thanks to garvin.thornten at datel.co.uk)
    Download and install the codec from
    [url=http://www.xlib.org/]www.xlib.org[/url]
    (see xvidcore-xxxx/doc/install). Add “–enable-xvid –enable-gpl” to your configure command. When compiling with xvid codec in MinGW or cygwin you will get a “mkstemp” error when compiling “xvidff.c”. To fix this edit “libavcodec/xvidff.c” and add the following after the #includes. This will probably be fixed in a future ffmpeg release: ´


    [b]C:[/b]




    1. /* Added for windows compile —————– */
    2. #include
    3.        
    4. int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2); void xvid_correct_framerate(AVCodecContext *avctx);

    5. int mkstemp(char* template)
    6. {
    7.  char temppath[512];
    8.  if(GetTempPath(512,temppath)!=0)
    9.  {
    10.    if(GetTempFileName(temppath,“fil”,0,template)!=0)
    11.    {
    12.      FILE *pFile;
    13.      pFile=fopen(template,“w+”);
    14.      if(pFile!=NULL)
    15.        return (int)pFile;
    16.    }
    17.  }
    18.  return -1;
    19. }
    20. /* ——————————————- */

    Link about
    [url=http://qstream.org/usage.html]qscale[/url]

    removed “-f singlejpeg” as its identical to “-f mjpeg”


    No Responses  
    • song writes:
      May 31st, 20062:58 pmat

      ffmpeg参数设定解说
      -bitexact 使用标准比特率
      -vcodec xvid 使用xvid压缩
      -s 320×240 指定分辨率
      -r 29.97 桢速率(可以改,确认非标准桢率会导致音画不同步,所以只能设定为15或者29.97)
      画面部分,选其一
      -b <比特率> 指定压缩比特率,似乎ffmpeg是自动VBR的,指定了就大概是平均比特率,比如768,1500这样的就是原来默认项目中有的
      -qscale <数值> 以<数值>质量为基础的VBR,取值0.01-255,约小质量越好
      -qmin <数值> 设定最小质量,与-qmax(设定最大质量)共用,比如-qmin 10 -qmax 31
      -sameq 使用和源同样的质量

      声音部分
      -acodec aac 设定声音编码
      -ac <数值> 设定声道数,1就是单声道,2就是立体声,转换单声道的TVrip可以用1(节省一半容量),高品质的DVDrip就可以用2
      -ar <采样率> 设定声音采样率,PSP只认24000
      -ab <比特率> 设定声音比特率,前面-ac设为立体声时要以一半比特率来设置,比如192kbps的就设成96,转换君默认比特率都较小,要听到较高品质声音的话建议设到160kbps(80)以上
      -vol <百分比> 设定音量,某些DVDrip的AC3轨音量极小,转换时可以用这个提高音量,比如200就是原来的2倍

      这样,要得到一个高画质音质低容量的MP4的话,首先画面最好不要用固定比特率,而用VBR参数让程序自己去判断,而音质参数可以在原来的基础上提升一点,听起来要舒服很多,也不会太大(看情况调整)


    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    SIDEBAR
    »
    S
    I
    D
    E
    B
    A
    R
    «
    »  Substance:WordPress   »