H.264的profile 和 level

一、简介

通常我们代码里关于H264的profile和level的定义是这样的:

/**
 * AVC profile types, each profile indicates support for various
 * performance bounds and different annexes.
 */
typedef enum OMX_VIDEO_AVCPROFILETYPE {
    OMX_VIDEO_AVCProfileBaseline = 0x01,   /**< Baseline profile */
    OMX_VIDEO_AVCProfileMain     = 0x02,   /**< Main profile */
    OMX_VIDEO_AVCProfileExtended = 0x04,   /**< Extended profile */
    OMX_VIDEO_AVCProfileHigh     = 0x08,   /**< High profile */
    OMX_VIDEO_AVCProfileHigh10   = 0x10,   /**< High 10 profile */
    OMX_VIDEO_AVCProfileHigh422  = 0x20,   /**< High 4:2:2 profile */
    OMX_VIDEO_AVCProfileHigh444  = 0x40,   /**< High 4:4:4 profile */
    OMX_VIDEO_AVCProfileKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
    OMX_VIDEO_AVCProfileVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
    OMX_VIDEO_AVCProfileMax      = 0x7FFFFFFF 
} OMX_VIDEO_AVCPROFILETYPE;


/**
 * AVC level types, each level indicates support for various frame sizes,
 * bit rates, decoder frame rates.  No need
 */
typedef enum OMX_VIDEO_AVCLEVELTYPE {
    OMX_VIDEO_AVCLevel1   = 0x01,     /**< Level 1 */
    OMX_VIDEO_AVCLevel1b  = 0x02,     /**< Level 1b */
    OMX_VIDEO_AVCLevel11  = 0x04,     /**< Level 1.1 */
    OMX_VIDEO_AVCLevel12  = 0x08,     /**< Level 1.2 */
    OMX_VIDEO_AVCLevel13  = 0x10,     /**< Level 1.3 */
    OMX_VIDEO_AVCLevel2   = 0x20,     /**< Level 2 */
    OMX_VIDEO_AVCLevel21  = 0x40,     /**< Level 2.1 */
    OMX_VIDEO_AVCLevel22  = 0x80,     /**< Level 2.2 */
    OMX_VIDEO_AVCLevel3   = 0x100,    /**< Level 3 */
    OMX_VIDEO_AVCLevel31  = 0x200,    /**< Level 3.1 */
    OMX_VIDEO_AVCLevel32  = 0x400,    /**< Level 3.2 */
    OMX_VIDEO_AVCLevel4   = 0x800,    /**< Level 4 */
    OMX_VIDEO_AVCLevel41  = 0x1000,   /**< Level 4.1 */
    OMX_VIDEO_AVCLevel42  = 0x2000,   /**< Level 4.2 */
    OMX_VIDEO_AVCLevel5   = 0x4000,   /**< Level 5 */
    OMX_VIDEO_AVCLevel51  = 0x8000,   /**< Level 5.1 */
    OMX_VIDEO_AVCLevelKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
    OMX_VIDEO_AVCLevelVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
    OMX_VIDEO_AVCLevelMax = 0x7FFFFFFF 
} OMX_VIDEO_AVCLEVELTYPE;

看注释我们就能知道profile是代表编码器能力的,不同的profile有不同的能力,所以越高级的profile需求越强的处理器,具体如下图:





 

而h.264 的level指示编码的分辨率、比特率、宏块数和帧率等。具体如下图:



 

二、附加介绍

    想要说明H.264 HP与H.264 MP的区别就要讲到H.264的技术发展了。JVT于2003年完成H.264基本部分标准制定工作,包含Baseline profile、Extended profile和Main profile,分别包括不同的编码工具。之后JVT又完成了H.264 FRExt(即:Fidelity Range Extensions)扩展部分(Amendment)的制定工作,包括High profile(HP)、High 10 profile(Hi10P)、High 4:2:2 profile(Hi422P)、High 4:4:4 profile(Hi444P)4个profile。

  H.264 Baseline profile、Extended profile和Main profile都是针对8位样本数据、4:2:0格式的视频序列,FRExt将其扩展到8~12位样本数据,视频格式可以为4:2:0、4:2:2、4:4:4,设立了High profile(HP)、High 10 profile(Hi10P)、High 4:2:2 profile(Hi422P)、High 4:4:4 profile(Hi444P) 4个profile,这4个profile都以Main profile为基础。

在相同配置情况下,High profile(HP)可以比Main profile(MP)节省10%的码流量,比MPEG-2 MP节省60%的码流量,具有更好的编码性能。根据应用领域的不同,Baseline profile多应用于实时通信领域,Main profile多应用于流媒体领域,High profile则多应用于广电和存储领域。

H.264 Baseline Profile对应MPEG-4 SP
H.264 Main Profile对应MPEG-4 ASP
H.264 Extended Profile对应MPEG-4 ARTS or FGS
H.264 Baseline Profile对应MPEG-4 Studio。

 

三、软件编码器的编码能力

h.264 software encoder






  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值