设为首页 收藏本站
查看: 603|回复: 0

[经验分享] ffmpeg for windows

[复制链接]

尚未签到

发表于 2016-5-23 06:39:22 | 显示全部楼层 |阅读模式
FFmpeg on Windows
  The purpose of this wiki is to provide help on everything thatinvolves FFmpeg under Windows.It originated as a step-by-step guide for building under a MSys+MinGWsystem, but now also includes guides for using FFmpeg's libraries inyour projects (C++,C#).
  It does not cover Cygwin, since Cygwin is a system that behavesbasically like a unix system, and the biggest problems of using FFmpegoccur 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 justlike any other library (either static or shared), with a C99 compiler.This again means that MSVC++ is not supported. You can, however, modifyyour build system to behave more closely like a
C99 system, and thenyou 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 toleave room for any errors. For most people, this step can safely beskipped.
  You will need a decompress utility that supports *.tar.gz and*.tar.bz2files. You will need to extract packages to an specified folder. If youalready have such program, and know how to extract packages to aspecified folder,
skip toPreparing 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

  Thisguide is very exhaustive. If you kind of know your way around compilinggeneral open-source programs, you might want to try readinghttp://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 guidecompletelybefore thinking about reporting anything to the ffmpeg mailinglists.This guide is very straight-forward. More than it needs sometimes. Ittries
to leave no room for errors. If you follow it accurately, youshouldn'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 forFFmpeg. 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 buildand 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 configuringFFmpeg, 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 onlyneed this if you want to generate documentation or install somespecific extra libraries. Don't worry about it now, you'll be remindedevery 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, youmust be able to access those files either by a command-line program, orby 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 runningbash.
http://ffmpeg.arrozcru.org/wiki/images/0/0a/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 doublequotes 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.
http://ffmpeg.arrozcru.org/wiki/images/4/4b/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 runMMX-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 foundhere.
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:
http://ffmpeg.arrozcru.org/wiki/images/5/5a/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:
http://ffmpeg.arrozcru.org/wiki/images/1/11/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:
http://ffmpeg.arrozcru.org/wiki/images/a/a9/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 beC:/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 beused when writing a program that uses FFmpeg. If you just want to runFFmpeg, all you need isffmpeg.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 inWindows 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 buildingstatically, except for the fact that you will have to inform theconfigure 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 notnecessary.
  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 underWin32,
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 understandsUnix 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 copySDL.dll.

  

Now, whenever you run ./configure for FFmpeg, it should find SDL and build FFplay correctly. Build again just likeBuilding FFmpeg SVN statically orBuilding
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.


  • dlfcn-win32
  

Install this library to get the drawtext vhook:


  • freetype2
  

Install these libraries to get the imlib2 vhook:



  • zlib <- optional (currently disabled to enable imlib2 compile)

  • libpng <- optional

  • libjpeg <- optional

  • libtiff <- optional

  • libungif <- optional
  • freetype2
  • imlib2
  

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

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

One more thing: Vhooks do not work on MinGW if FFmpeg has been compiledstatically. 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 (version1.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 orVirtualDub's filters, that have ample support and documentation (thoughnot 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 compiledstatically 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 astatic 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, youwill need to pass extra arguments to FFmpeg's configure script, so thatit 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 staticlibraries in another (like I currently do, so it's easier to makestatic 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'sdefault search paths, you will have to pass these arguments to FFmpeg'sconfigure 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, sothat you don't have to pass any extra arguments to FFmpeg'sconfigure script, the
prefix you want is:
  

/mingw
  If you install the libraries as dlls, you must make sure the generated dlls are in thePATH.
  Note that you may then use dlls compiled with other compilers, such as Microsoft Visual C++.
  

For each library I'll explain:


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


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


  
  

libs
  These are the libraries I'll show:


  • pthreads
  • zlib
  • bzip2
  • mp3lame

  • xvidcore <-- might not be necessary as FFmpeg provides a native mpeg4 encoder

  • libvorbis <-- might not be necessary as FFmpeg provides a native implementation
  • libtheora
  • libspeex

  • faad <-- might not be necessary as FFmpeg provides a native implementation
  • faac

  • amr_nb <-- non free, not re-distributable with this enabled

  • amr_wb <-- non free, not re-distributable with this enabled
  • libgsm

  • libnut <-- might not be necessary as FFmpeg provides native nut (de)muxer
  • x264
  • libschroedinger

MSVC

From FFmpeg on Windows

Jump to:
navigation,
search



Contents

[hide]




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

    • 1.1Types of libraries
    • 1.2Building
    • 1.3Including and Linking
    • 1.4Examples


  

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 youwill use are the
libav* libraries, which are an integral part ofFFmpeg.
  Before you start, you must know very well what you're doing and how. Preferably you should already have understoodBuilding FFmpeg statically andBuilding
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. Eithershared libraries or
staticlibraries. If you don't know the difference between them, I suggest youplay around a bit with some tutorials or dummy libraries. The wikipediapages are a good place to start:


  • http://en.wikipedia.org/wiki/Static_libraries
  • http://en.wikipedia.org/wiki/Shared_library#Shared_libraries
  
  

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 makesgood use of libav*, but rather only show how to include and linkproperly.
  To use the libraries, you must first of all make sure your
MSVC++
system has the inttypes.h and stdint.hinclude files. They don't come by default, so you'll only have them ifyou have gone through the process of installing them. You can do thatby followingthis
page.
  And before #includeing any libav* header file in aC file (note this is not needed for
C++ files), you must add a little hack that makesMSVC++'s C compiler behave more closely to the
C99 standard (required by FFmpeg). This hack involves defining theinline 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 thelibraries libavformat and libavcodec.
  Alternatively, you might just want to create a Process objectfor the FFmpeg.exe and use a GUI, or some other interfaces, to massagethe arguments and let FFmpeg do its work.
  There is a
draftshowing how to use PI with "do-it-yourself" (that's Adam Nathan'sdescription) marshalling. But ideally, you'd like to have a simplehigh-level library that expose most of the functionality of the FFmpeglibraries.
  
  
  
  raw url:http://ffmpeg.arrozcru.org/wiki/index.php?title=Main_Page

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-220441-1-1.html 上篇帖子: 《领域驱动设计 C# 2008 实现》 下篇帖子: 2008年终盘点-十大惊艳Java应用程序
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表