Cross-compiled FFMPEG windows SDK Based on Ubuntu

Source: Internet
Author: User

Preface

FFmpegIt is an open-source and cross-platform audio and video solution that integrates collection, transcoding, and streaming.LibavcodecCodec Module andLibavformatThe media format module supports very rich codec formats and container encapsulation formats. It is a project that must be mastered and referenced for media development. Customizing and compiling FFmpeg is a matter of time for streaming media development. It is relatively simple on the Linux platform and it is quite troublesome on the Windows platform. The purpose of this article is to introduce in detail how to compile and customize FFMPEG Based on the Ubuntu cross-compiling environment.

 

I. Overview

FFmpeg is mainly developed based on Linux. Of course it also supports windows, but does not support Visual Studio series IDE (because it uses a large number of c99 features, vs does not support c99 ), therefore, to use it on Windows, you must compile it through mingw or cygwin, or build a Windows cross-compiling environment on Linux. The latter should be simpler. There is a website. Let's take a look at it first. If it is compiled to meet your needs (it seems that it was not added to libfaac at the time of last reading, but you do not know it now), and you are too lazy to compile it, you can use it. If you are not familiar with Linux, you may not want to continue reading it. Do not worry. Ubuntu is easy to install and use. You can simply use it in a virtual machine. During compilation, you only need to use a few simple commands.

 

2. Environment preparation

1.Ubuntu LinuxInstall Ubuntu 11.10 onVMware WorkstationMedium

2.Mingw compilation environmentThanks very much, zeranoe, which makes a script for automatically downloading and compiling FFMPEG mingw and other tool chains. Please download the latest mongominggw-w64 build script 2.8.2 at http://ffmpeg.zeranoe.com/blog ". Decompress the package and create a new directory to put it in (my directory is/Home/haibindev/maxcompute studio/mingw-w64/), Then open the terminal, CD to the directory where the MinGW-w64 is located, and execute "chmod + x mingw-w64-build-2.8.2" to make this script executable. After running "./mingw-w64-build-2.8.2", you can follow the prompts to do it. If it prompts you that the dependent library is missing, install the dependent library as prompted by executing "sudo apt-Get install library name ".

3. Set terminal environment variables

Run the following command. (Note: If you close the terminal or create a new terminal, you need to execute this command again .)

 
Export Path ="$ Path:/home/haibindev/studio/mingw-w64/mingw-w64-i686/bin"

 

3. Download The FFMPEG source code and the source code of the codec library you need.

You don't need to introduce this. Go to the FFMPEG official website to download FFMPEG.Source codeAnd then Google the codec library you need and download it from the relevant website. I downloaded the following in this compilation:CodeFor your reference.

 
Libx264 libfaac libmp 3lame libopenjpeg libogg libspeex libvorbis libtheora libxvid FFMPEG

Decompress the downloaded package and put it in a directory./Home/haibindev/studio/opensource /.Build-FFmpeg is the working directory for compiling FFMPEG. As described below, FreeType is not compiled ).

4. Compile

For convenience, I stored the compiled results of all the libraries in a unified directory./Home/haibindev/opensdk,For the method, see the following compilation command.

Except for the first command, all the other commands are configure commands. After execution,You also need to execute the make command and then execute make install. I will not write any more.

1. Run the following command first

Ln-S"/Usr/bin/PKG-config"/Home/haibindev/studio/mingw-w64/mingw-w64-i686/bin/i686-w64-mingw32-pkg-config

2.Libx264

 
./Configure -- enable-Static-- Enable-win32thread -- Host = i686-w64-mingw32 -- prefix =/home/haibindev/opensdk -- Cross-Prefix = i686-w64-mingw32-

3.Libfaac

 
./Configure -- Host = i686-w64-mingw32 -- prefix =/home/haibindev/opensdk -- enable-Static-- Disable-shared -- with-mp4v2 = No

4.Libmp 3lame

 
Cflags =-dforceinline =./configure -- Host = i686-w64-mingw32 -- prefix =/home/haibindev/opensdk -- enable-Static-- Disable-shared -- disable-frontend

5.Libopenjpeg

 
./Configure -- Host = i686-w64-mingw32 -- prefix =/home/haibindev/opensdk -- enable-Static-- Disable-shared

6.Libogg

 
./Configure -- Host = i686-w64-mingw32 -- prefix =/home/haibindev/opensdk -- enable-Static-- Disable-shared

7.Libspeex

 
./Configure -- Host = i686-w64-mingw32 -- prefix =/home/haibindev/opensdk -- enable-Static-- Disable-shared -- disable-oggtest

8.Libvorbis

 
./Configure -- Host = i686-w64-mingw32 -- prefix =/home/haibindev/opensdk -- enable-Static-- Disable-shared -- disable-oggtest

9.Libtheora

./Configure -- Host = i686-w64-mingw32 -- prefix =/home/haibindev/opensdk -- enable-Static-- Disable-shared -- disable-oggtest -- disable-vorbistest -- disable-sdltest -- With-Ogg-nodes des =/home/haibindev/opensdk/include -- With-Ogg-libraries =/home /haibindev/opensdk/lib

10.Libxvid

 
./Configure -- Host = i686-w64-mingw32 -- prefix =/home/haibindev/opensdk -- disable-pthread

11.FFmpeg

First create/Home/haibindev/studio/opensource/build-FFMPEGAnd then CD to the directory and execute

 .. /FFMPEG- 0.8 .  7 /configure -- disable- static  -- enable-shared -- enable-version3 -- enable-GPL -- enable-nonfree -- disable-pthreads -- enable-w32threads -- enable-runtime-cpudetect -- enable-memalign-hack -- enable-libfaac -- enable-libmp3lame -- enable-libopenjpeg -- enable-libspeex -- enable-libtheora -- enable-libvorbis -- enable-libx264 -- enable-libxvid -- enable-zlib -- enable-Cross-compile -- target- OS = mingw32 -- arch = x86 -- prefix =/home/haibindev/opensdk/FFMPEG -- Cross-Prefix = i686-w64-mingw32--- extra-cflags = "  -I/home/haibindev/opensdk/include  "  -- extra-ldflags =  " -L/home/haibindev/opensdk/lib  "  

Note: When compiling Xvid, you must edit the configure file and then delete the "-MnO-cygwin" field in it. Otherwise, make will fail and the message-MnO-cygwin is invalid. The most recent "cflags =-dforceinline =" in libmp 3lame hits is to prevent a compilation error in mp3lame. Remember to include it.

After the above compilation is successful, the FFMPEG Win32 SDK appears in/Home/haibindev/opensdk/FFMPEGThe bin directory contains all the files we need.

 

5. Verify the compiledProgram

On Windows, run ffmpeg.exe in the command line.

Verify that you can perform a transcoding operation.

 
Ffmpeg.exe-I S. Avi-vcodec libx264-acodec libfaac s.mp4

It runs normally and generates a 264-encoded and AAC-encoded MP4 file. It plays normally and is OK.

 

6. Finally, let's talk about it.

Please do not forget to execute make and make install after configure during compilation! In addition, you must check out the commands I posted and replace my directory with your directory. Do not copy them directly. That is not acceptable because you are not called haibindev :). If a compilation error occurs in some libraries during make, you can simply modify the source file.

FFmpeg has many configuration options. You can customize it in depth and compile avcodec very small. You can study it on your own.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.