ubuntu下編譯ffmpeg with libx264


Preparation

Remove any existing packages:

sudo apt-get remove ffmpeg x264 libav-tools libvpx-dev libx264-dev yasm

Get the dependencies (Ubuntu Desktop users):

sudo apt-get update
sudo apt-get -y install autoconf automake build-essential checkinstall git libass-dev libfaac-dev \
  libgpac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev \
  librtmp-dev libsdl1.2-dev libspeex-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev \
  libx11-dev libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev

 

 

Installation

Yasm

Yasm is an assembler and is recommended for x264 and FFmpeg.

cd  //回到用戶家目錄
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
sudo checkinstall --pkgname=yasm --pkgversion="1.2.0" --backup=no \
  --deldoc=yes --fstrans=no --default

 

x264

H.264 video encoder. The following commands will get the current source files, compile, and install x264.

cd
git clone --depth 1 git://git.videolan.org/x264.git
cd x264
./configure --enable-static
make
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
  awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
  --fstrans=no --default
//我用的選項

--enable-shared   (--enable-debug)

 

platform:      X86

system:        LINUX

cli:           yes

libx264:       internal

shared:        yes

static:        no

asm:           yes

interlaced:    yes

avs:           avxsynth

lavf:          no

ffms:          no

gpac:          yes

gpl:           yes

thread:        posix

filters:       crop select_every

debug:         no

gprof:         no

strip:         no

PIC:           no

visualize:     no

bit depth:     8

chroma format: all

 

FFmpeg

Note: Ubuntu Server users should remove --enable-x11grab from the following command:

cd
git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame \
  --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora \
  --enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264 --enable-nonfree --enable-version3
make
sudo checkinstall --pkgname=ffmpeg --pkgversion="7:$(date +%Y%m%d%H%M)-git" --backup=no \
  --deldoc=yes --fstrans=no --default
hash –r
 
我用的選項
./configure --enable-gpl --enable-libfaac --enable-x11grab --enable-libx264 --enable-nonfree --enable-version3

Finish

Installation is now complete and FFmpeg is now ready for use.

 

測試x264是否支持mp4 output,然后再次編譯使其支持 lavf

x264 --video-filter resize:width=352,height=288,method=spline -o /home/ray/media/Linux.mp4 /mnt/hgfs/share/test.mpg

 

輸入x264 –help

Infile can be raw (in which case resolution is required),

  or YUV4MPEG (*.y4m),

  or Avisynth if compiled with support (yes).

  or libav* formats if compiled with lavf support (no) or ffms support (no).

Outfile type is selected by filename:

 .264 -> Raw bytestream

 .mkv -> Matroska

 .flv -> Flash Video

 .mp4 -> MP4 if compiled with GPAC support (yes)

 

Add lavf support to x264 (Re-compile x264)

This allows x264 to accept just about any input that FFmpeg can handle and is useful if you want to use x264 directly.

cd ~/x264
make distclean
./configure --enable-static
make
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
  awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
  --fstrans=no –default
再次測試之
輸入x264 –help
Infile can be raw (in which case resolution is required),
  or YUV4MPEG (*.y4m),
  or Avisynth if compiled with support (yes).
  or libav* formats if compiled with lavf support (yes) or ffms support (no).
Outfile type is selected by filename:
 .264 -> Raw bytestream
 .mkv -> Matroska
 .flv -> Flash Video
 .mp4 -> MP4 if compiled with GPAC support (yes)
x264 --video-filter resize:width=352,height=288,method=spline -o /home/ray/media/Linux.mp4 /mnt/hgfs/share/test.mpg
成功轉換出mp4
 

【附】第一次編譯x264與第二次編譯區別

x264 can use LAVF input if it detects a usable install of FFmpeg. Notice that the first x264 set was issued before compiling FFmpeg, therefore it will not have the option of using LAVF to open files. The later step recompiles x264 after FFmpeg is installed, detecting LAVF automatically.

LAVF input (and FFMS input, if that had been covered) allows the user to give x264 any general video file directly. Any way you look at the steps though, a recompile is going to be necessary somewhere in the process. Either x264 has to be rebuilt (as per this guide), or FFmpeg has to be rebuilt (
in cases where the user wants to keep the LAVF and FFMS components streamlined, and needs a stripped-down version of FFmpeg).


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM