1x264
x264是基于H.264/AVC标准的一款免费、开源的视频编解码器(库),x264是目前使用最广的、最优秀的一款H.264编解码器。x264编解码器支持的功能诸多ubuntu 视频播放器 知乎,包括:
2安装
2.1安装汇编工具
x264库依赖于汇编工具(asm),首先需安装汇编工具ubuntu 视频播放器 知乎,否则编译x264失败。目前x264库使用的是nasm,旧版本x264库依赖于yasm;这儿需安装nasm。
nasm下载地址:
最新版本:
本人使用的版本:
各类压缩文件格式都有,选择一个自己系统早已安装了相应格式的解压工具,省去再安装一个额外解压工具的过程。这儿选择.bz2压缩版本。
# 解压
tar -xvjf nasm-2.13.03.tar.bz2
# 配置
cd nasm-2.13.03
./configure
# 编译
make
# 安装到系统
sudo make install
2.2安装x264库
x264库下载地址:
x264代码库房:
# 解压
tar -xvjf last_x264.tar.bz2
# 配置
cd x264-snapshot-20190708-2245
./configure --enable-shared
# 编译
make
# 安装到系统
sudo make install
编译完成成功后,在当前目录生成静态库libx264.a和动态库libx264.so.157。
安装则是将动态库libx264.so.157安装(拷贝)到/usr/local/lib目录下,并创建一个软链接文件libx264.so,链接到libx264.so.157动态库。由于linux详解词典,依赖于x264库的应用程序执行时,索引链接的库名称是libx264.so。使用软链接的用处就是,不由于x264库的更新造成应用程序索引不到动态库。x264的库是持续更新迭代的,编译后的动态库名称通常会带版本后缀,如libx264.so.157中的“157”后缀;若果以具体版本的动态库为索引名称,更新动态库时将须要更改或则程序。为此,最理想的方法是构建一个软链接。
3测试
源码中提供了一个测试事例x264.c,该事例是一个基本的视频编码过程,可以将YUV视频流转换成264、flv、mkv等格式的视频。通过这个事例初步直观感受x264的强悍功能。编译x264库的时侯,早已将测试事例源码编译,编译后的执行文件为x264,可以执行./x264-help查看使用技巧。
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 selected by filename:
.264 -> Raw bytestream
.mkv -> Matroska
.flv -> Flash Video
.mp4 -> MP4 if compiled with GPAC or L-SMASH support (no)
从网路上下载一个YUV序列文件测试疗效,编码后的文件可以通VLC播放器播放。
acuity@ubuntu:/mnt/hgfs/LSW/X264/x264 tools/x264-snapshot-20190708-2245$ ./x264 BUS_176x144_15_orig_01.yuv -o bus.264
yuv : 176x144p 0:0 @ 25/1 fps (cfr)
x264 : using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3
x264 : profile Progressive High, level 1.1, 4:2:0, 8-bit
x264 : frame I:1 Avg QP:28.16 size: 5745
x264 : frame P:30 Avg QP:28.28 size: 2143
x264 : frame B:44 Avg QP:31.38 size: 702
x264 : consecutive B-frames: 6.7% 34.7% 32.0% 26.7%
x264 : mb I I16..4: 0.0% 54.5% 45.5%
x264 : 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 : 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 : 8x8 transform intra:45.8% inter:41.9%
x264 : coded y,uvDC,uvAC intra: 97.3% 84.6% 53.3% inter: 38.3% 12.6% 1.6%
x264 : i16 v,h,dc,p: 25% 25% 50% 0%
x264 : i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 19% 24% 5% 5% 3% 6% 7% 11%
x264 : i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 29% 19% 6% 5% 4% 5% 6% 7%
x264 : i8c dc,h,v,p: 69% 20% 6% 5%
x264 : Weighted P-Frames: Y:13.3% UV:3.3%
x264 : ref P L0: 65.1% 22.0% 7.3% 5.1% 0.6%
x264 : ref B L0: 90.7% 8.4% 0.8%
x264 : ref B L1: 99.4% 0.6%
x264 : kb/s:269.10
encoded 75 frames, 631.36 fps, 269.10 kb/s
执行编码,可以见到原始YUV序列文件的信息,编码后I帧、P帧、B帧的压缩信息,编码率为631.36fps。编码后文件(bus.264)大小为98.5Karch linux,原YUV文件为2.71M,压缩率3%。
使用快速编码方法:
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 : 176x144p 0:0 @ 25/1 fps (cfr)
x264 : using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3
x264 : profile Main, level 1.1, 4:2:0, 8-bit
x264 : frame I:1 Avg QP:20.00 size: 10256
x264 : frame P:74 Avg QP:27.54 size: 3294
x264 : mb I I16..4: 2.0% 0.0% 98.0%
x264 : 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 : coded y,uvDC,uvAC intra: 97.5% 72.8% 56.4% inter: 77.3% 20.5% 3.8%
x264 : i16 v,h,dc,p: 22% 68% 8% 2%
x264 : i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 25% 13% 6% 6% 4% 8% 6% 11%
x264 : i8c dc,h,v,p: 29% 49% 16% 6%
x264 : Weighted P-Frames: Y:6.8% UV:0.0%
x264 : kb/s:677.44
encoded 75 frames, 1441.39 fps, 677.44 kb/s
使用快速编码,编码率提升到1441.39fps,编码后文件为248K,压缩率接近9%(压缩率越低压缩比越大)。
4参考文章
【1】H264基础简介
【2】H264基本原理
本文原创地址://sclmfb.cn/xjyhbzdyxkys.html编辑:刘遄,审核员:暂无