open GOP & close GOP

open GOP & close GOP

FlyingPenguin关注

2018.04.27 15:41:50字数 689阅读 2,049

GOP的两种结构

MPEG的格式支持open GOP或者close GOP格式。Close GOP是指帧间的预测都是在GOP中进行的。而使用open GOP,后一个GOP会参考前一个GOP的信息。使用这种方式就大大降低了码率。

Close-GOP

By definition, closed GOPs cannot contain any frame that refers to a frame in the previous or next GOP.

closed GOP中的帧不可以参考其前后的其它GOP.

Closed GOPs created by Compressor always begin with an I-frame.

Closed GOP一般以I帧开头。

Open-GOP

Open-GOP:informal structure. 在一个GOP里面的某一帧在解码时要依赖于前一个GOP中的某一些帧,这种GOP结构叫做Open-GOP。一般码流里面含有B帧的时候才会出现Open-GOP。

Open GOPs are most efficient because they allow an extra B-frame in the GOP pattern.
Open GOPs start with a B-frame that is able to look at the last P-frame from the preceding GOP as well as the first I-frame of its own GOP.
open GOPs begin with one or more B-frames that reference the last P-frame of the previous GOP.

Open GOP以一个或多个B帧开始,参考之前GOP的P帧和当前GOP的I帧

Open and Closed GOPs

Open GOPs generally provide slightly better compression than do closed GOPs of the same structure and size.
The illustration above shows that a closed GOP contains one more P-frame than does an open GOP of the same length. Since P-frames generally require more bits than do B-frames, the open GOP achieves slightly better compression.

同等条件下,Open GOP比closed GOP具有更高的压缩效率。

H264中的I帧

主要有2种I帧:I(IDR帧)、I(非IDR I帧)。

I(IDR帧)

NALU_type = 0x65。
IDR帧是一种特殊的I帧,在解码IDR帧前,清空所有前后向参考缓冲区,IDR帧随后的所有帧不能参考IDR前面的任何帧
IDR帧是视频安全的随机访问点,找到一个IDR帧可以丢弃前面所有帧数据而正确解码

I(非IDR帧)

NALU_type = 0x61。
i帧是帧内预测帧,它的解码不依赖与任何其他帧

区别

有些解码器没有区分这两种I帧,将所有的i帧都缺省的认为是IDR帧,这样会造成解码错误。
这两种i帧在open-GOP的结构中需要明确区分,而在close-GOP中可以视为相同

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在RK3399平台下,您可以使用Linux系统下的Rockchip VPU库来进行h264视频编码。下面是使用C语言调用VPU进行图像数据编码为h264视频格式的步骤: 1. 在C代码中包含Rockchip VPU库的头文件: ``` #include <rockchip/rk_vpu.h> ``` 2. 初始化VPU: ``` vpu_api_init(); ``` 3. 定义VPU编码参数结构体,并设置参数: ``` VpuEncConfig enc_cfg; memset(&enc_cfg, 0, sizeof(VpuEncConfig)); enc_cfg.width = 1920; // 编码图像宽度 enc_cfg.height = 1080; // 编码图像高度 enc_cfg.framerate = 30; // 编码帧率 enc_cfg.bitrate = 4000; // 编码码率 enc_cfg.gop_size = 30; // GOP大小 enc_cfg.rc_mode = 1; // 码率控制模式 ``` 4. 打开VPU编码器: ``` VpuEncHandle enc_handle; memset(&enc_handle, 0, sizeof(VpuEncHandle)); vpu_enc_open(&enc_handle, &enc_cfg); ``` 5. 定义输入图像数据结构体: ``` VpuFrame input_frame; memset(&input_frame, 0, sizeof(VpuFrame)); input_frame.width = enc_cfg.width; input_frame.height = enc_cfg.height; input_frame.format = VPU_FRAME_FORMAT_YUV420SP; ``` 6. 定义输出数据结构体: ``` VpuPacket output_packet; memset(&output_packet, 0, sizeof(VpuPacket)); ``` 7. 读入图像数据到输入数据结构体中: ``` FILE *fp = fopen("image_data.yuv", "rb"); unsigned char *yuv_data = (unsigned char *)malloc(enc_cfg.width * enc_cfg.height * 3 / 2); fread(yuv_data, 1, enc_cfg.width * enc_cfg.height * 3 / 2, fp); fclose(fp); input_frame.vir_addr = yuv_data; ``` 8. 使用VPU进行编码: ``` int ret = vpu_enc_encode(enc_handle, &input_frame, &output_packet); ``` 在这个例子中,我们使用vpu_enc_encode函数进行编码。编码后的数据将存储在output_packet缓冲区中。 9. 将编码后的数据写入到一个新的文件中: ``` fp = fopen("encoded_data.h264", "wb"); fwrite(output_packet.vir_addr, 1, output_packet.size, fp); fclose(fp); ``` 在这个例子中,我们使用fwrite函数将编码后的数据写入到一个新的文件中。 10. 释放内存: ``` free(yuv_data); vpu_enc_close(&enc_handle); vpu_api_exit(); ``` 在完成编码后,我们需要释放之前分配的内存,并关闭VPU编码器。 这样,您就可以使用C语言和Rockchip VPU库在RK3399平台下将图像数据编码为h264视频格式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值