h264中profile和level的含义

Profile是对视频压缩特性的描述(CABAC呀、颜色采样数等等)。Level是对视频本身特性的描述(码率、分辨率、fps)。
简单来说,Profile越高,就说明采用了越高级的压缩特性。Level越高,视频的码率、分辨率、fps越高。
一些移动设备(手机、游戏机、PMP)由于性能有限,不支持全部高级视频压缩特性和高分辨率图像,只支持基础压缩特性和分辨率低一些的图像。为了让这个限制更加清晰明了,H264从低到高划分了很多Profile和Level,设备只需要标出所支持的Profile和Level就可以让用户和开发者一看既知。
具体哪些Profile和Level对应哪些特性,上面的wiki已经列表写得很清楚了。我记得PSP是支持到MainProfile的Level 2.1。

这个解释也不能说错,只是个人觉得不够准确,profile主要是定义了编码工具的集合,不同的profile,包含了不同的编码技术;而level主要是对码流的关键参数的取值范围作了限定,与解码器的处理能力和存储能力相关联



For h.264 users, how to specify the profile/level seems to be a fairly common question. Profiles define sets of bit stream features a h.264 stream can use. Levels define restrictions on the video resolution, frame rate and some stuff called VBV (Video Buffer Verifier).


H.264 Profiles

H.264 Profiles are discussed in depth on Wikipedia, but to simplify the considerations for the average user, I will focus on the Baseline, Main and High Profiles.

  • Baseline Profile
    • I/P slices
    • Multiple reference frames (–refs <int>, >1 in the x264 CLI)
    • In-loop deblocking
    • CAVLC entropy coding (–no-cabac in the x264 CLI)
  • Main Profile
    • Baseline Profile features mentioned above
    • B slices
    • CABAC entropy coding
    • Interlaced coding – PAFF/MBAFF
    • Weighted prediction
  • High Profile
    • Main Profile features mentioned above
    • 8×8 transform option (–8×8dct in the x264 CLI)
    • Custom quantisation matrices

    H.264 Levels

    H.264 Levels are also discussed on Wikipedia, though in my opinion, less explicitly and less successfully than for the profiles. For practical use, to specify a Level, a number of constraints have to be met.

    The resolutions/frame rates in the following table are merely a guideline – the number of macroblocks per second is the actual restriction. To calculate this:

    Macroblocks are 16×16 in H.264 and so to code a frame one can calulate the number of macroblocks per frame as:

    ceil( width / 16.0 ) * ceil( height / 16.0 )

    Note: The ceil() function rounds up its argument to the next integer. For example, ceil( 10.2 ) returns 11.

    Then you need to multiply the number of macroblocks per frame by the number of frames per second to get the number of macroblocks per second.

    macroblocks per second = ceil( width / 16.0 ) * ceil( height / 16.0 ) * frame rate

    Level

    VBV maximum bit rate [1000bits/s]

    VBV buffer size [1000bits]

    Macroblocks/s

    Resolution and frame rate

    1

    64

    175

    1485

    128×96@30 or 176×144@15

    1b

    128

    350

    1485

    128×96@30 or 176×144@15

    1.1

    192

    500

    3000

    176×144@30 or 320×240@10

    1.2

    384

    1000

    6000

    176×144@60 or 320×240@20

    1.3

    768

    2000

    11880

    352×288@30

    2

    2000

    2000

    11880

    352×288@30

    2.1

    4000

    4000

    19800

    352×288@50

    2.2

    4000

    4000

    20250

    352×288@50 or 640×480@15

    3

    10000

    10000

    40500

    720×480@30 or720×576@25

    3.1

    14000

    14000

    108000

    1280×720@30

    3.2

    20000

    20000

    216000

    1280×720@60

    4

    20000

    25000

    245760

    1920×1088@30or 2Kx1K@30

    4.1

    50000

    62500

    245760

    1920×1088@30 or 2Kx1K@30

    4.2

    50000

    62500

    522240

    1920×1088@60 or or 2Kx1K@60

    5

    135000

    135000

    589824

    2560×1920@30

    5.1

    240000

    240000

    983040

    4Kx2K@30 or 4



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

余额充值