Android-NDK-013-X264命令指南

111 阅读3分钟

X264

x264的官网上有编译好的Windows、Linux、Mac平台对应的二进制文件,比如Windows下是exe文件,可以直接用该文件来进行编码的操作。

官网地址: www.videolan.org/developers/…

C:\Users\jesson\Desktop\x264>x264-r2901-7d0ff22.exe --help
x264 core:155 r2901 7d0ff22
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 (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 or L-SMASH support (no)
Output bit depth: 8/10
.
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 (requ
ires cfr input)
​
Ratecontrol:
​
  -B, --bitrate <integer>     Set bitrate (kbit/s)
      --crf <float>           Quality-based VBR (-12-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 width: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
      resize:[width,height][,sar][,fittobox][,csp][,method]
      select_every:step,offset1[,...]
Syntax: x264 [options] -o outfile infile
​
​
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)

image.png

指定码率 --bitrate

x264 --bitrate 1000 -o output.264 input_640x360_yuv420p.yuv

指定帧率 --fps

x264 --fps 10 -o output.264 input_640x360_yuv420p.yuv

指定编码速度 --preset

x264 --preset ultrafast -o output.264 input_640x360_yuv420p.yuv

image.png

配合视觉优化 --tune

--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

image.png

YUV

YUV (YCrCb):像素格式 视频编码

Y 灰度

U (蓝⾊)

V (红⾊)

Y 分量 没有 UV 1⽐1

采样当中:

UV采样率 < Y采样率

A:B: C

存储格式:

平⾯格式(planar)、Semi-Planar、打包格式

单独数组

Y0 Y1 Y2 Y3。。。

U0 U1 .。。

V0。V1

YUV420P IYUV I420 YU12

每4个Y分量 共享 ⼀组UV