Skip to content
Search

FFmpeg:Compile

lastmod 2021-06-15created 2014-10-0928 edits

Describes how to compile FFmpeg.

How to check GCC build options

When building with configuration, the GCC options are not printed separately. To see the options, add echo to the COMPILE function in common.mak as shown below.

define COMPILE
       $(call $(1)DEP,$(1))
       echo $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $<
       $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $<
endef

When using FFmpeg-related libraries, use pkg-config whenever possible.

For reference, a more accurate method is as follows.

$(foreach VAR,$(BRIEF), \ 
    $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR)))) 
$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR)))) 

In the statement above, at around line 26, remove the @ in front of $$(call ECHO,$(VAR),$$(MSG)); $($(VAR)))).

FFplay Options

The compile options for ffplay are as follows.

echo @printf "CC\t%s\n" ffplay.o; gcc -I. -I./ -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -U__STRICT_ANSI__
    -D__USE_MINGW_ANSI_STDIO=1 -D__printf__=__gnu_printf__ -DPIC -DZLIB_CONST -std=c99 -fomit-frame-pointer -D_GNU_SOURCE=1
    -Dmain=SDL_main -Id:/local/tcm-gcc481-x64/include/SDL -g -Wdeclaration-after-statement -Wall -Wdisabled-optimization
    -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -Wmissing-prototypes -Wno-pointer-to-int-cast
    -Wstrict-prototypes -Wempty-body -Wno-parentheses -Wno-switch -Wno-format-zero-length -Wno-pointer-sign -O3 -fno-math-errno
    -fno-signed-zeros -fno-tree-vectorize -Werror=format-security -Werror=implicit-function-declaration -Werror=missing-prototypes
    -Werror=return-type -Werror=vla -Wformat -Wno-maybe-uninitialized  -D_GNU_SOURCE=1 -Dmain=SDL_main
    -Id:/local/tcm-gcc481-x64/include/SDL -MMD -MF ffplay.d -MT ffplay.o -c -o ffplay.o ffplay.c

The output printed at link time is as follows.

echo @printf "LD\t%s\n" ffplay_g.exe; gcc -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil
    -Llibpostproc -Llibswscale -Llibswresample -Wl,--nxcompat -Wl,--dynamicbase -Wl,--as-needed -Wl,--warn-common
    -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample
    -o ffplay_g.exe cmdutils.o ffplay.o -lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lavicap32
    -lgdi32 -lpsapi -lole32 -lstrmiids -luuid -lws2_32 -liconv 
    -Ld:/local/tcm-gcc481-x64/lib -lmingw32 -lSDLmain -lSDL -mwindows -lm -lz -lpsapi -ladvapi32 -lshell32
    -Ld:/local/tcm-gcc481-x64/lib -lmingw32 -lSDLmain -lSDL -mwindows

FFserver Options

The compile options for ffserver are as follows.

printf "CC\t%s\n" ffserver.o; gcc -I. -I./ -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
-D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DZLIB_CONST -std=c99 -fomit-frame-pointer -pthread
-g -Wdeclaration-after-statement -Wall -Wdisabled-optimization -Wpointer-arith -Wredundant-decls
-Wwrite-strings -Wtype-limits -Wundef -Wmissing-prototypes -Wno-pointer-to-int-cast -Wstrict-prototypes
-Wempty-body -Wno-parentheses -Wno-switch -Wno-format-zero-length -Wno-pointer-sign -O3 -fno-math-errno
-fno-signed-zeros -fno-tree-vectorize -Werror=format-security -Werror=implicit-function-declaration
-Werror=missing-prototypes -Werror=return-type -Werror=vla -Wformat -Wno-maybe-uninitialized
-MMD -MF ffserver.d -MT ffserver.o -c -o ffserver.o ffserver.c
CC  ffserver.o

printf "LD\t%s\n" ffserver_g; gcc -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample
-Llibavutil -Llibpostproc -Llibswscale -Llibswresample -Wl,--as-needed -Wl,-z,noexecstack -Wl,--warn-common
-Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample
-o ffserver_g cmdutils.o ffserver_config.o ffserver.o
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lxcb -lxcb-shm -lxcb
-lxcb-xfixes -lxcb-render -lxcb-shape -lxcb -lxcb-shape -lxcb -lX11 -lm -lbz2 -lz -pthread -lrt
LD  ffserver_g

printf "CP\t%s\n" ffserver; cp -p ffserver_g ffserver
CP  ffserver

printf "STRIP\t%s\n" ffserver; strip ffserver
STRIP   ffserver

CentOS install

$ yum -y install http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
$ yum install ffmpeg

Ubuntu install

$ sudo apt-get install libavcodec-extra

Windows build

To build the FFMPEG source on Windows: download the ffmpeg source via SVN (the source is already ported).

If you get an error saying the libavformat.vcproj project cannot be loaded, apply the following as well. All you need is the yasm.rules file in the C:\Program Files (x86)\M icrosoft Visual Studio 9.0\VC\VCProjectDefaults folder.

yasm.rules sample

<?xml version="1.0" encoding="utf-8"?>
<VisualStudioToolFile
    Name="Yasm"
    Version="8.00"
    >
    <Rules>
        <CustomBuildRule
            Name="YASM"
            DisplayName="Yasm Assembler"
            CommandLine="yasm -Xvc -f $(PlatformName) [AllOptions] [AdditionalOptions] [Inputs]"
            Outputs="[$ObjectFileName]"
            FileExtensions="*.asm"
            ExecutionDescription="Assembling $(InputFileName)"
            ShowOnlyRuleProperties="false"
            >
            <Properties>
                <StringProperty
                    Name="Defines"
                    DisplayName="Definitions"
                    Category="Pre-Defined Symbols"
                    Description="Specify pre-defined symbols (&apos;symbol&apos; or &apos;symbol = value&apos;) "
                    Switch="-D [value]"
                    Delimited="true"
                    Inheritable="true"
                />
                <StringProperty
                    Name="IncludePaths"
                    DisplayName="Include Paths"
                    Category="Configuration"
                    Description="Set the paths for any additional include files"
                    Switch="-i &quot;[value]&quot;"
                    Delimited="true"
                    Inheritable="true"
                />
                <StringProperty
                    Name="UnDefines"
                    DisplayName="Remove Definitions"
                    Category="Pre-Defined Symbols"
                    Description="Remove pre-defined symbols "
                    Switch="-u [value]"
                    Delimited="true"
                    Inheritable="true"
                />
                <StringProperty
                    Name="ObjectFileName"
                    DisplayName="Object File Name"
                    Category="Output"
                    Description="Select the output file name"
                    Switch="-o &quot;[value]&quot;"
                    DefaultValue="&quot;$(IntDir)\$(InputName).obj&quot;"
                />
                <StringProperty
                    Name="ListFileName"
                    DisplayName="List File Name"
                    Category="Output"
                    Description="Select an output listing by setting its file name"
                    Switch="-l &quot;[value]&quot;"
                />
                <StringProperty
                    Name="PreIncludeFile"
                    DisplayName="Pre Include File"
                    Category="Configuration"
                    Description="Select a pre-included file by setting its name"
                    Switch="-P &quot;[value]&quot;"
                />
                <BooleanProperty
                    Name="Debug"
                    DisplayName="Debug Information"
                    Category="Output"
                    Description="Generate debugging information"
                    Switch="-g cv8"
                />
                <EnumProperty
                    Name="PreProc"
                    DisplayName="Pre-Processor"
                    Category="Configuration"
                    Description="Select the pre-processor (&apos;nasm&apos; or &apos;raw&apos;)"
                    >
                    <Values>
                        <EnumValue
                            Value="0"
                            Switch="-rnasm"
                            DisplayName="Nasm "
                        />
                        <EnumValue
                            Value="1"
                            Switch="-rraw"
                            DisplayName="Raw"
                        />
                    </Values>
                </EnumProperty>
                <EnumProperty
                    Name="Parser"
                    DisplayName="Parser"
                    Category="Configuration"
                    Description="Select the parser for Intel (&apos;nasm&apos;) or AT&amp;T ( &apos;gas&apos;) syntax"
                    >
                    <Values>
                        <EnumValue
                            Value="0"
                            Switch="-pnasm"
                            DisplayName="Nasm"
                        />
                        <EnumValue
                            Value="1"
                            Switch="-pgas"
                            DisplayName="Gas"
                        />
                    </Values>
                </EnumProperty>
            </Properties>
        </CustomBuildRule>
    </Rules>
</VisualStudioToolFile>

Debug mode

./configuration --disable-stripping --enable-debug=3 --extra-cflags=-g

FFmpeg with OpenH264

Add the directory where the pkg-config configuration file (openh264.pc) is installed to the PKG_CONFIG_PATH environment variable, then proceed as follows. <del>

./configure --extra-ldflags=-static-libgcc --enable-shared --enable-cross-compile --arch=x86 \
            --cross-prefix=i686-w64-mingw32- --target-os=mingw32 --enable-runtime-cpudetect \
            --enable-pic --disable-doc --enable-memalign-hack --disable-everything \
            --enable-decoder='h264,mpeg4,mjpeg' --enable-libopenh264 --enable-encoder=libopenh264 \
            --extra-cflags=-I빌드한 openh264/include --extra-ldflags=-L빌드한 openh264/lib \
            --enable-filter=yadif --prefix=`pwd`/../ffmpeg_w32_dist

</del>

In short, it comes down to the following.

## --extra-cflags와 --extra-ldflags도 생략한다.
./configure --enable-libopenh264

Troubleshooting

recompile with -fPIC

Other libraries that use FFmpeg (e.g. OpenCV) may run into the following problem.

/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

In this case, add the --extra-cflags="-fPIC" option at the configure step and recompile.

See also

Favorite site

FFmpeg Compilation Guide

author Zer0 sitemap