LinkShare rotating banner
Showing posts with label encoder. Show all posts
Showing posts with label encoder. Show all posts

Wednesday, September 5, 2012

To Compile ffmpeg with MinGW

ffmpeg is an important component of many open-source projects, such as MPlayer and VLC. I am compiling ffmpeg so that I can use it to transcode multimedia files. This guide shows how to use MinGW to compile ffmpeg either statically or dynamically. Installation of MinGW is explained in this post. The example commands below are meant to be entered into an MSYS window (not Command Prompt). I downloaded the FFmpeg source and unpacked it.



Preparing External Libraries for FFMpeg


FFMpeg can be linked with external libraries to add features to FFmpeg. I am adding most features to FFMpeg by compiling additional libraries. Most of these libraries are also covered in my posts on compiling MPlayer and Mencoder.




  1. Compression Libraries: Zlib and bzLib

    Get the zlib source (zlib127.zip), unzip and compile it:

    unzip zlib127.zip
    cd zlib-1.2.7/
    make -f win32/Makefile.gcc
    cp -iv zlib1.dll /mingw/bin
    cp -iv zconf.h zlib.h /mingw/include
    cp -iv libz.a /mingw/lib
    cp -iv libz.dll.a /mingw/lib


    Optionally, get bzip2 source from bzip.org and compile it like this:


    tar xzvf bzip2-1.0.6.tar.gz
    cd bzip2-1.0.6
    make
    cp bzlib.h /mingw/include/
    cp libbz2.a /mingw/lib


  2. libgsm

    Download gsm-1.0.13.tar.bz2, unpack and compile it as follows:

    tar xzvf gsm-1.0.13.tar.bz2
    cd gsm-1.0-pl13/
    make

    Just ignore the compile errors with fchmod and fchown when trying to build applications. Copy the header and static library to /mingw:


    mkdir /mingw/include/gsm
    cp inc/gsm.h /mingw/include/gsm
    cp lib/libgsm.a /mingw/lib


  3. LAME is an excellent MP3 encoder. LAME makes use of the nasm assembler if available. So download yasm and save it as /mingw/bin/nasm.exe. Then, download the LAME source from lame.sf.net and compile it like this.

    ./configure --prefix=/mingw --enable-expopt=full

    make

    make install


  4. OGG, Vorbis, Speex and Theora

    The source code for these libraries can be obtained from xiph.org. Compile them each like this:


    ./configure --prefix=/mingw
    make
    make install

    As for speex, use the version 1.2rc1 or later.



  5. FAAC

    FAAC is an MPEG-4 AAC audio encoder. Get the source (faac-1.28.tar.gz) and unpack the package. Then, edit Makefile.am:

    SUBDIRS = include libfaac

    Also, edit the line beginning with AC_OUTPUT in the file configure.in:

    AC_OUTPUT(libfaac/Makefile include/Makefile Makefile)

    Then, compile FAAC like this

    sh bootstrap
    ./configure --prefix=/mingw
    make
    make install


  6. XviD is a popular video encoder used to create movie files distributed in p2p networks. Xvid can use yasm assembler to build optimized binaries if found (/mingw/bin/yasm.exe). Get the XviD source from xvid.org and compile as follows:

    tar xzvf xvidcore-1.3.2.tar.gz
    cd xvidcore/build/generic
    ./configure --prefix=/mingw
    make
    make install


    If you encounter "unrecognized command-line option -mno-cygwin" errors, open the file platform.inc in a text editor and delete "-mno-cygwin". Then, run make and make install again.



    Copy the import library for xvidcore.dll:


    cp -iv \=build/xvidcore.dll.a /mingw/lib/libxvidcore.a


  7. x264 is yet another good video encoder. x264 requires YASM to build an optimized executable. So get yasm and save it as /mingw/bin/yasm.exe. Then, compile x264 like this:

    configure --prefix=/mingw --enable-win32thread --extra-cflags="-DX264_VERSION=20100422"

    make

    make install

    cp -iv x264.h x264_config.h /mingw/include

    cp -iv libx264.a /mingw/lib

    cp -iv x264.pc /mingw/lib/pkgconfig


  8. Compile librtmp as shown in this post.



Building FFMpeg Statically


You need pr.exe from MYS coreutils package (coreutils-5.97-3-msys-1.0.13-ext.tar.lzma). I configured ffmpeg with the following command:


CPPFLAGS='-DHAVE_INT32_T' ./configure --prefix=/mingw --enable-gpl --enable-nonfree --enable-postproc --enable-avfilter --enable-w32threads --enable-runtime-cpudetect --enable-memalign-hack --enable-bzlib --enable-libfaac --enable-libgsm --enable-libmp3lame --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-zlib --disable-debug

-DHAVE_INT32_T is used to allow static FAAC to be linked. Then, I began compilation and installation:


make
make install


Compiling FFmpeg Dynamically


Some Windows applications, such as Audacity, uses FFmpeg libraries when available. If you want to compile FFmpeg dynamically, append --enable-shared --disable-static to the ./configure command for FFmpeg.


./configure --prefix=/mingw --enable-gpl --enable-nonfree --enable-postproc --enable-avfilter --enable-w32threads --enable-runtime-cpudetect --enable-memalign-hack --enable-bzlib --enable-libfaac --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-zlib --enable-shared --disable-static --disable-debug


If you get "int32_t" error when compiling libfaac.o, open /mingw/include/faac.h and insert the following line:


#include <stdint.h>


When I built mplayer with --enable-static and --disable-ffmpeg_a options to force linking with shared ffmpeg libraries, I had to rename ffmpeg libraries so their names end in *.a.


cd /mingw/lib
cp -iv libavcodec.dll.a libavcodec.a
cp -iv libavformat.dll.a libavformat.a
cp -iv libavutil.dll.a libavutil.a
cp -iv libpostproc.dll.a libpostproc.a
cp -iv libswscale.dll.a libswscale.a

Sunday, May 16, 2010

Using Mencoder To Merge AVI Files

Merging 2 AVI files can be easily accomplished with mencoder. But the two AVI files must be encoded with the same video and audio codec. Assuming that you have part1.avi and part2.avi, seamlessly consecutive, the mencoder command to concatenate them is:


mencoder -ovc copy -oac copy -o whole.avi part1.avi part2.avi

Saturday, April 24, 2010

MinGW: To Compile Vorbis Tools

Vorbis tools include oggenc and vorbiscomment that can be used to produce Ogg-Vorbis music files. Ogg Vorbis provides people with free, open-source audio format and encoding algorithm. Because the MP3 algorithm is patented and creating MP3 exposes people to legal risks, use of the Ogg Vorbis format is a reasonable choice for legally conscious people. Besides its openness and patent-free characteristics, Ogg Vorbis offers good compression and sound quality, comparable to MP3 and AAC. Therefore, everyone is recommended to create, use and spread Ogg Vorbis music files, instead of MP3 and AAC.



To learn how to prepare a MinGW environment, read this post. Then, download the source for libogg, libvorbis and vorbis-tools from xiph.org.





To build Vorbis tools, libogg and libvorbis should be compiled first. Start the MinGW rxvt console from the Start menu. Unpack the libogg source and compile it as follows:



tar xzvf libogg-1.2.0.tar.gz
cd libogg-1.2.0/
./configure --prefix=/mingw
make
make install


libvorbis can be compiled likewise:



tar xzvf libvorbis-1.3.1.tar.gz
cd libvorbis-1.3.1/
./configure --prefix=/mingw
make
make install


Then, build vorbis-tools as follows:



tar xzvf vorbis-tools-1.4.0.tar.gz
cd vorbis-tools-1.4.0/
./configure --prefix=/mingw --disable-nls --enable-threads=win32
make
make install


When done, the following files are created in /mingw/bin:



libogg-0.dll
libvorbis-0.dll
libvorbisenc-2.dll
libvorbisfile-3.dll
oggdec.exe
oggenc.exe
ogginfo.exe
vorbiscomment.exe


Copy these files whereever you want. To create an Ogg Vorbis file from a .WAV file, use a command like this:



oggenc -q5 audio.wav


Related Posts


Friday, April 9, 2010

MinGW: Building TwoLAME

TwoLAME is MPEG-2 audio encoder. First, compile libsndfile which is used is read sound files in various formats.


tar xzvf libsndfile-1.0.21.tar.gz
cd libsndfile-1.0.21/
./configure --prefix=/mingw --disable-shared --enable-static
make
make install

Then, build twolame.


tar xzvf twolame-0.3.12.tar.gz
cd twolame-0.3.12/
./configure --prefix=/mingw CPPFLAGS='-DLIBTWOLAME_STATIC'
make
make install

When linking a program with a static TwoLAME library, define LIBTWOLAME_STATIC with CPPFLAGS.


CPPFLAGS=' -DLIBTWOLAME_STATIC' ./configure --enable-static --enable-twolame

MinGW: MPlayer와 Mencoder 동적 컴파일하기

MinGW의 GCC 컴파일러를 사용하여 Windows용 MPlayer와 Mencoder를 컴파일해 보자. MPlayer는 동영상을 보는 프로그램이고 Mencoder는 동영상이나 음악을 인코딩하는 프로그램이다. 예전에는 정적으로 컴파일하였지만 이번에는 동적으로 컴파일해 보자.


우선 MinGW를 설치한다. MPlayer는 FFmpeg 라이브러리에 의존하므로 먼저 FFmpeg 라이브러리를 동적으로 컴파일하도록 한다.


시작 메뉴를 열어 MinGW (rxvt)를 실행한다. 노란 창이 나타날 것이다. 그럼 다음과 같이 MPlayer와 의존 라이브러리를 컴파일하자.



  1. LZO 압축 라이브러리 컴파일 (옵션)

    tar xzvf lzo-2.03.tar.gz
    cd lzo-2.03/
    ./configure --prefix=/mingw
    make
    make install


  2. Fribidi 라이브러리 컴파일 (옵션)

    Fribidi는 아랍어와 히브리어의 표시에 필요하다. 솔직히 이 기능은 빠뜨려도 된다.

    tar xzvf fribidi-0.19.2.tar.gz
    cd fribidi-0.19.2/
    ./configure --prefix=/mingw --disable-debug
    make
    make install

    자세한 내용은 Fribidi에 관한 글을 참조.

  3. giflib 라이브러리 컴파일 (옵션)

    tar xjvf giflib-4.1.6.tar.bz2 
    cd giflib-4.1.6/
    ./configure --prefix=/mingw
    make
    make install


  4. Live555 라이브러리 컴파일 (권장)

    Live 라이브러리는 인터넷 동영상을 보는 데 쓰인다. live555.com에서 최신 버전을 받아 다음과 같이 컴파일한다:

    export CC=/mingw/bin/gcc.exe
    cd /mingw/lib/
    tar xzvf live.2010.04.01.tar.gz
    cd live/
    ./genMakefiles mingw
    make


  5. JPEG 라이브러리 컴파일 (권장)

    tar xzvf jpegsrc.v8a.tar.gz
    cd jpeg-8a/
    ./configure --prefix=/mingw
    make
    make install


  6. PNG 라이브러리 컴파일 (권장)

    tar xzvf libpng-1.4.1.tar.gz 
    cd libpng-1.4.1
    ./configure --prefix=/mingw
    make
    make install


  7. FreeType 라이브러리 컴파일 (필수)

    자막 표시에 필요하다.

    그리고 Freetype를 컴파일한다.

    tar xzvf freetype-2.3.12.tar.gz 
    cd freetype-2.3.12/
    ./configure --prefix=/mingw
    make install


  8. 만일 iconv 라이브러리가 설치되어 있지 않다면 컴파일한다. libXML2 그리고 fontconfig 에 필요하다.

  9. libXML2 컴파일

    만약에 fontconfig 라이브러리를 컴파일하려면 필요하다. 먼저 testThreads.c를 고친다.

    --- testThreads.c.orig  2009-09-11 18:09:00.268640135 +0200
    +++ testThreads.c 2009-09-11 18:12:43.412653512 +0200
    @@ -107,7 +107,7 @@

    for (i = 0; i < num_threads; i++) {
    results[i] = NULL;
    - tid[i] = (pthread_t) -1;
    + memset(&tid[i], 0, sizeof(pthread_t));
    }

    for (i = 0; i < num_threads; i++) {

    그리고 컴파일한다:


    ./configure --prefix=/mingw
    make install


  10. Fontconfig 라이브러리 컴파일 (권장)

    SSA 자막 표시에 필요하다.

    tar xzvf fontconfig-2.8.0.tar.gz 
    cd fontconfig-2.8.0/
    ./configure --prefix=/mingw
    make install


  11. Libcdio 컴파일 (옵션)

    tar xzvf libcdio-0.83.tar.gz 
    cd libcdio-0.83/
    ./configure --prefix=/mingw
    make
    make install


  12. Libdca 컴파일 (권장)

    tar xjvf libdca-0.0.5.tar.bz2 
    cd libdca-0.0.5/
    ./configure --prefix=/mingw
    make install


  13. DirectX 7 라이브러리 추출 (권장)

    cd /mingw/include/
    tar xzvf dx7headers.gz


  14. MPlayer, Mencoder 컴파일

    ffmpeg 소스를 받아서 mplayer 소스 디렉토리에 넣는다.

    tar xjvf mplayer-export-snapshot.tar.bz2

    cd mplayer-export-2011-11-25/

    tar xjvf ffmpeg-snapshot.tar.bz2

    CPPFLAGS='-DWIN32 -DHAVE_INT32_T' ./configure --prefix=/mingw --enable-runtime-cpudetection --enable-theora --enable-fribidi --disable-ffmpeg_a --yasm=/mingw/bin/yasm

    MPlayer를 컴파일하기 전에 config.mak를 텍스트 에디터(notepad.exe)로 수정한다.

    EXTRALIBS_MPLAYER  = -lgdi32 -lopengl32 -lwinmm -lfaac -lx264 -lmp3lame -lfribidi
    EXTRALIBS_MENCODER = -lfaac -lx264 -lfribidi -lmp3lame

    MPlayer 컴파일 시작한다.

    make

  15. MPlayer.exe와 Mencoder.exe를 복사한다.

    strip mencoder.exe mplayer.exe
    cp -iv m*.exe /mingw/bin

Friday, April 2, 2010

MP4Box Usage

To package a MPEG-4 Video


Wrap up the raw H.264 video along with chapters inside a MPEG-4 container.


MP4Box -add video.264 -chap chapters.txt -fps 23.976 film.m4v


To Find Info on the First Track inside a .M4V file


MP4Box -info 1 movie.m4v


To Extract H.264 Video from a .M4V file


MP4Box -raw 1 movie.m4v


To Extract AAC audio from M4A file


Use MP4Box to extract AAC audio from a .M4A file like this:


MP4Box -raw 1 music.m4a

About This Blog

KBlog logo This blog seeks to share useful information on freely available fonts on the Internet. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

CyberChimps Professional WordPress Themes
Powered By Blogger