x264
h.264
specific
reference:https://www.videoproc.com/resource/h264-codec.htm
- I-frame contains the complete information of the image, it is coded independently of other non-I-frame pictures.
- P-frame contains differences relative to preceding frames.
- B-frame contains differences relative to both preceding and following frames.
- GOP (Group of Pictures) is made of I, P, B frames starting with I frame. A typical structure could be IBBPBBPBBI or IBBPBBPBBPBBI. The more frames between I-frames, the longer the GOP.
帧内帧间预测
帧内内预测,264新增加。
帧间预测,早期版本有,264支持9个方向,4种分块模式(16x16,16x8,8x16,8x8)。
运动估计、运动补偿
运动估计,帧被分离到宏块中,在帧内寻找最比配的像素块。
运动补偿,当前宏块与运动估计的差值
转换与量化
利用DCT与量化,保留高频信号。
去块滤波
解决各种压缩过程种使用宏块为单元,造成块间出现可察觉变化。
熵编码
H264使用CABAC将二进制算数编码
裸流
使用NALU格式,
+--------------------------+------------------------------------------+
| NAL header | RBSP |
+--------------------------+------------------------------------------+
x264
use the ffmpeg to generate the x264 stream.
#mp4 to 264
//带了帧率
ffmpeg -i yourvideoname.mp4 -c:v libx264 outputfilename.264
//不带帧率
x264 test1.mp4 -o test4.264
ffmpeg -i test.mp4 -an -vcodec libx264 -crf 23 test.264
# 264 to mp4
ffmpeg -framerate 24 -i input.264 -c copy output.mp4
x264 raw_stream.264 -o playable_video.mp4
profile
序 | name | 名称 | 8x8dct | cqm | bframes | cabac | weightp | interlaced |
---|---|---|---|---|---|---|---|---|
1 | baseline | 基线 | no | flat | 0 | no | 0 | no |
2 | main | 主要 | no | flat | 不限 | 不限 | 不限 | 不限 |
3 | high | 高 | 不限 | 不限 | 不限 | 不限 | 不限 | 不限 |
4 | high10 | 高10位 | 不限 | 不限 | 不限 | 不限 | 不限 | 不限 |
- cqm: 自定义量化矩阵(custom quantization matrices), 默认有flat 和 JVT
- weightp: 使用加权预测,模式越高越慢。
- cabac: 弹性二进制编码
- interlaced: 隔行扫描
preset
name | 名称 | b-adapt | bframes | direct | me | merange | partitions | rc-lookahead | ref | subme | trellis | weightp | other |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ultrafast | 极快 | 0 | 0 | dia | none | 0 | 1 | 0 | 0 | 0 | no-8x8dct , aq-mode0 , no-cabac , no-deblock, no-mbtree, no-mixed-refs , scenecut0 , no-weightb | ||
superfast | 超快 | dia | i8x8,i4x4 | 0 | 1 | 1 | 0 | 1 | no-mixed-refsno-mbtree | ||||
veryfast | 很快 | 10 | 1 | 2 | 0 | 1 | no-mixed-refs | ||||||
faster | 较快 | 20 | 2 | 4 | 1 | no-mixed-refs | |||||||
fast | 快 | 30 | 2 | 6 | 1 | ||||||||
medium | 中 | ||||||||||||
slow | 慢 | 2 | auto | umh | 50 | 5 | 8 | ||||||
slower | 较慢 | 2 | auto | umh | all | 60 | 8 | 9 | 2 | ||||
veryslow | 很慢 | 2 | 8 | auto | umh | 24 | all | 60 | 16 | 10 | 2 | ||
placebo | 2 | 16 | auto | tesa | 24 | all | 60 | 16 | 11 | 2 | slow-firstpass , no-fast-pskip |
- b-adapt 设置弹性B帧位置决策算法。
- bframe: B在IP之间数量
- direct:动态预测模式
- merange: 运动估计最大范围,单位i像素
- partitions:宏块大小
- rc-lookahead: mb-tree使用帧数。
- subme:像素估算复杂度
- trellis:执行trellis quantization提高效率
tune
序 | name | 名称 | ref | bframes | deblock | psy-rd | aq-strength | other |
---|---|---|---|---|---|---|---|---|
1 | film | 电影 | -1:-1 | :0.15 | ||||
2 | animation | 动画 | {Double if >1 else 1} | {+2} | 1:1 | 0.4: | 0.6 | |
3 | grain | 颗粒 | -2:-2 | :0.25 | 0.5 | no-dct-decimate deadzone-inter6 deadzone-intra6 ipratio1.1 pbratio1.1 qcomp0.8 | ||
4 | stillimage | 静态图像 | -3:-3 | 2.0:0.7 | 1.2 | |||
5 | psnr | PSNR测试 | no | aq-mode0 | ||||
6 | ssim | SSIM测试 | no | aq-mode2 | ||||
7 | fastdecode | 快速解码 | no | no-cabac no-weightb weightp0 | ||||
8 | zerolatency | 零延迟 | 0 | force-cfr no-mbtree sync-lookahead0 sliced-threads rc-lookahead0 |
- ref: 控制解码图片缓冲,P可以向前参考多少帧
- psy-rd: psy-RDO, psy-Trellis强度
- aq-strength:弹性量化强度