logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

Compile FFmpeg on Ubuntu, Debian, or Mint

by digipine posted Nov 02, 2017
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
Get the Dependencies
 
Copy and paste the whole code box for each step.
 
sudo apt-get update
sudo apt-get -y --force-yes install autoconf automake build-essential libass-dev libfreetype6-dev libgpac-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
mkdir ~/ffmpeg_sources
Notes:
 
Server users can omit the ffplay and x11grab dependencies: libsdl1.2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev.
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 (ffmpeg, ffplay, ffserver, x264, 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.3.0 then you can install that instead of compiling:
 
sudo apt-get install yasm
Otherwise you can compile:
 
cd ~/ffmpeg_sources
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
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
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).
 
sudo apt-get install unzip
cd ~/ffmpeg_sources
unzip fdk-aac.zip
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
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
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
tar xjvf libvpx-v1.3.0.tar.bz2
cd libvpx-v1.3.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
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. To use it:
 
Navigate to ~/bin and execute the binary: cd ~/bin && ./ffmpeg -i ~/input.mp4 ~/videos/output.mkv (notice the ./)
Or you can use the full path to the binary: /home/yourusername/bin/ffmpeg -i ../input.mp4 ../videos/output.mkv
Or if you simply want to just issue the ffmpeg command and have your shell use your compiled binary see the Persistent Environment Variables section below.
Persistent Environment Variables
 
You can tell your shell (assuming you're using Bash) to persistently use your new ffmpeg in ~/bin. The first command will allow you to simply run man ffmpeg to get the FFmpeg man pages. The second command will source ~/.profile which will add ~/bin to your $PATH. In short, the following commands will allow you to simply type ffmpeg and man ffmpeg in your terminal and they will "just work":
 
echo "MANPATH_MAP $HOME/bin $HOME/ffmpeg_build/share/man" >> ~/.manpath
. ~/.profile
Note:
 
This may reset custom variables in the current shell session.
This assumes you are using the default ~/.profile (and therefore ~/.bashrc).
This assumes you are using Bash shell.
Sourcing the default ~/.profile will also source ~/.bashrc.
You may have to log out and then log in for man ffmpeg to work.
Don't worry: you can undo any of this as shown in Reverting Changes Made by This Guide.
See ​Ubuntu Wiki: Persistent Environment Variables for more info.
 
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.
HTML formatted documentation is available in ~/ffmpeg_build/share/doc/ffmpeg.
You can keep the ffmpeg_sources directory if you plan on updating later. See Updating FFmpeg below for more details followed by instructions for reverting all changes made by this guide.
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,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,ffserver,vsyasm,x264,x265,yasm,ytasm}
sudo apt-get autoremove autoconf automake build-essential cmake libass-dev libfreetype6-dev libgpac-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
 
TAG •

List of Articles
No. Subject Author Date Views
104 프로세스 능력 성숙도 모델(CMMI)의 적용 digipine 2017.10.28 698
103 프로그래밍 언어 순위 2023년 file digipine 2023.10.30 142
102 포렌식을 활용한 정보보호 digipine 2017.11.02 434
101 초고속망 통신사 DNS 서버 주소 모음 - DNS 설정 digipine 2017.11.03 2630
100 임베디드SW 개발자센터 이용안내(성남시 분당구, 개발공간 무료제공) digipine 2017.11.02 588
99 이벤트 텍소노미(Event Taxonomy)란 무엇인가요? digipine 2023.08.11 243
98 유닉스/리눅스 명령어 레퍼런스 digipine 2017.11.03 745
97 윈도우즈 도스 커멘드(Command) 네트워크 관련 명령어 lizard2019 2019.02.07 1342
96 윈도우 한영 전환 쉬프트 스페이스로 변경 digipine 2017.11.03 413
95 우분투 Nabi 한글 입력기 Tray(트레이) 상단 메뉴바로 옮기기 digipine 2017.11.03 1630
94 우분투 18.04 MongoDB 설치 및 구성 lizard2019 2021.02.26 501
93 언어 IDE 별로 git ignore 파일을 자동으로 만들어 주는 사이트 엉뚱도마뱀 2018.12.17 122392
92 악성코드 종류 구분 digipine 2017.11.13 960
91 수학적 구조물 모델링 만들기 소개 비디오 엉뚱도마뱀 2018.09.24 1050
90 소프트웨어 테스팅 전문가들을 위한 사이트 digipine 2017.11.02 609
89 비밀번호 해쉬에 Salt(소금) 첨가하기 file 엉뚱도마뱀 2017.11.23 4272
88 리눅스 커널의 Swap Memory에 대해서 digipine 2017.11.02 675
87 리눅스 /dev/random을 이용한 랜덤값 생성 엉뚱도마뱀 2017.11.22 1554
86 대칭키 암호화관련 개념 정리 digipine 2017.11.09 1640
85 난수발생기 개론 엉뚱도마뱀 2017.11.22 4311
Board Pagination Prev 1 2 3 4 5 6 Next
/ 6