compile and install ffmpeg on Ubuntu

compile and install ffmpeg on Ubuntu

there are three steps in build ffmpeg
configuration (with a configure script)
compilation (with make)
installation (with make install)

1. configuration
./configure --prefix=$HOME/ffmpeg_build  # run it under ffmpeg top directory
but a error occured during this configuration. it said yasm not installed. so to install it.

about yasm:
An assembler for x86 optimizations used by x264 and FFmpeg. Highly recommended or your resulting build may be very slow.
If your repository offers a yasm package ≥ 1.2.0 then you can install that instead of compiling

the yasm package in my repository is less than 1.2.0, so i did source code installation
cd /work/ffmpeg/ffmpeg-3.2.2
wget 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="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
make distclean
notice:
a. --bindir="$HOME/bin is the directory yasm to be installed to
b. you should add $HOME/bin to $PATH otherwise the same error will continue to occur in configuration step.
after yasm installed, execute ffmpeg configuration again. and it succeeded.

2. make
run make under ffmpeg home directory

3. install
make install

after step 3, the ffmpeg build is finished. the build results are:
$HOME/ffmpeg_build/lib:          all ffmpeg libs such as libavcodec.a and libavformat.a
$HOME/ffmpeg_build/include   ffmpeg header files(APIs)
$HOME/ffmpeg_build/bin          ffmpeg executable programs, namely ffmpeg, ffplayer and ffserver
in order to run ffmpeg program in any directory, we can add $HOME/ffmpeg_build/bin to $PATH(and export $PATH)

references
1. Compile FFmpeg on Ubuntu, Debian, or Mint
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
2. wiki: Compilation Guide Generic
https://trac.ffmpeg.org/wiki/CompilationGuide/Generic#Whytocompilefromsource







### 安装 FFmpeg 的方法 #### 方法一:通过包管理器安装 在 Ubuntu 系统中,可以利用 `apt` 包管理器快速安装 FFmpeg 工具。这种方法简单易用,适合大多数用户。 运行以下命令来更新软件源并安装 FFmpeg: ```bash sudo apt update sudo apt install ffmpeg ``` 验证安装是否成功可以通过以下命令检查版本号: ```bash ffmpeg -version ``` 此方法适用于有网络连接且不需要自定义编译选项的情况[^1]。 --- #### 方法二:无 Root 权限时的用户级安装 如果没有系统的管理员权限(即无法使用 `sudo`),仍可通过手动下载和配置的方式,在本地环境中安装 FFmpeg 并设置环境变量。 具体操作流程如下: 1. 下载 FFmpeg 压缩包: ```bash wget https://ffmpeg.org/releases/ffmpeg-7.0.2.tar.xz ``` 2. 解压压缩包: ```bash tar xf ffmpeg-7.0.2.tar.xz cd ffmpeg-7.0.2 ``` 3. 配置编译参数: 运行以下命令进行配置(可根据需求调整参数): ```bash ./configure --prefix=$HOME/local/ffmpeg --enable-shared ``` 4. 编译与安装: 执行以下命令完成编译过程: ```bash make && make install ``` 5. 设置环境变量: 修改用户的 `.bashrc` 文件以添加 FFmpeg 到 PATH 中: ```bash echo 'export PATH=$PATH:$HOME/local/ffmpeg/bin' >> ~/.bashrc source ~/.bashrc ``` 完成后再次测试 FFmpeg 是否可用: ```bash ffmpeg -version ``` 这种方式无需管理员权限即可实现功能完整的 FFmpeg 使用[^2]。 --- #### 方法三:从源码完全定制化安装 对于需要特定功能支持或者最新版 FFmpeg 的场景,可以从官网获取最新的源代码,并按照官方文档逐步编译安装。 以下是基本步骤概述: 1. 下载 FFmpeg 源码: ```bash wget https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 tar xjvf ffmpeg-snapshot.tar.bz2 cd ffmpeg ``` 2. 安装依赖项: 在正式编译之前,需先满足必要的开发库依赖关系。执行以下命令安装所需组件: ```bash sudo apt-get install autoconf automake build-essential libass-dev \ libfreetype6-dev libsdl2-dev libtool libva-dev libvdpau-dev \ libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev ``` 3. 开始编译: 根据实际需求指定额外的功能模块或优化选项后启动构建脚本: ```bash ./configure --prefix=/usr/local --extra-libs=-ldl --enable-version3 --disable-debug --disable-doc --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree --enable-postproc --enable-small --enable-static --enable-swresample --enable-avfilter --enable-pthreads --enable-network --enable-dct --enable-idct --enable-error-resilience --enable-runtime-cpudetect --enable-hardcoded-tables --enable-pic --enable-lto --enable-cross-compile --arch=x86_64 --cpu=native --target-os=linux-gnu --pkgconfigdir=/usr/lib/x86_64-linux-gnu/pkgconfig/ make -j$(nproc) sudo make install ``` 注意:上述命令中的某些外部编码解码器可能受专利保护,因此需要单独授权或许可才能合法分发其二进制形式的产品[^3]。 最后一步同样要记得把新安装位置加入到全局搜索路径里去以便随时调用它作为常规命令行工具之一。 --- ### 注意事项 无论采用哪种方式进行部署,请务必确认最终能够正常加载该程序及其关联动态链接库文件;另外考虑到不同发行版本之间可能存在细微差异之处,则建议参照对应手册进一步核实细节部分设定情况后再行动作决定。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值