ubuntu1604 X64 编译 ffmpeg

01 测试环境 ubuntuX64_1604

ubuntu-16.04-desktop-amd64.iso
http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-amd64.iso

VMWare WorkStation 12

系统安装完成后,执行

sudo apt-get update
sudo apt-get upgrade

02官方编译说明文档

https://trac.ffmpeg.org/wiki/CompilationGuide

03 编译 ffmpeg for ubuntuX64_1604 版本

03.01 安装git

sudo apt-get install git

03.02 安装 ffmpeg 编译依赖

sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev \
  libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \
  libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev

sudo apt-get -y install libsdl1.2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev

sudo apt-get -y install yasm

03.03 下载 ffmpeg 源代码

cd $HOME
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd $HOME/ffmpeg/
# git branch -a # 查看最新release版本是 remotes/origin/release/3.1,迁出最新稳定版本代码
git checkout -b 3.1 remotes/origin/release/3.1
# git branch -vv

03.04 编译 ffmpeg 版本

mkdir -p $HOME/ffmpeg/build
# --enable-debug 是生成debug版本
make distclean # 确保环境干净
# 生成ffmpeg、ffprobe、ffplay、ffserver
./configure --prefix=$HOME/ffmpeg/build --enable-static --disable-shared --enable-version3 --enable-gpl --enable-memalign-hack --enable-ffplay
make && make install

# 生成$HOME/ffmpeg/build/bin/
$HOME/ffmpeg/build/bin/ffmpeg
$HOME/ffmpeg/build/bin/ffplay
$HOME/ffmpeg/build/bin/ffprobe
$HOME/ffmpeg/build/bin/ffserver

03.05 GDB 调试 ffmpeg 方法

GDB调试:
有两种方式可以进入GDB,一种就是直接

A:直接在命令行上使用:gdb

调试时应当是ffmpeg_g,它带有调试符号;而不是ffmpeg
gdb ffmpeg_g

B:在命令行上输入gdb,然后再在gdb中用file命令加载要调试

gdb
file ffmpeg_g
# 用 "set args 参数值1  参数值2...."来设置输入参数
set args -h filter=transform
set args -i input.mp4 -vf transform=input_stereo_format=MONO:w_subdivisons=4:h_subdivisons=4:max_cube_edge_length=512 -qscale 20 output.mp4
# 以上参数是ffmpeg加入facebook/transform代码的设置参数,自己调试时改成自己想要的参数就好了,ffmpeg常用参数一览表
b transform_pos  // b <函数名称> : b: Breakpoint的简写,设置断点。两可以使用“行号”“函数名称”“执行地址”等方式指定断点位置。
b 45    // b <行号>
r       // Run的简写,运行被调试的程序。如果此前没有下过断点,则执行完整个程序;如果有断点,则程序暂停在第一个可用断点处。
p face  // p <变量名称> : Print的简写,显示指定变量(临时变量或全局变量)的值。
c       // Continue的简写,继续执行被调试程序,直至下一个断点或程序结束。
i b     // 查看断点信息(i-->info,b-->break)
d <断点标号>  // 删除某个断点

03.06 测试 ffmpeg

mkdir -p $HOME/ffmpeg/video
# 准备视频文件
cp /mnt/hgfs/vlc/yii2_001.flv $HOME/ffmpeg/video/yii2_001.flv
# 查看视频文件信息
./build/bin/ffprobe $HOME/ffmpeg/video/yii2_001.flv
# 测试下播放效果
./build/bin/ffplay $HOME/ffmpeg/video/yii2_001.flv

播放效果如图:
ubuntu1604 X64 编译 ffmpeg_第1张图片

04 按照官网完整编译

#!/bin/sh

# 2016-09-26 严格按照官网编译ffmpeg

# 01 安装必要的库文件
sudo apt-get update
sudo apt-get upgrade

sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev \
  libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \
  libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev

sudo libsdl1.2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev


# 构建目录
cd $HOME
mkdir -p $HOME/ffmpeg/
mkdir -p $HOME/ffmpeg/src
mkdir -p $HOME/ffmpeg/build

path_src=$HOME/ffmpeg/src
path_build=$HOME/ffmpeg/build
path_bin=$HOME/ffmpeg/build/bin

# yasm-1.3.0.tar.gz  编译yasm
cd "$path_src"
wget -c -P "$path_src" http://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="$path_build" --bindir="$path_bin"
make && make install
# make distclean


# 编译x264
cd "$path_src"
wget -c -P "$path_src" http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
tar xjvf last_x264.tar.bz2
cd x264-snapshot*
./configure --prefix="$path_build" --bindir="$path_bin" --enable-static --disable-opencl
make && make install
# make distclean

# 编译x265
cd "$path_src"
sudo apt-get install cmake mercurial
hg clone https://bitbucket.org/multicoreware/x265
cd "$path_src/x265/build/linux"
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$path_build" -DENABLE_SHARED:bool=off ../../source
make && make install
# make clean

# 安装acc
cd "$path_src"
wget -c -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
tar xzvf fdk-aac.tar.gz
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure --prefix="$path_build" --disable-shared
make && make install
# make distclean

# 安装 libmp3lame 
cd "$path_src"
sudo apt-get install nasm
wget -c -P "$path_src" http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix="$path_build" --enable-nasm --disable-shared
make && make install
# make clean

# 安装 libopus
cd "$path_src"
wget -c -P "$path_src" http://downloads.xiph.org/releases/opus/opus-1.1.2.tar.gz
tar xzvf opus-1.1.2.tar.gz
cd opus-1.1.2
./configure --prefix="$path_build" --disable-shared
make && make install
# make clean

cd "$path_src"
wget -c -P "$path_src" http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.5.0.tar.bz2
tar xjvf libvpx-1.5.0.tar.bz2
cd libvpx-1.5.0
./configure --prefix="$path_build" --disable-examples --disable-unit-tests
make && make install
# make clean

# ffmpeg 编译
cd "$path_src"
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd "$path_src/ffmpeg"
# git branch -a # 查看最新release版本是 remotes/origin/release/3.1,迁出最新稳定版本代码
git checkout -b 3.1 remotes/origin/release/3.1
# git branch -vv

cd "$path_src/ffmpeg"
PATH="$path_bin:$PATH" PKG_CONFIG_PATH="$path_build/lib/pkgconfig" ./configure \
  --pkg-config-flags="--static" \
  --prefix="$path_build" \
  --extra-cflags="-I$path_build/include -I$path_build/include/fdk-aac -I$path_build/include/libyasm -I$path_build/include/vpx -I$path_build/include/lame -I$path_build/include/opus" \
  --extra-ldflags="-L$path_build/lib" \
  --bindir="$path_bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libfreetype \
  --enable-libfdk-aac \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree \
  --enable-version3 \
  --enable-static \
  --disable-shared
# --arch=x86   # 编译32位版本
# --arch=x86_64 # 编译64位版本

make && make install
# make distclean

你可能感兴趣的:(ffmpeg)