视频编码解码(H264中的profile和level)

主要内容

即将开始另一系列的笔记,主要是1涉及以下内容

  • SPS/PPS/Slice Header
  • 常见的分析工具
  • ffmpeg视频编码

Profile与Level

这是本节主要涉及的内容

H264 Profile

对压缩视频特性的描述,profile越高,就说明采用了越高级的压缩特性。
在这里插入图片描述
在图中可以看得出第一级是以CONSTRAINED BASELINE为核心,发展出来MAIN Profile和BASELINE以及BASELINE的延伸EXTEND Profile。
在核心的CONSTRAINED BASELINE中主要包含P帧、I帧,但是可以发现并没有B帧,B帧是在main profile中才出现的。
b帧的出现也使得压缩率进一步提升,所以main profile的压缩率一定是比CONSTRAINED BASELINE要高得多的。
在实际中用的更多也会是MAIN profile。
在这里插入图片描述
这是MAIN Profile的详细图

H264 Level

Level是对视频的描述,Level越高,视频的码率、分辨率、fps越高。
如果视频的level很低,就只能处理一些低清晰的视频,如果很高就可以处理1080p等高清视频。
在这里插入图片描述
以第一个为例,level为1,最大码流仅支持64,分辨率为128x96,帧率30,或者分辨率为176x144,帧率15

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 FFmpeg 库设置 H.264 编码器的 profilelevel 的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <inttypes.h> #include <unistd.h> #include <libavcodec/avcodec.h> int main(int argc, char *argv[]) { AVCodec *codec; AVCodecContext *codec_ctx = NULL; AVDictionary *opts = NULL; int ret; avcodec_register_all(); codec = avcodec_find_encoder_by_name("libx264"); if (codec == NULL) { fprintf(stderr, "Codec 'libx264' not found\n"); return 1; } codec_ctx = avcodec_alloc_context3(codec); if (codec_ctx == NULL) { fprintf(stderr, "Failed to allocate codec context\n"); return 1; } codec_ctx->width = 1280; codec_ctx->height = 720; codec_ctx->time_base.num = 1; codec_ctx->time_base.den = 30; codec_ctx->framerate.num = 30; codec_ctx->framerate.den = 1; codec_ctx->gop_size = 30; codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; codec_ctx->profile = FF_PROFILE_H264_HIGH; // 设置 profile codec_ctx->level = 41; // 设置 level av_dict_set(&opts, "preset", "medium", 0); av_dict_set(&opts, "tune", "zerolatency", 0); if (avcodec_open2(codec_ctx, codec, &opts) < 0) { fprintf(stderr, "Failed to open codec\n"); return 1; } // ... avcodec_close(codec_ctx); avcodec_free_context(&codec_ctx); av_dict_free(&opts); return 0; } ``` 在上面的代码,`codec_ctx->profile` 和 `codec_ctx->level` 分别用于设置 H.264 编码器的 profilelevel。可以通过设置 `codec_ctx->profile` 的值为 `FF_PROFILE_H264_BASELINE`、`FF_PROFILE_H264_MAIN` 或 `FF_PROFILE_H264_HIGH` 来选择不同的 profile。而 `codec_ctx->level` 的值可以设置为对应的 level 值,比如 `10`、`11`、`31`、`41` 等。 需要注意的是,不同的 profilelevel 有不同的编码复杂度和兼容性,需要根据实际情况选择合适的参数。同时,需要使用 FFmpeg 版本 4.0 或以上才支持设置 profilelevel
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值