ubuntu上安装ffmpeg方法

Compile FFmpeg on Ubuntu, Debian, or Mint

This guide for supported releases of UbuntuDebian, and Linux Mint will provide a local install of the latest FFmpeg tools and libraries including several external encoding and decoding libraries (codecs). This will not interfere with repository packages.

You may also refer to the Generic FFmpeg Compilation Guide for additional information.

Recent static builds are also available for lazy people or those who are unable to compile. The static builds do not support non-free encoders.

Note: FFmpeg has returned in Ubuntu 15.04 Vivid Vervet. You may still wish to compile if you experience a bug or want to customize your build, and it will not interfere with the ffmpeg package in the repository.


Get the Dependencies

Copy and paste the whole code box for each step. First install the dependencies:

sudo apt-get update
sudo apt-get -y --force-yes 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 texi2html zlib1g-dev

Note: Server users can omit the ffplay and x11grab dependencies: libsdl1.2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev.

Now make a directory for the source files that will be downloaded later in this guide:

mkdir ~/ffmpeg_sources

Compilation & Installation

You can compile ffmpeg to your liking. If you do not require certain encoders you may skip the relevant section and then remove the appropriate ./configure option in FFmpeg. For example, if libopus is not needed, then skip that section and then remove --enable-libopus from the Install FFmpeg section.

This guide is designed to be non-intrusive and will create several directories in your home directory:

  • ffmpeg_sources – Where the source files will be downloaded.
  • ffmpeg_build – Where the files will be built and libraries installed.
  • bin – Where the resulting binaries (ffmpegffplayffserverx264, and yasm) will be installed.

You can easily undo any of this as shown in Reverting Changes Made by This Guide.

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:

sudo apt-get install yasm

Otherwise you can compile:

cd ~/ffmpeg_sources
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

libx264

H.264 video encoder. See the H.264 Encoding Guide for more information and usage examples.

Requires ffmpeg to be configured with --enable-gpl --enable-libx264.

If your repository offers a libx264-dev package ≥ 0.118 then you can install that instead of compiling:

sudo apt-get install libx264-dev

Otherwise you can compile:

cd ~/ffmpeg_sources
wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
tar xjvf last_x264.tar.bz2
cd x264-snapshot*
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
PATH="$HOME/bin:$PATH" make
make install
make distclean

libx265

H.265/HEVC video encoder. See the H.265 Encoding Guide for more information and usage examples.

sudo apt-get install cmake mercurial
cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make
make install
make distclean

libfdk-aac

AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples.

Requires ffmpeg to be configured with --enable-libfdk_aac (and --enable-nonfree if you also included --enable-gpl).

cd ~/ffmpeg_sources
wget -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="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

libmp3lame

MP3 audio encoder.

Requires ffmpeg to be configured with --enable-libmp3lame.

If your repository offers a libmp3lame-dev package ≥ 3.98.3 then you can install that instead of compiling:

sudo apt-get install libmp3lame-dev

Otherwise you can compile:

sudo apt-get install nasm
cd ~/ffmpeg_sources
wget 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="$HOME/ffmpeg_build" --enable-nasm --disable-shared
make
make install
make distclean

libopus

Opus audio decoder and encoder.

Requires ffmpeg to be configured with --enable-libopus.

If your repository offers a libopus-dev package ≥ 1.1 then you can install that instead of compiling:

sudo apt-get install libopus-dev

Otherwise you can compile:

cd ~/ffmpeg_sources
wget http://downloads.xiph.org/releases/opus/opus-1.1.tar.gz
tar xzvf opus-1.1.tar.gz
cd opus-1.1
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

libvpx

VP8/VP9 video encoder and decoder. See the VP8 Video Encoding Guide for more information and usage examples.

Requires ffmpeg to be configured with --enable-libvpx.

cd ~/ffmpeg_sources
wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.4.0.tar.bz2
tar xjvf libvpx-1.4.0.tar.bz2
cd libvpx-1.4.0
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests
PATH="$HOME/bin:$PATH" make
make install
make clean

ffmpeg

cd ~/ffmpeg_sources
wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
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" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree
PATH="$HOME/bin:$PATH" make
make install
make distclean
hash -r

Conclusion

Installation is now complete and ffmpeg is now ready for use. Your newly compiled FFmpeg programs are in ~/bin.

Usage

There are several methods to use your new ffmpeg.

  • Navigate to ~/bin and execute the binary: cd ~/bin && ./ffmpeg -i ~/input.mp4 ~/videos/output.mkv (notice the ./)
  • Or use the full path to the binary: /home/yourusername/bin/ffmpeg -i ../input.mp4 ../videos/output.mkv

If you want the ffmpeg command to just work from anywhere:

  • Log in and log out
  • Or run source ~/.profile

Note: ~/bin is included in the standard Ubuntu $PATH by default (via the ~/.profile file), but only when the ~/bin directory actually exists. This is why you must log out then log in or run source ~/.profile if you just created ~/bin. See Ubuntu Wiki: Persistent Environment Variables for more info.

Documentation

If you want to run man ffmpeg to have local access to the documentation:

echo "MANPATH_MAP $HOME/bin $HOME/ffmpeg_build/share/man" >> ~/.manpath

You may then have to log out and then log in for man ffmpeg to work.

HTML formatted documentation is available in ~/ffmpeg_build/share/doc/ffmpeg.

You can also refer to the online FFmpeg documentation, but remember that it is regenerated daily and is meant to be used with the most current ffmpeg (meaning an old build may not be compatible with the online docs).

Additional Notes

  • See the H.264 Encoding Guide for some encoding examples.
  • If you do not see FFmpeg developers in your ffmpeg console output then something went wrong and you're probably using the fake "ffmpeg" from the repository (the counterfeit "ffmpeg" was eventually removed and the real ffmpeg returned in 15.04).
  • You can delete the ffmpeg_sources directory if you want to.

Updating FFmpeg

Development of FFmpeg is active and an occasional update can give you new features and bug fixes. First you need to delete (or move) the old files:

rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffplay,ffserver,vsyasm,x264,x265,yasm,ytasm}

Now just follow the guide from the beginning.


Reverting Changes Made by This Guide

rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffplay,ffserver,vsyasm,x264,x265,yasm,ytasm}
sudo apt-get autoremove autoconf automake build-essential cmake libass-dev libfreetype6-dev \
  libmp3lame-dev libopus-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev \
  libvorbis-dev libvpx-dev libx264-dev libxcb1-dev libxcb-shm0-dev ibxcb-xfixes0-dev mercurial texi2html zlib1g-dev
sed -i '/ffmpeg_build/c\' ~/.manpath
hash -r

If You Need Help

Feel free to ask questions at the #ffmpeg IRC channel or the ffmpeg-user mailing list.


Also See

Ubuntu 18.04上安装ffmpeg,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了必要的编译工具和依赖项。你可以使用以下命令安装它们: ```shell sudo apt-get update sudo apt-get install build-essential ``` 2. 下载ffmpeg的源代码。你可以在官方网站或者其他可信的资源中找到最新版本的源代码。 3. 解压下载的源代码文件。你可以使用以下命令进入解压后的文件夹: ```shell cd ffmpeg-<version> ``` 4. 配置和编译ffmpeg。你可以按照以下命令依次执行: ```shell ./configure make sudo make install ``` 5. 安装完成后,你可以通过以下命令检查ffmpeg是否成功安装: ```shell ffmpeg -version ``` 如果你想卸载或重新安装ffmpeg,你可以按照以下步骤进行操作: 卸载ffmpeg: 1. 删除相关的软链接: ```shell sudo rm /usr/bin/ffmpeg sudo rm /usr/bin/ffprobe ``` 2. 清空环境变量中修改的地方并更新: ```shell sudo ldconfig ``` 重新安装ffmpeg: 1. 如果你需要更新、回退或增加库支持,你可以按照以下步骤进行操作: - 删除ffbuild目录下带"config"字段的文件:`rm ffmpeg-<version>/ffbuild/config` - 删除相关的软链接: ```shell sudo rm /usr/bin/ffmpeg sudo rm /usr/bin/ffprobe ``` - 重新编译和安装ffmpeg: ```shell cd ffmpeg-<version> ./configure make sudo make install ``` - 配置ffmpeg依赖环境并更新环境变量: ```shell sudo nano /etc/ld.so.conf ``` 在打开的文件中添加ffmpeg所在的目录,保存并关闭文件。然后运行以下命令更新环境变量: ```shell sudo ldconfig ``` 通过以上步骤,你可以在Ubuntu 18.04上安装、卸载或重新安装ffmpeg。请根据你的需求选择相应的操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Ubuntu 18.04 安装FFmpeg](https://blog.csdn.net/weixin_43804210/article/details/108198399)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Ubuntu 18.04 安装ffmpeg(支持GPU硬件加速)](https://blog.csdn.net/txf1931783593/article/details/128250457)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值