- [Statement] Course learning address: https://ke.qq.com/course/468797
table of Contents
Linux environment construction
Windows environment setup
- Go to the official ffmpeg to download the compiled Windows shared library;
- Official website: https://ffmpeg.org/
- Copy the executable file ffmpeg.exe ffplay.exe ffprobe.exe to the C:\Windows directory;
- Copy the corresponding dynamic library to the C:\Windows\SysWOW64 directory;
- 注:WOW64 (Windows-on-Windows 64-bit)
- Enter ffmpeg -version in the command line window to check the version, but to confirm whether the environment is successfully built
[Configuration environment ubuntu desktop 16.04 + ffmpeg 4.2.1]
Linux environment construction
Create a directory
- Created in the home directory
- ffmpeg_sources: used to download source files
- ffmpeg_build: store compiled library files
- bin: store binary files (ffmpeg, ffplay, ffprobe, X264, X265, etc.)
cd ~ mkdir ffmpeg_sources ffmpeg_build bin
Installation dependencies
sudo apt-get update -qq && sudo apt-get -y install \ autoconf \ automake \ build-essential \ cmake \ git-core \ libass-dev \ libfreetype6-dev \ libsdl2-dev \ libtool \ libva-dev \ libvdpau-dev \ libvorbis-dev \ libxcb1-dev \ libxcb-shm0-dev \ libxcb-xfixes0-dev \ pkg-config \ texinfo \ wget \ zlib1g-dev
Install common third-party libraries
NASM
- Install using source code
cd ~/ffmpeg_sources && \ wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2 && \ tar xjvf nasm-2.14.02.tar.bz2 && \ cd nasm-2.14.02 && \ ./autogen.sh && \ PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \ make && \ make install
Yasm
- Install using source code
cd ~/ffmpeg_sources && \ wget -O yasm-1.3.0.tar.gz https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \ tar xzvf yasm-1.3.0.tar.gz && \ cd yasm-1.3.0 && \ ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \ make && \ make install
libx264
- H.264 video encoder. For more information and usage examples, please refer to H.264 Encoding Guide
- Configure when compiling ffmpeg: --enable-gpl --enable-libx264.
- Compile using source code:
cd ~/ffmpeg_sources && \ git -C x264 pull 2> /dev/null || git clone --depth 1 https://code.videolan.org/videolan/x264.git && \ cd x264 && \ PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --enable-pic && \ PATH="$HOME/bin:$PATH" make && \ make install
libx265
- H.265/HEVC video encoder. For more information and usage examples, please refer to H.265 Encoding Guide .
- Configure when compiling ffmpeg: --enable-gpl --enable-libx265.
sudo apt-get install mercurial libnuma-dev && \ cd ~/ffmpeg_sources && \ if cd x265 2> /dev/null; then hg pull && hg update && cd ..; else hg clone https://bitbucket.org/multicoreware/x265; fi && \ cd x265/build/linux && \ PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off ../../source && \ PATH="$HOME/bin:$PATH" make && \ make install
libvpx
- VP8/VP9 video codec. For more information and usage examples, refer to VP9 Video Encoding Guide .
- Configure when compiling ffmpeg: --enable-libvpx.
cd ~/ffmpeg_sources && \ git -C libvpx pull 2> /dev/null || git clone --depth 1 https://github.com/webmproject/libvpx.git && \ cd libvpx && \ PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \ PATH="$HOME/bin:$PATH" make && \ make install
libfdk-aac
- AAC Audio Encoding. For more information and usage examples, refer to AAC Audio Encoding Guide .
- Configure when compiling ffmpeg: --enable-libfdk-aac (if you have already configured --enable-gpl, you need to add --enable-nonfree).
cd ~/ffmpeg_sources && \ git -C fdk-aac pull 2> /dev/null || git clone --depth 1 https://github.com/mstorsjo/fdk-aac && \ cd fdk-aac && \ autoreconf -fiv && \ ./configure --prefix="$HOME/ffmpeg_build" --disable-shared && \ make && \ make install
libmp3lame
- MP3 audio encoder.
- Configure when compiling ffmpeg: --enable-libmp3lame.
cd ~/ffmpeg_sources && \ git clone --depth 1 https://gitee.com/hqiu/lame.git && \ cd lame && \ PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm && \ PATH="$HOME/bin:$PATH" make && \ make install
libopus
- Opus audio codec.
- Configure when compiling ffmpeg: --enable-libopus.
cd ~/ffmpeg_sources && \ git -C opus pull 2> /dev/null || git clone --depth 1 https://github.com/xiph/opus.git && \ cd opus && \ ./autogen.sh && \ ./configure --prefix="$HOME/ffmpeg_build" --disable-shared && \ make && \ make install
libaom
- AV1 video codec:
- Configure when compiling ffmpeg: --enable-libaom.
- AV1 is not supported first, and there is a problem with the compilation.
cd ~/ffmpeg_sources && \ git -C aom pull 2> /dev/null || git clone --depth 1 https://aomedia.googlesource.com/aom && \ mkdir -p aom_build && \ cd aom_build && \ PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off -DENABLE_NASM=on ../aom && \ PATH="$HOME/bin:$PATH" make && \ make install cd ~/ffmpeg_sources && \ git -C aom pull 2> /dev/null || git clone --depth 1 https://github.com/mozilla/aom.git && \ mkdir -p aom_build && \ cd aom_build && \ PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off -DENABLE_NASM=on ../aom && \ PATH="$HOME/bin:$PATH" make && \ make install
FFmpeg
cd ~/ffmpeg_sources && \ wget -O ffmpeg-4.2.1.tar.bz2 https://ffmpeg.org/releases/ffmpeg-4.2.1.tar.bz2 && \ tar xjvf ffmpeg-4.2.1.tar.bz2 && \ cd ffmpeg-4.2.1 && \ PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ --prefix="$HOME/ffmpeg_build" \ --pkg-config-flags="--static" \ --extra-cflags="-I$HOME/ffmpeg_build/include" \ --extra-ldflags="-L$HOME/ffmpeg_build/lib" \ --extra-libs="-lpthread -lm" \ --bindir="$HOME/bin" \ --enable-gpl \ --enable-libass \ --enable-libfdk-aac \ --enable-libfreetype \ --enable-libmp3lame \ --enable-libopus \ --enable-libvorbis \ --enable-libvpx \ --enable-libx264 \ --enable-libx265 \ --enable-nonfree && \ PATH="$HOME/bin:$PATH" make && \ make install && \ hash -r
- Then log in to the system again or execute the following command in the current shell session to identify the location of the newly installed ffmpeg:
source ~/.profile
- After compilation, the general situation of ffmpeg_build ffmpeg_sources bin directory
lqf@ubuntu:~/ffmpeg_build$ ls bin include lib share lqf@ubuntu:~/ffmpeg_sources$ ls fdk-aac lame-3.100.tar.gz opus yasm-1.3.0.tar.gz ffmpeg-4.2.1 libvpx x264 ffmpeg-4.2.1.tar.bz2 nasm-2.14.02 x265 lame nasm-2.14.02.tar.bz2 yasm-1.3.0 lqf@ubuntu:~/bin$ ls ffmpeg ffplay ffprobe lame nasm ndisasm vsyasm x264 yasm ytasm
use
- Now, you can open a terminal, enter the ffmpeg command, and it should execute the new ffmpeg.
- If you need multiple users to use your newly compiled ffmpeg at the same time, you can move or copy the ffmpeg binary file from ~/bin to /usr/local/bin.
Documentation
- You can use man ffmpeg to access the document locally:
- echo "MANPATH_MAP $HOME/bin $HOME/ffmpeg_build/share/man" >> ~/.manpath
- You may have to log out of the system and then log back in to man ffmpeg to take effect.
- The documentation in HTML format is located at ~/ffmpeg_build/share/doc/ffmpeg .
- You can refer to the online FFmpeg documentation .