###Date: 2017/12/23
###Author: SoaringLee
======================================================================
1、x264简介
x264是H264标准的开源编码器,由于x264编码器进行了很多优化,现在已经成为了工业界实用的H264编码器,其编码性能也是很高的。
x264下载地址:ftp://ftp.videolan.org/pub/videolan/x264/snapshots/
2、x264在Linux平台下的编译
在linux平台下的编译很简单,开源工程的编译都是通过makefile实现的,步骤如下:
(1)./configure
(2)make
3、x264在Windows平台(MinGW)下的编译
(1)需要安装MinGW
(2)需要安装yasm或者nasm汇编编译器,http://www.nasm.us/,将nasm.exe放在工程目录下。
(3)./configure --enable-shared
(4) make
最后,静态库libx264.a和编码器可执行文件x264.exe成功生成了!
至于动态库dll的编译可以采用./configure --enable-shared make生成libx264.-152.dll。
如下图:
至于如何从dll中生成引导库lib,可以采用pexports生成def文件,然后采用lib命令在mingGW中生成lib。
$ pexports.exe -v libx264-152.dll >libx264-152.def
$ lib /machine:x86 /def:libx264-152.def
至此,x264编码器的静态库、动态库以及可执行文件的编译就完成了。
4、x264编码参数设置及编码过程
(1)编码参数设置
x264 core:152
Syntax: x264 [options] -o outfile infile
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 or L-SMASH support (no)
Output bit depth: 8 (configured at compile time)
Options:
-h, --help List basic options
--longhelp List more options
--fullhelp List all options
Example usage:
Constant quality mode:
x264 --crf 24 -o <output> <input>
Two-pass with a bitrate of 1000kbps:
x264 --pass 1 --bitrate 1000 -o <output> <input>
x264 --pass 2 --bitrate 1000 -o <output> <input>
Lossless:
x264 --qp 0 -o <output> <input>
Maximum PSNR at the cost of speed and visual quality:
x264 --preset placebo --tune psnr -o <output> <input>
Constant bitrate at 1000kbps with a 2 second-buffer:
x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input>
Presets:
--profile <string> Force the limits of an H.264 profile
Overrides all settings.
- baseline,main,high,high10,high422,high444
--preset <string> Use a preset to select encoding settings [medium]
Overridden by user settings.
- ultrafast,superfast,veryfast,faster,fast
- medium,slow,slower,veryslow,placebo
--tune <string> Tune the settings for a particular type of source
or situation
Overridden by user settings.
Multiple tunings are separated by commas.
Only one psy tuning can be used at a time.
- psy tunings: film,animation,grain,
stillimage,psnr,ssim
- other tunings: fastdecode,zerolatency
Frame-type options:
-I, --keyint <integer or "infinite"> Maximum GOP size [250]
--tff Enable interlaced mode (top field first)
--bff Enable interlaced mode (bottom field first)
--pulldown <string> Use soft pulldown to change frame rate
- none, 22, 32, 64, double, triple, euro (requires cfr input)
Ratecontrol:
-B, --bitrate <integer> Set bitrate (kbit/s)
--crf <float> Quality-based VBR (0-51) [23.0]
--vbv-maxrate <integer> Max local bitrate (kbit/s) [0]
--vbv-bufsize <integer> Set size of the VBV buffer (kbit) [0]
-p, --pass <integer> Enable multipass ratecontrol
- 1: First pass, creates stats file
- 2: Last pass, does not overwrite stats file
Input/Output:
-o, --output <string> Specify output file
--sar height Specify Sample Aspect Ratio
--fps <float|rational> Specify framerate
--seek <integer> First frame to encode
--frames <integer> Maximum number of frames to encode
--level <string> Specify level (as defined by Annex A)
--quiet Quiet Mode
Filtering:
--vf, --video-filter <filter0>/<filter1>/... Apply video filtering to the input file
Filter options may be specified in <filter>:<option>=<value> format.
Available filters:
crop:left,top,right,bottom
select_every:step,offset1[,...]
(2)编码过程
参考:http://blog.csdn.net/table/article/details/8085004