"1 x264
X264 is a free, open source video codec (library) based on the H.264 / AVC standard, and X264 is currently using the broadest and best H.264 codec. The X264 codec support has many functions, including:
8x8 and 4x4 Adaptive Space Translation Adaptive B Select B Frame as Reference Frame / Around Sequence CAVLC / CABAC Entropy Code Credits Code Code Code Credit Quantization Matrix I Frame: All Macro Block Types (16x16, 8x8, 4x4, PCM and All Prediction PCM P Frame: All partitions (from 16x16 to 4x4) B frame: Subregion (including Skip / Direct) Interlacing (MBAFF) multi-reference frame rate control: constant quantizer, constant quality, single or more The average code rate of the subcoding, optional VBV parameter scene change detection B frame time domain, spatial domain Direct mode adaptive selection supports multiple CPUs on parallel encoding predictive lossless coding for detail preserved PSY optimization (adaptive quantization, psyrd , Psygrid) is used for any area of arbitrary adjustment bit rate distribution
2 installation
Assembly tool installation X264 library installation
2.1 Install assembly tool
The X264 library relies on assembly tool (ASM), first installing assembly tools, otherwise compiling x264 failed. At present, the X264 library uses NASM, the old version X264 library depends on Yasm; here you need to install NASM.
NASM download address:
Latest version: https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/
I am using the version: https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/
Various compressed file formats have, selecting a decompression tool that has been installed in its own system, saving the process of installing an additional decompression tool. Here to choose the .bz2 compressed version.
# 解 压
Tar-xvjf nasm-2.13.03.tar.bz2
# Configure
CD NASM-2.13.03
./configure
# Compilation
Make
# Install to the system
Sudo make install
123456789
2.2 Installing X264 Library
X264 library download address: http://www.videolan.org/developers/x264.html
X264 Code Warehouse: https://code.videolan.org/videolan/x264.git
# 解 压
Tar-xvjf last_x264.tar.bz2
# Configure
CD x264-snapshot-20190708-2245
./configure --enable-shared
# Compilation
Make
# Install to the system
Sudo make install
123456789
After completing successfully, a static library libX264.a and dynamic library libx264.so.157 are generated in the current directory.
The installation is to install the dynamic library libx264.so.157 into the / usr / local / lib directory, and create a soft link libx264.so, link to libx264.so.157 dynamic library. Because, the library name of the index link is libx264.so when the application executed by the X264 library is executed. The advantage of using a soft link is that not because the update of the X264 library causes the application indexer less than a dynamic library. The library of x264 is continuously updated, and the compiled dynamic library name is usually version suffix, such as "157" suffix in libx264.so.157; if the specific version of the dynamic library is the index name, update the dynamic library You need to modify the script or program. Therefore, the most ideal way is to create a soft link.
3 test
A test example X264.c is provided in the source code. This example is a basic video encoding process that converts YUV video streams to 264, FLV, MKV, and other formats. Through this example, it is preliminating the power of X264. When compiling the X264 library, the test example source code has been compiled. The compiled execution file is X264, which can be executed ./x264 -help View usage method.
Acuity @ Ubuntu: / MNT / HGFS / LSW / X264 / X264 Tools / X264-Snapshot-20190708-2245 $ ./x264-h
X264 Core: 157
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 success by filename:
.264-> Raw bytestream
.mkv -> Matroska
.flv -> Flash Video
.mp4-> MP4 if compiled with gpac or l-smash support (no)
12345678910111213
Download a YUV sequence file test effect from the network, encoding files can be played through the VLC player.
Acuity @ Ubuntu: / MNT / HGFS / LSW / X264 / X264 Tools / X264-Snapshot-20190708-2245 $ ./x264 bus_176x144_15_orig_01.yuv -o bus.264
YUV [INFO]: 176X144P 0: 0 @ 25/1 FPS (CFR)
X264 [INFO]: USING CPU Capabilities: MMX2 SSE2FAST SSSE3 SSE4.2 AVX FMA3
X264 [Info]: Profile Progressive High, Level 1.1, 4: 2: 0, 8-bit
X264 [INFO]: Frame I: 1 AVG QP: 28.16 Size: 5745
X264 [INFO]: Frame P: 30 AVG QP: 28.28 Size: 2143
X264 [INFO]: Frame B: 44 AVG QP: 31.38 Size: 702
X264 [INFO]: Connecutive B-Frames: 6.7% 34.7% 32.0% 26.7%
X264 [info]: MB I i16..4: 0.0% 54.5% 45.5%
X264 [info]: MB P i16..4: 0.1% 3.5% 4.6% P16..4: 25.6% 34.7% 29.1% 0.0% 0.0% SKIP: 2.4%
X264 [info]: MB B I16..4: 0.0% 0.0% 0.0% B16..8: 43.3% 25.4% 10.6% Direct: 3.9% SKIP: 16.7% L0: 37.5% L1: 39.9% BI: 22.7%
X264 [INFO]: 8x8 Transform Intra: 45.8% Inter: 41.9%
X264 [INFO]: CODED Y, UVDC, UVAC Intra: 97.3% 84.6% 53.3% Inter: 38.3% 12.6% 1.6%
X264 [INFO]: I16 V, H, DC, P: 25% 25% 50% 0%
X264 [INFO]: I8 V, H, DC, DDL, DDR, VR, HD, VL, HU: 20% 19% 24% 5% 5% 3% 6% 7% 11%
X264 [INFO]: I4 V, H, DC, DDL, DDR, VR, HD, VL, Hu: 20% 29% 19% 6% 5% 4% 5% 6% 7%
X264 [INFO]: I8C DC, H, V, P: 69% 20% 6% 5%
X264 [INFO]: Weighted P-Frames: Y: 13.3% UV: 3.3%
X264 [INFO]: REF P L0: 65.1% 22.0% 7.3% 5.1% 0.6%
X264 [INFO]: REF B L0: 90.7% 8.4% 0.8%
X264 [INFO]: REF B L1: 99.4% 0.6%
X264 [INFO]: KB / S: 269.10
Encoded 75 Frames, 631.36 FPS, 269.10 KB / S
123456789101112131415161718192021222324
Perform the encoding, you can see the information of the original YUV sequence file, encoding the compressed information of the I frame, the P frame, and B frame, the coding rate is 631.36FPs. After the encoding, the file (bus. 264) is 98.5K, the original YUV file is 2.71m, the compression ratio is 3%.
Use fast encoding mode:
Acuity @ Ubuntu: / MNT / HGFS / LSW / X264 / X264 Tools / X264-Snapshot-20190708-2245 $ ./x264 bus_176x144_15_orig_01.yuv --Input-res 176x144 -o bus1.264 --NO-8X8DCT - AQ- Mode 0 --B-Adapt 0 --bframes 0 --NO-Cabac --NO-Deblock - NO-Mbtree - Me Dia - NO-MIXED-REFS --PARTITIONS NONE --RC-Lookahead 0 Ref 1 --scenecut 0 --Subme 0 --TRELLIS 0
YUV [INFO]: 176X144P 0: 0 @ 25/1 FPS (CFR)
X264 [INFO]: USING CPU Capabilities: MMX2 SSE2FAST SSSE3 SSE4.2 AVX FMA3
X264 [info]: Profile Main, Level 1.1, 4: 2: 0, 8-bit
X264 [INFO]: Frame I: 1 AVG QP: 20.00 Size: 10256
X264 [INFO]: Frame P: 74 AVG QP: 27.54 Size: 3294
X264 [info]: MB I i16..4: 2.0% 0.0% 98.0%
X264 [info]: MB P I16..4: 3.5% 0.0% 0.0% P16..4: 93.2% 0.0% 0.0% 0.0% 0.0% Skip: 3.3%
X264 [INFO]: CODED Y, UVDC, UVAC Intra: 97.5% 72.8% 56.4% Inter: 77.3% 20.5% 3.8%
X264 [INFO]: I16 V, H, DC, P: 22% 68% 8% 2%
X264 [INFO]: I4 V, H, DC, DDL, DDR, VR, HD, VL, Hu: 21% 25% 13% 6% 6% 4% 8% 6% 11%
X264 [INFO]: I8C DC, H, V, P: 29% 49% 16% 6%
X264 [INFO]: Weighted P-Frames: Y: 6.8% UV: 0.0%
X264 [INFO]: KB / S: 677.44
Encoded 75 Frames, 1441.39 FPS, 677.44 KB / S
12345678910111213141516
Using fast coding, the coding rate is increased to 1441.39FPS, the file is 248K after encoding, the compression ratio is close to 9% (the lower compression ratio is more compression ratioBig).
4 Reference article
[1] H264 basic profile [2] H264 basic principle "
Our other product: