Introduction to FFmpeg
Wide application of audio and video
-
Live streaming: audio and video conferencing (Tencent Conference, Zoom), entertainment live streaming (Douyu, Huya)
-
Audio and video calls: QQ, WeChat
-
Online video: Tencent Video, iQiyi
-
Short video: Douyin, Kuaishou
-
Video Surveillance: Hikvision
-
Artificial intelligence: face recognition, smart speakers
concept
The full name of FFMPEG is fast forward moving picture expert group . It is a leading multimedia framework that provides functions such as audio and video encoding, decoding, transcoding, encapsulation, decapsulation, streaming, filtering, and playback. Supports almost all audio and video formats, highly portable, cross-platform: Linux, Mac, Windows, etc., released under LGPL\GPL.
Sphere of influence
Players as the core: Baofeng Video, QQ Video, etc.
Transcoding tool as the core: format factory, etc.
Apps provided
- ffmpeg: audio and video transcoding, codec tool
- ffplay: audio and video player
- ffprobe: multimedia analyzer (view stream information, frame rate)
- ffserver: multimedia real-time broadcast streaming server
internal composition
- AVCodec: codec module
- AVFormat: encapsulation module
- AVFilter: filter module
- AVUtil: basic utility module
- AVDevice: acquisition and rendering input and output module
- swscale: video image conversion module
- swresample: audio conversion calculation module
Environment installation
- Preparation
Host or device with Ubuntu system installed
Some related software packages have been packaged and organized . If you need the latest version, you can download it from the official website according to the prompts in the text.
- Compile and install
Create an installation directorysudo mkdir -p /usr/local/ffmpeg/lib
Unzip the source codetar -jxf ffmpeg-4.3.2.tar.bz2
Go to the specified ffmpeg directory for configurationcd ffmpeg-4.3.2/
configuration: Errors will be reported many times, and this step needs to be executed repeatedly during the process. The following are referred to asconfiguration, note that this step should be run ffmpeg-4.3.2
under
./configure --prefix="/usr/local/ffmpeg/" \
--enable-gpl \
--enable-nonfree \
--enable-ffplay \
--enable-libfdk-aac \
--enable-libmp3lame \
--enable-libx264 \
--enable-libx265 \
--enable-filter=delogo \
--enable-debug \
--disable-optimizations \
--enable-libspeex \
--enable-shared \
--enable-pthreads \
--enable-version3 \
--enable-hardcoded-tables \
--extra-ldflags=-L/usr/local/ffmpeg/lib
如果报错:C compiler test failed.
解决:
sudo apt install g++
sudo apt install gcc
report errornasm/yasm not found or too old. Use --disable-x86asm for a crippled build.
解决: `sudo apt-get install yasm`
Againconfiguration
report errorERROR: libfdk_aac not found
解决:
①官⽹下载fdk-aac源码:https://jaist.dl.sourceforge.net/project/opencore-amr/fdk-aac/
②解压fdk-aac:
tar -zxf fdk-aac-2.0.1.tar.gz
并到指定目录:
cd fdk-aac-2.0.1
③进行配置
./configure --prefix=/usr/local/ffmpeg --enable-shared
④源码编译再安装
make -j8
sudo make install
添加环境变量:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/ffmpeg/lib/pkgconfig/
Againconfiguration
如果依旧是 ERROR: libfdk_aac not found
可能是缺少pkg-config
解决方案:sudo apt install pkg-config
report errorERROR: libmp3lame >= 3.98.3 not found
解决:
①官⽹下载mp3lame源码:https://sourceforge.net/projects/lame/
②解压lame文件并到指定目录下
tar -zxf lame-3.100.tar.gz
cd lame-3.100/
③进行配置
./configure --prefix=/usr/local/ffmpeg --enable-shared
④编译及安装
make -j8
sudo make install
Againconfiguration
report errorERROR: speex not found using pkg-config
解决:
https://www.speex.org/downloads/ 下载Speex Source Code
tar -zxf speex-1.2.0.tar.gz
cd speex-1.2.0/
./configure --prefix=/usr/local/ffmpeg
make -j8
sudo make install
Againconfiguration
report errorERROR: libx264 not found
解决:
wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
tar jxf x264-master.tar.bz2
./configure --prefix=/usr/local/ffmpeg/ --enable-shared --disable-asm
make -j8
sudo make install
Againconfiguration
report errorERROR: x265 not found using pkg-config
解决:
http://ftp.videolan.org/pub/videolan/x265/
tar -zxf x265_3.2.tar.gz
cd x265_3.2/build/linux
sudo apt-get install cmake
./make-Makefiles.bash
make -j8
sudo make install
Againconfiguration
Execute again if no error is reported (in the ffmpeg directory)
make -j8
sudo make install
============================================================
After the installation is complete, it is found that there are no applications such as ffplay in the /usr/local/ffmpeg/bin directory, and SDL needs to be installed
解决:
tar -zxf SDL2-2.0.12.tar.gz
cd SDL2-2.0.12/
./configure --prefix=/usr/local/ffmpeg/ --enable-shared
make -j8
sudo make install
Re-run "ffmpegconfigurationcommand", recompile and install ffmpeg, and
make -j8
sudo make install
You will find that there are already ffmpeg, ffplay, ffprobe and other applications in the /usr/local/ffmpeg/bin directory.
============================================================
Execution ffmpeg
, error message: The program 'ffmpeg' is currently not installed. You can install it bytyping: sudo apt install ffmpeg
解决方法:
1、修改系统环境变量: sudo vim /etc/profile文件最后加上export PATH="/usr/local/ffmpeg/bin:$PATH"
2、sudo vim /etc/ld.so.conf 文件最后加上 /usr/local/ffmpeg/lib
3、再执行命令 : sudo ldconfig
Then run the ffmpeg command to have the following information: (Also report an error and try to restart the machine)
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --prefix=/usr/local/ffmpeg/ --enable-gpl --enable-nonfree --enable-ffplay --enable-libfdk-aac --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --extra-ldflags=-L/usr/local/ffmpeg/lib
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
============================================================
After executing the ffplay command, it prompts an error: Could not initialize SDL-No available video device(Did you set the DISPLAY variable?)
1、安装依赖包
sudo apt-get install libasound2-dev
sudo apt-get install libpulse-dev
sudo apt-get install libx11-dev
sudo apt-get install xorg-dev
2、重新编译安装SDL(cd SDL2-2.0.12/)
./configure --prefix=/usr/local/ffmpeg/ --enable-shared --enable-video-x11 --enable-x11-shared --enable-video-x11-vm
make -j8
sudo make install
3、重新配置、编译、安装ffmpeg,再运行ffplay命令,即可正常运行输入ffmpeg -version,得到如下信息,说明ffmpeg安装成功。
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --prefix=/usr/local/ffmpeg/ --enable-gpl --enable-nonfree --enable-ffplay --enable-libfdk-aac --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --extra-ldflags=-L/usr/local/ffmpeg/lib
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Finally test it ffplay testVideo.mkv
(just find a video to see if it can be played successfully)
Introduction to FFmpeg source directory
Tools supported by FFmpeg:
- FFmpeg encoding support and customization: configure --help
- FFmpeg encoder support: configure --list-encoders
- FFmpeg decoder support: configure --list-decoders
- FFmpeg package support: configure --list-muxers
- FFmpeg decapsulation support: configure --list-demuxers
- FFmpeg communication protocol support: configure --list-protocols
Tools supported by the current environment:
- FFmpeg encapsulation format support: ffmpeg -muxers / ffmpeg -demuxers / ffmpeg -formats
- FFmpeg encoding format support: ffmpeg -encoders / ffmpeg -codecs
- FFmpeg decoding format support: ffmpeg -decoders / ffmpeg -codecs
- FFmpeg filter support: ffmpeg -filters
FFmpeg audio and video processing flow
Different packaging formats use different containers to hold audio and video streams (frames) in different arrangements.
The essence of encoding - compression, such as H264/H265/AAC can be understood as a compressed format (encoding format).
Video encoding must be lossy.
FFprobe tool introduction
- View help information:
ffprobe --help
Command format:ffprobe [OPTIONS] [INPUT_FILE]
- Check the multimedia package:
ffprobe -show_packets -show_data testVideo.flv
- View package format:
ffprobe -show_format testVideo.flv
- View the frame information of the video file:
ffprobe -show_frames testVideo.flv
- To view the stream information of a video file:
ffprobe -show_streams testVideo.flv
- Formatted display:
ffprobe -of json -show_format testVideo.flv
ffprobe -print_format csv -show_packets out.mp4 > outMp4.csv
Introduction to FFplay tools
- View help information:
ffplay --help
Command format:ffplay [options] input_file
- Play local stream:
ffplay -window_title "Testwindow" testVideo.flv
- Play network stream:
ffplay http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8