ffmpeg--编译ffmpeg-4.0的源码

1.首先要有个GNU的环境。如果在Windows系统下,就要弄一个虚拟环境,安装一个Cygwin。如果是Linux环境,那么Linux中是有GNU的。

2.下载ffmpeg的源码,不用爬梯,直接官网可以下载:http://www.ffmpeg.org/download.html

   下载NDK,在Google官网下载,不用爬梯:https://developer.android.google.cn/ndk/downloads/

3.编译Android可用的动态库。需要配置某些东西,主要跟动态库名字有关,不修改,Android无法识别。修改如下:

下载FFmpeg源代码之后,首先需要对源代码中的configure文件进行修改。由于编译出来的动态库文件名的版本号在.so之后(例如“libavcodec.so.5.100.1”),而android平台不能识别这样文件名,所以需要修改这种文件名。在configure文件中找到下面几行代码:

  1. SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'  
  2. LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'  
  3. SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'  
  4. SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR)$(SLIBNAME)'  
    替换为下面内容就可以了:
  1. SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'  
  2. LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'  
  3. SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'  
  4. SLIB_INSTALL_LINKS='$(SLIBNAME)' 
4.然后就可以编译了,当然会用到make命令,在make之前需要执行一个脚本,就是前面修改了的configure文件,执行这个文件后面要加很多参数,头都大。在网上搜到的大多数脚本都是这样的形式的:
#!/bin/sh
    cd ffmpeg

    make clean

    export NDK=./android-ndk-r17
    export PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt
    export PLATFORM=$NDK/platforms/android-24/arch-arm
    export PREFIX=./simplefflib
    build_one(){  
      ./configure --target-os=linux --prefix=$PREFIX \
    --enable-cross-compile \
    --enable-runtime-cpudetect \
    --disable-asm \
    --arch=arm \
    --cc=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi-gcc \
    --cross-prefix=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi- \
    --disable-stripping \  
    --nm=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi-gcc-nm \
    --sysroot=$PLATFORM \
    --enable-gpl --enable-shared --disable-static --enable-small \
    --disable-ffprobe --disable-ffplay --disable-ffmpeg --disable-ffserver --disable-debug \
    --extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -marm -march=armv7-a"
    }

    build_one

    make
    sudo make install
      
    cd ..

该脚本中前面几个变量“NDK”、“PREBUILT”、“PLATFORM”根据NDK路径的不同需要做相应的修改。另外需要注意64位NDK和32位NDK中某些文件夹名称也有一些区别:例如32位NDK中文件夹名称为“linux-x86”而64位NDK中文件夹名称为“linux-x86_64”。

在修改一个宏后,就可以执行,发现说少了很多文件。比如:ffmpeg makefile:2:config.mak:No such file or directory

然后执行以下三个命令后,那么缺少的文件就有了:

sudo apt-get install yasm
./configure
make
sudo make install

注意那些make要在ffmpeg根目录执行。

运行完上面几个命令后,就不报 缺少文件的错误了,大概编译几分钟后,顺利编完了,但是此时中间文件都编译出来了,按照网上说的应该按照PREFIX=./simplefflib所定义的,在./simplefflib文件夹中出现so文件,但是编译完后,没有simplefflib文件夹出现,自己建了一个同名的文件夹再编一遍,还是没有,而且在ffmpeg整个目录都找不到任何so库。然后翻墙找到另外一种脚本如下:

扫描二维码关注公众号,回复: 2807194 查看本文章
#!/bin/sh
cd ffmpeg
make clean
export NDK=./android-ndk-r17
export PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt
export PLATFORM=$NDK/platforms/android-24/arch-arm
sed -i 's/-lflite"/-lflite -lasound"/' configure &&

./configure --prefix=/usr        \
            --enable-gpl         \
            --enable-version3    \
            --enable-nonfree     \
            --disable-static     \
            --enable-shared      \
            --disable-debug      \
            --enable-avresample  \
            --docdir=/usr/share/doc/ffmpeg-4.0 &&

make &&

gcc tools/qt-faststart.c -o tools/qt-faststart
cd ..

可以成功编译并且在各个模块的源码目录下生成了so文件。注意make前最好使用make clean。



以下是一个介绍ffmpeg-4.0的文档,需要梯子:

http://www.linuxfromscratch.org/blfs/view/svn/multimedia/ffmpeg.html

下面是这个文档的内容:

FFmpeg-4.0

Introduction to FFmpeg

FFmpeg is a solution to record, convert and stream audio and video. It is a very fast video and audio converter and it can also acquire from a live audio/video source. Designed to be intuitive, the command-line interface (ffmpeg) tries to figure out all the parameters, when possible. FFmpeg can also convert from any sample rate to any other, and resize video on the fly with a high quality polyphase filter. FFmpeg can use a Video4Linux compatible video source and any Open Sound System audio source.

This package is known to build and work properly using an LFS-8.2 platform.

Package Information

  • Download (HTTP): http://ffmpeg.org/releases/ffmpeg-4.0.tar.xz

  • Download MD5 sum: 1cc9e8cb027b9fd4c54f598f51002c19

  • Download size: 8.3 MB

  • Estimated disk space required: 141 MB (add 3.1 GB for the FATE suite/tests, add 17 MB for docs)

  • Estimated build time: 1.7 SBU (using parallelism=4; add 3.8 SBU (with THREADS=4) to run the FATE suite after sample files are downloaded; add 0.4 SBU for docs)

FFmpeg Dependencies

Recommended

Recommended for desktop use

Optional

Fontconfig-2.13.0, frei0r-plugins-1.6.1, libcdio-2.0.0 (to identify and play CDs), libwebp-1.0.0, opencv-3.4.1, OpenJPEG-2.3.0, GnuTLS-3.5.18, PulseAudio-11.1, Speex-1.2.0, texlive-20180414 (or install-tl-unx) for PDF and PS documentation, v4l-utils-1.14.2, XviD-1.3.5, X Window System, Flite, GSM, HEVC/H.265, libaacplus, libbluray, libcaca, libcelt, libdc1394, libdca, libiec61883, libilbc, libmodplug, libnut (Git checkout), librtmp,libssh, OpenAL, OpenCore AMR, Schroedinger, TwoLAME, vo-aaenc, vo-amrwbenc, and ZVBI

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/ffmpeg

Installation of FFmpeg

Install FFmpeg by running the following commands:

sed -i 's/-lflite"/-lflite -lasound"/' configure &&

./configure --prefix=/usr        \
            --enable-gpl         \
            --enable-version3    \
            --enable-nonfree     \
            --disable-static     \
            --enable-shared      \
            --disable-debug      \
            --enable-avresample  \
            --enable-libass      \
            --enable-libfdk-aac  \
            --enable-libfreetype \
            --enable-libmp3lame  \
            --enable-libopus     \
            --enable-libtheora   \
            --enable-libvorbis   \
            --enable-libvpx      \
            --enable-libx264     \
            --enable-libx265     \
            --docdir=/usr/share/doc/ffmpeg-4.0 &&

make &&

gcc tools/qt-faststart.c -o tools/qt-faststart

HTML documentation was built in the previous step. If you have texlive-20180414 installed and wish to build PDF and Postscript versions of the documentation, issue the following commands:

pushd doc &&
for DOCNAME in `basename -s .html *.html`
do
    texi2pdf -b $DOCNAME.texi &&
    texi2dvi -b $DOCNAME.texi &&

    dvips    -o $DOCNAME.ps   \
                $DOCNAME.dvi
done &&
popd &&
unset DOCNAME

If you have Doxygen-1.8.14 installed and you wish to build (if --disable-doc was used) or rebuild the html documentation, issue the command doxygen doc/Doxyfile.

The fate-suite tests include comparisons with installed files, and should not be run before the package is installed. Therefore, if you desire to run them, instructions are given further below.

Now, as the root user:

make install &&

install -v -m755    tools/qt-faststart /usr/bin &&
install -v -m755 -d           /usr/share/doc/ffmpeg-4.0 &&
install -v -m644    doc/*.txt /usr/share/doc/ffmpeg-4.0

If the PDF and Postscript documentation was built, issue the following commands, as the root user, to install them:

install -v -m644 doc/*.pdf /usr/share/doc/ffmpeg-4.0 &&
install -v -m644 doc/*.ps  /usr/share/doc/ffmpeg-4.0

If you used doxygen to manually create the API documentation, install it by issuing the following commands as the root user:

install -v -m755 -d /usr/share/doc/ffmpeg-4.0/api                     &&
cp -vr doc/doxy/html/* /usr/share/doc/ffmpeg-4.0/api                  &&
find /usr/share/doc/ffmpeg-4.0/api -type f -exec chmod -c 0644 \{} \; &&
find /usr/share/doc/ffmpeg-4.0/api -type d -exec chmod -c 0755 \{} \;

To properly test the installation you must have rsync-3.1.3 installed and follow the instructions for the FFmpeg Automated Testing Environment (FATE). First, about 1 GB of sample files used to run FATE are downloaded with the command:

make fate-rsync SAMPLES=fate-suite/

The fate-suite directory is created and the files are downloaded there. That command actually runs an rsync command, to obtain the sample files. You may want to compress and keep this directory for testing again, in another system, or when a new version of ffmpeg is launched. Then, you unpack the sample files in the source directory, and run, again, the make fate-rsync ... command above, to sync with the repository. Now, the download size and time are drastically reduced. Estimated values in "Package Information" do not include the download SBU. Some samples may have been removed, in the new version, so, in order to be sure local and server fate samples are identical, when you use previously saved samples, run the following command:

rsync -vrltLW  --delete --timeout=60 --contimeout=60 \
      rsync://fate-suite.ffmpeg.org/fate-suite/ fate-suite/

Next, FATE is executed, with the commands (you obtain a number of tests larger than 3000):

make fate THREADS=N SAMPLES=fate-suite/ | tee ../fate.log &&
grep ^TEST ../fate.log | wc -l

where N is an integer, N ≤ number of cores in the system.

Command Explanations

sed -i ... configure: This command adds the ALSA library to the Flite LDFLAGS variable and enables the discovery of Flite.

find ... ;: Fix permissions of documentation files and directories.

--enable-libfreetype: Enables Freetype support.

--enable-gpl: Enables the use of GPL code and permits support for postprocessing, swscale and many other features.

--enable-version3: Enables the use of (L)GPL version 3 code.

--enable-nonfree: Enables the use of nonfree code. Note that the resulting libraries and binaries will be unredistributable.

--disable-static: This switch prevents installation of static versions of the libraries.

--enable-shared: Enables building shared libraries, otherwise only static libraries are built and installed.

--disable-debug: Disables building debugging symbols into the programs and libraries.

--enable-avresample: Enables Transcode-1.1.7 to be compiled.

--enable-libass: Enables ASS/SSA subtitle format rendering via libass.

--enable-libfdk-aac: Enables currently the highest-quality AAC audio encoding via libfdk-aac.

--enable-libmp3lame: Enables MP3 audio encoding via libmp3lame.

--enable-libvorbis --enable-libtheora: Enables Theora video encoding via libvorbis and libtheora.

--enable-libvorbis --enable-libvpx: Enables WebM encoding via libvorbis and libvpx.

--enable-libx264: Enables high-quality H.264/MPEG-4 AVC encoding via libx264.

--enable-libx265: Enables high-quality H.265/HEVC encoding via libx265.

--enable-openssl or --enable-gnutls: Enables HTTPS protocol for network streams.

--disable-doc: Disables building html documentation. This is only needed if Doxygen-1.8.14 is installed and you do not want to build the html documentation.

gcc tools/qt-faststart.c -o tools/qt-faststart: This builds the qt-faststart program which can modify QuickTime formatted movies (.mov or .mp4) so that the header information is located at the beginning of the file instead of the end. This allows the movie file to begin playing before the entire file has been downloaded.

[Note]  

Note

Support for most of the dependency packages requires using options passed to the configure script. View the output from ./configure --help for complete information about enabling dependency packages.

Configuring FFmpeg

Config Files

/etc/ffserver.conf and ~/.ffmpeg/ffserver-config

You'll find a sample ffserver configuration file at doc/ffserver.conf in the source tree.

Contents

Installed Programs: ffmpeg, ffplay, ffprobe, ffserver, and qt-faststart
Installed Libraries: libavcodec.so, libavdevice.so, libavfilter.so, libavformat.so, libavutil.so, libpostproc.so, libswresample.so, and libswscale.so
Installed Directories: /usr/include/libav{codec,device,filter,format,util}, /usr/include/libpostproc, /usr/include/libsw{resample,scale}, /usr/share/doc/ffmpeg-4.0, and /usr/share/ffmpeg

Short Descriptions

ffmpeg

is a command-line tool to convert video files, network streams and input from a TV card to several video formats.

ffplay

is a very simple and portable media player using the ffmpeg libraries and the SDL library.

ffprobe

gathers information from multimedia streams and prints it in a human and machine-readable fashion.

ffserver

is a streaming server for everything that ffmpeg could use as input (files, streams, TV card input, webcam, etc).

qt-faststart

moves the index file to the front of quicktime (mov/mp4) videos.

libavcodec.so

is a library containing the FFmpeg codecs (both encoding and decoding).

libavdevice.so

is the FFmpeg device handling library.

libavfilter.so

is a library of filters that can alter video or audio between the decoder and the encoder (or output).

libavformat.so

is a library containing the file formats handling (mux and demux code for several formats) used by ffplay as well as allowing the generation of audio or video streams.

libavutil.so

is the FFmpeg utility library.

libpostproc.so

is the FFmpeg post processing library.

libswresample.so

is the FFmpeg audio rescaling library, it contains functions for converting audio sample formats.

libswscale.so

is the FFmpeg image rescaling library.

Last updated on 2018-05-13 21:34:13 -0500



猜你喜欢

转载自blog.csdn.net/b1480521874/article/details/80435276