ffmpeg for windows

FFmpeg on Windows

The purpose of this wiki is to provide help on everything that involves FFmpeg under Windows. It originated as a step-by-step guide for building under a MSys+MinGW system, but now also includes guides for using FFmpeg's libraries in your projects (C++, C#).

It does not cover Cygwin, since Cygwin is a system that behaves basically like a unix system, and the biggest problems of using FFmpeg occur with people that aren't very familiar with unix systems.

Before you start, these messages must be clearly understood:


First message:

FFMPEG DOES NOT BUILD UNDER MSVC++, AND WILL NOT, EVER, BUILD UNDER MSVC++.

MSVC++ still does not adhere to the C99 standard, and FFmpeg relies on it, because its developers chose to rely on it.

That means the entire build process of FFmpeg must be done with MSys+MinGW.

The libraries created by FFmpeg with MinGW are usable just like any other library (either static or shared), with a C99 compiler. This again means that MSVC++ is not supported. You can, however, modify your build system to behave more closely like a C99 system, and then you will be able to use FFmpeg's libraries with MSVC++.


Second message:

If you have any problems with this guide, please ask in the FFmpeg Windows Help Forum before asking in the ffmpeg-user mailinglist.

 


Basic Prerequisite

This might be out of the scope of this guide, but I don't want to leave room for any errors. For most people, this step can safely be skipped.

You will need a decompress utility that supports *.tar.gz and *.tar.bz2 files. You will need to extract packages to an specified folder. If you already have such program, and know how to extract packages to a specified folder, skip to Preparing the MSys+MinGW system.

I will show here how to use 7-Zip and WinRAR for such purpose.

7-Zip
WinRAR

 

Introduction

From FFmpeg on Windows

Jump to: navigation, search

This guide is very exhaustive. If you kind of know your way around compiling general open-source programs, you might want to try reading http://ffmpeg.mplayerhq.hu/general.html under Native Windows compilation. It's much smaller and works with just a few tweaks.

But if you happen to have any problems there, read this exhaustive guide completely before thinking about reporting anything to the ffmpeg mailinglists. This guide is very straight-forward. More than it needs sometimes. It tries to leave no room for errors. If you follow it accurately, you shouldn't have any problems with FFmpeg on Windows.

Try your best to solve your own problems before reporting anything.
The vast majority of FFmpeg developers do not use Windows, so they can't help. At all.

 

MSys MinGW

From FFmpeg on Windows

Jump to: navigation, search

Preparing the MSys+MinGW system

Get the most up-to-date MSys+MinGW system.

Today (November 29, 2008), that includes:

  • make

The version of make that is installed by default will not work for FFmpeg. You will have to upgrade.
make must be MSYS make version => 3.81
Preferably version 3.81-2.
Also do not get MinGW make. Get MSYS make.

 

  • Mingw runtime

Must be version => 3.15
Note: if any older version is used, everything will still build and link fine, but non numeric AVOptions will not work in ffmpeg (-flags, etc.)

 

  • w32api

Should be version => 3.13
Note: if any older version is used, you will have to --disable-devices while configuring FFmpeg, and vfwcap will not be compiled in.

 

  • bash

Must be version => 2.05b to build FFmpeg.
Preferably version 3.1 to build most other external libraries.

 

  • binutils

do not use binutils-2.15.91-20040904-1. It is known to not link properly.
(2.17 recommended by Gianluigi Tiesi)


If you are sure you have this ready, skip to Getting FFmpeg SVN. Or else, read these steps.

Installing MSys
Installing MinGW
Integrating MinGW with MSys


This step can safely be ignored for most people. You'll only need this if you want to generate documentation or install some specific extra libraries. Don't worry about it now, you'll be reminded every time it is needed.

Installing MSys DTK

 

Getting FFmpeg SVN

If you already know how to get FFmpeg's source code, skip to Building FFmpeg SVN statically.

Since the FFmpeg source code resides in an SVN repository, you must be able to access those files either by a command-line program, or by a graphical user interface front-end.
Here I'll show how to use TortoiseSVN, which integrates very well into Windows Explorer, and the original command line version.

TortoiseSVN
svnclient

 

Static

From FFmpeg on Windows

Jump to: navigation, search

Building FFmpeg SVN statically

If your system has been carefully crafted with Preparing the MSys+MinGW system and Getting FFmpeg SVN, the following should work:


On the Start Menu, go

Start->Programs->MinGW->MSys->msys

This beige window should open. It is the rxvt program running bash.

image:rxvt.png


It is a Unix-like shell that will work almost like a real Unix shell on Windows.

Note 1: Folder names use a forward slash instead of the usual Windows backslash (such as "C:/ffmpeg" instead of "C:/ffmpeg").

Note 2: The drive letters (such as "C:/") can be accessed in the root folder (such as "/C/").

Note 3: File and folder names with spaces must have double quotes around them (such as "/C/Program Files (x86)", with the quotes)


Change directory to wherever you checked FFmpeg out.
If you followed the suggestions in this article, you should achieve that by typing:

cd /C/ffmpeg

and pressing enter.

image:cd_ffmpeg.png


Then you have to configure FFmpeg, choosing what you want to install, how, and where.
If you want extra libraries (such as mp3lame, or xvid), checkout the Using External Libraries page after you're done with this step and the next one.
If you don't know what you want, just enter:

./configure --enable-memalign-hack --extra-cflags="-fno-common"


The --enable-memalign-hack option is necessary for FFmpeg to run MMX-optimized code on Windows.

The --extra-cflags="-fno-common" option is necessary to work around a bug in the toolchain. More information about this bug can be found here. It only affects SSE2-optimized code.

After a while, when it finishes configuring, it will go back to the prompt (the $ line, where you enter commands). You should see the following list:

image:configure.png

 

If there are no errors, you're all set to make FFmpeg. Enter this in the prompt:

make

This will take long. It is the actual compiling of the complete FFmpeg source code. If all goes well, once it's done, you'll be back in the prompt with this output:

image:make.png


The program is already compiled. You can find the ffmpeg.exe executable on FFmpeg's folder. After that, all you have to do is install the program, with the command:

make install

And you'll get this output:

image:make_install.png

 

FFmpeg will install to a default folder (/usr/local) if you have not provided a specific --prefix option in configure. Remember that /usr/local can be found right under MSYS's folder. In Windows paths, if you followed this tutorial correctly, that would be C:/msys/local (in MSYS, the /usr folder is a link to /).


Three folders will be installed:
bin contains the ffmpeg.exe executable. This is what you want. It runs standalone.
include and lib contain the include and lib files to be used when writing a program that uses FFmpeg. If you just want to run FFmpeg, all you need is ffmpeg.exe.


Good. Now you can just run ffmpeg.exe exactly the way you wanted in the first place. You're all set. FFmpeg was successfully statically compiled and installed.


Of course you'll need to know the correct parameters to pass to FFmpeg. To generate files that will play normally in Windows Media Player, check here for more information.

 

Shared

From FFmpeg on Windows

Jump to: navigation, search

Building FFmpeg SVN dlls

Building FFmpeg with shared libs is almost the same as building statically, except for the fact that you will have to inform the configure script that you want it to be built shared.

Note: If you do not know exactly how to build statically, read Building FFmpeg SVN statically.


Open up MSys again if it's not already open. For that, go

Start->Programs->MinGW->MSys->msys

Change folder to the FFmpeg SVN source code folder. It is a good idea to clean the previous statically linked compilation. If you just made little changes to the source code, it's normally not necessary.

But if you're following this guide sequentially, and thus need to clean the previous compilation, run:

make distclean

The configure call will need to include --enable-shared and --disable-static, such as:

./configure --enable-shared --disable-static --enable-memalign-hack --extra-cflags="-fno-common"

Then, just like in Step 3:

make

and

make install

 

Since FFmpeg no longer installs its libraries and executables to the same folder, you will need to make your libs (libav*.dll) accessible by $PATH from the executable (ffmpeg.exe).

You can do that by copying the dlls that were installed to <prefix>/lib (<prefix> is /usr/local by default) to wherever ffmpeg.exe is.

Or else, you can add <prefix> to your PATH, by issuing the following command:

PATH=$PATH:/usr/local/lib

Building FFplay

From FFmpeg on Windows

Jump to: navigation, search

To build FFplay, you must have SDL-devel installed.

Go to libsdl.org, and near the end, at Development Libraries, get the latest under Win32, for MinGW32, not Visual C++.
download


Unpack the file.

With Windows Explorer, go to the folder you just unpacked.
Copy all the files from the lib folder to C:/msys/mingw/lib/.
Copy the SDL folder from the include folder to C:/msys/mingw/include/.
Copy all the files from the bin folder to C:/msys/mingw/bin/.


Edit c:/msys/mingw/bin/sdl-config with an editor that understands Unix line endings (like wordpad.exe).
Change the line that says:
prefix=/Users/hercules/tmp/SDL-1.2.13
to
prefix=/mingw

 

The SDL.dll file must be in the PATH for ffplay.exe to run correctly.

The bin folder it was copied to, is in the PATH for MSys.

But if you want to run ffplay.exe from outside of MSys, you'll have to copy SDL.dll.


Now, whenever you run ./configure for FFmpeg, it should find SDL and build FFplay correctly. Build again just like Building FFmpeg SVN statically or Building FFmpeg SVN dlls.

 

Building VHooks

From FFmpeg on Windows

Jump to: navigation, search

Note: vhooks are being replaced by a LibAVFilter, and any development work on vhook is highly discouraged (bug fix is allowed).


The ppm vhook doesn't work on Windows as it's designed for POSIX.


To get any vhook working (watermark, fish, null), you must have dlfcn (aka libdl), which is not present in MinGW.


Install this library to get the drawtext vhook:


Install these libraries to get the imlib2 vhook:


Instead of building the zlib and libregif libraries from source, you can get them already built from Tiesi's site


There you go. Now just run configure normally, and make sure it prints out vhooks are enabled.


One more thing: Vhooks do not work on MinGW if FFmpeg has been compiled statically. So you must --disable-static --enable-shared on FFmpeg's configure.


example:

$ cd ..
$ cd ffmpeg
$ mkdir build
$ cd build
$ ../src/configure --enable-memalign --disable-static --enable-shared
$ make
$ make install
$ cp -r /mingw/lib/imlib2 /usr/local/bin/imlib2
$ make output_example.exe
$ ./output_example.exe input.mpg
$ cp input.mpg /usr/local/bin/
$ cd /usr/local/bin
$ ./ffmpeg.exe -i input.mpg -vhook 'vhook/imlib2.dll -x W*(0.5+0.25*sin(N/47*PI]]-w/2 /
-y H*(0.5+0.50*cos(N/97*PI]]-h/2 -i /mingw/share/imlib2/data/images/bulb.png' /

Building documentation

From FFmpeg on Windows

Jump to: navigation, search

Building documentation

To build FFmpeg's documentation, you need texi2html. If the configure script finds it, documentation will be automatically generated, or else, no documentation will be generated.

FFmpeg's website uses an old (hard to find) version of texi2html (version 1.56k), which produces a very nice output.
The newest version of texi2html produces something else, which I dislike.


You can either install the latest and ugly version, or the old and nice version.

texi2html requires perl, which can be installed with the MSys DTK.


texi2html version 1.56k
texi2html latest version


pod2man is also needed, to generate man pages, or else make will fail. I don't build them. I don't want man pages.


I simply create an empty /bin/pod2man file:

touch /bin/pod2man

 

texi2html version 1.56k

It's rather hard to find this old version of texi2html, but it produces better output.
I'm hosting a copy here


To install it, simply download that file to your /bin folder.
In Windows, it should be C:/msys/bin.

 

texi2html latest version

Go here.
Get the latest release: download


Unpack it.
In MSys, change to that folder.
Run

configure --prefix=/usr

Run

make install


-acodec copy -sameq -y output.mpg


The usage of vhooks is explained here
Just remember to use .dll where the examples use .so and use double quotes where the examples use single quotes.
And if you find vhooks hard, you can always use either Avisynth or VirtualDub's filters, that have ample support and documentation (though not here ;-]].

 

Using External Libraries

From FFmpeg on Windows

Jump to: navigation, search

You must have already fully understood Building FFmpeg SVN dlls.


(jump straight to libs menu)


To add extra libraries to your FFmpeg binaries, you must first decide how you want those libraries to be included.

Do you want them to be statically linked to FFmpeg?
Do you want them to be external dlls that are loaded by FFmpeg?


Don't confuse this with compiling FFmpeg statically or shared. You can have all your extra libraries compiled statically into FFmpeg, and still make use of FFmpeg as shared dlls.

Think about this scenario:
Do you want to be able to change the xvidcore.dll file to any newer versions without having to recompile FFmpeg?
If so, then you should build xvidcore as a shared library.
If you want xvidcore to be statically linked to libavcodec, then you should build it as a static library.


The second thing you must decide is where do you want those libraries to be installed in your MSys system.

For most libraries, if you install them in default paths, you will need to pass extra arguments to FFmpeg's configure script, so that it will know where to find those libraries.
If you install each library in gcc's default include and lib path, then you won't have to specify extra search paths to FFmpeg's configure script.
If you want to keep the shared libraries in one path, and the static libraries in another (like I currently do, so it's easier to make static and shared builds), then you will also have to specify that path.
Such path is called the prefix where you install your library.


If you happen to install any library in a prefix different from gcc's default search paths, you will have to pass these arguments to FFmpeg's configure script, so that it may find the appropriate libraries:

-–extra-ldflags=-L<prefix>/lib --extra-cflags=-I<prefix>/include

Such as:

./configure --enable-memalign-hack --enable-libmp3lame /
-–extra-ldflags=-L/usr/local/lib /
--extra-cflags=-I/usr/local/include


If you want to install the libraries in gcc's default search path, so that you don't have to pass any extra arguments to FFmpeg's configure script, the prefix you want is:

/mingw

If you install the libraries as dlls, you must make sure the generated dlls are in the PATH.

Note that you may then use dlls compiled with other compilers, such as Microsoft Visual C++.


For each library I'll explain:

  1. How to obtain the library;
  2. How to compile statically or shared;
  3. How to install to a specific prefix;
  4. Which extra arguments to pass to FFmpeg's configure;
  5. Example commands.

 

Before you start, you must make sure you have bash version => 3.1, from Installing bash.

 

libs

These are the libraries I'll show:

MSVC

From FFmpeg on Windows

Jump to: navigation, search

Contents

[hide]

<script type="text/javascript"> </script>

Building FFmpeg libraries that can be used by your MSVC++ program

Please note:

FFmpeg itself will not compile under MSVC++.
But if it is properly built, the generated libraries can be used from MSVC++.


If you got prebuilt libraries and just want to use them, skip to Including and Linking.

Note that, in this guide, you will not use ffmpeg.exe. What you will use are the libav* libraries, which are an integral part of FFmpeg.

Before you start, you must know very well what you're doing and how. Preferably you should already have understood Building FFmpeg statically and Building FFmpeg dlls completely, and gotten them to work.

Actually, not only preferable, let's say it's a prerequisite.

Types of libraries

There are two types of libraries you can build with FFmpeg. Either shared libraries or static libraries. If you don't know the difference between them, I suggest you play around a bit with some tutorials or dummy libraries. The wikipedia pages are a good place to start:

 

Building

Now follow on to building the libraries:
Building FFmpeg shared libraries
Building FFmpeg static libraries

 

Including and Linking

Note that these pages do not show how to create a project that makes good use of libav*, but rather only show how to include and link properly.

To use the libraries, you must first of all make sure your MSVC++ system has the inttypes.h and stdint.h include files. They don't come by default, so you'll only have them if you have gone through the process of installing them. You can do that by following this page.

And before #includeing any libav* header file in a C file (note this is not needed for C++ files), you must add a little hack that makes MSVC++'s C compiler behave more closely to the C99 standard (required by FFmpeg). This hack involves defining the inline keyword (valid C99) to _inline (MSVC++'s variant):

#define inline _inline


And then finally follow on to linking the libraries:
Using FFmpeg shared libraries with MSVC++
Using FFmpeg static libraries with MSVC++

 

Examples

For practical examples on how to use the libraries with MSVC++, follow these:
Example 1: avcodec_sample.0.4.9
Example 2: output_example

 

C Sharp

From FFmpeg on Windows

Jump to: navigation, search

Using FFmpeg with C#

Once you have compiled, or downloaded, the Windows DLLs for FFmpeg, you can use .Net Platform Invoke (PI) to access the functions in the libraries libavformat and libavcodec.

Alternatively, you might just want to create a Process object for the FFmpeg.exe and use a GUI, or some other interfaces, to massage the arguments and let FFmpeg do its work.

There is a draft showing how to use PI with "do-it-yourself" (that's Adam Nathan's description) marshalling. But ideally, you'd like to have a simple high-level library that expose most of the functionality of the FFmpeg libraries.

 

 

 

raw url:http://ffmpeg.arrozcru.org/wiki/index.php?title=Main_Page

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值