准备工作
ubuntu要安装一下必要工具,比如:
# gcc, g++工具链
sudo apt-get install gcc g++
#Makefile
sudo apt-get install make
#安装git
sudo apt-get install git
下载ffmpeg源码:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
配置ffmpeg
cd ffmpeg/
./configure --enable-libmp3lame \
--enable-libfdk-aac \
--enable-gpl \
--enable-nonfree \
--enable-libx264 \
--enable-libx265 \
--enable-ffplay \
--disable-static \
--enable-shared \
--prefix=/home/lorien/work/media/ffmpeg/install
通过configure命令来生成Makefile,–prefix参数是配置软件安装最终目录。
配置可能会失败,提示缺失依赖组件,缺什么补什么就行,大致安装如下以来组件:
# 汇编编译
sudo apt-get install yasm
# libfdk-aac
sudo apt-get install libfdk-aac-dev
# x264
sudo apt-get install libx264-dev
# x265
sudo apt-get install libx265-dev
# ffplay使用,缺少这个,不会生成ffplay
sudo apt install libsdl2-dev
# libmp3lame-dev
sudo apt-get install libmp3lame-dev
注意: libsdl2-dev库是生成ffplay工具用的,如果缺少这个lib,编译能成功,但不会生成ffplay工具。
编译、安装
执行
make -j4
make install
上述命令执行完之后,编译产物会安装到prefix参数指定的路径下面,我设置的是:/home/lorien/work/media/ffmpeg/install
接下来,将bin/和lib/路径添加到环境变量,方便使用ffmpeg工具,执行如下:
sudo vim ~/.bashrc
# 在文件末尾添加两行
export PATH=$PATH:/home/lorien/work/media/ffmpeg/install/bin
export LD_LIBRARY_PATH=/home/lorien/work/media/ffmpeg/install/lib
source ~/.bashrc
下面就可以体验使用ffmpeg工具了:
# 播放mp4视频文件
ffplay test.mp4
#查看mp4文件头信息
ffprobe test.ma4
ffprobe version N-106442-g8ae15b5655 Copyright (c) 2007-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --enable-libmp3lame --enable-libfdk-aac --enable-gpl --enable-nonfree --enable-libx264 --enable-libx265 --enable-ffplay --disable-static --enable-shared --prefix=/home/lorien/work/media/ffmpeg/install
libavutil 57. 24.101 / 57. 24.101
libavcodec 59. 25.100 / 59. 25.100
libavformat 59. 20.101 / 59. 20.101
libavdevice 59. 6.100 / 59. 6.100
libavfilter 8. 29.100 / 8. 29.100
libswscale 6. 6.100 / 6. 6.100
libswresample 4. 6.100 / 4. 6.100
libpostproc 56. 5.100 / 56. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: isommp41mp42
creation_time : 2022-03-27T03:21:38.000000Z
Duration: 00:00:33.21, start: 0.000000, bitrate: 1609 kb/s
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt2020nc/bt2020/arib-std-b67, progressive), 960x540, 1539 kb/s, 24.01 fps, 30 tbr, 600 tbn (default)
Metadata:
creation_time : 2022-03-27T03:21:38.000000Z
handler_name : Core Media Video
vendor_id : [0][0][0][0]
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 65 kb/s (default)
Metadata:
creation_time : 2022-03-27T03:21:38.000000Z
handler_name : Core Media Audio
vendor_id : [0][0][0][0]