2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "libavutil/common.h"
20 #include "libavcodec/h264_levels.h"
27 // First level usable at some standard sizes.
28 // (From H.264 table A-6.)
29 { 176, 144, 10 }, // QCIF
30 { 352, 288, 11 }, // CIF
31 { 640, 480, 22 }, // VGA
32 { 720, 480, 22 }, // NTSC
33 { 720, 576, 22 }, // PAL
34 { 800, 600, 31 }, // SVGA
35 { 1280, 720, 31 }, // 720p
36 { 1280, 1024, 32 }, // SXGA
37 { 1920, 1080, 40 }, // 1080p
38 { 2048, 1080, 42 }, // 2Kx1080
39 { 2048, 1536, 50 }, // 4XGA
40 { 3840, 2160, 51 }, // 4K
41 { 7680, 4320, 60 }, // 8K
43 // Overly wide or tall sizes.
68 // First level usable for some DPB sizes.
69 // (From H.264 table A-7.)
76 { 1280, 720, 10, 50 },
77 { 1920, 1080, 1, 40 },
78 { 1920, 1080, 5, 50 },
79 { 1920, 1080, 13, 50 },
80 { 1920, 1080, 14, 51 },
81 { 3840, 2160, 5, 51 },
82 { 3840, 2160, 6, 60 },
83 { 3840, 2160, 16, 60 },
84 { 7680, 4320, 5, 60 },
93 // Values where profile affects level at a given bitrate.
97 { 100000000, 77, 50 },
98 { 100000000, 100, 50 },
99 { 100000000, 244, 41 },
100 { 999999999, 77, 0 },
101 { 999999999, 100, 62 },
103 { 32 * 1200, 66, 10 },
104 { 32 * 1500, 100, 10 },
105 { 96 * 1200, 66, 11 },
106 { 96 * 1500, 100, 9 },
107 { 144 * 1200, 66, 11 },
108 { 144 * 1500, 100, 11 },
111 static const struct {
120 { "Bluray 1080p 40Mb/s", 100, 40000000, 1920, 1080, 4, 41 },
121 { "Bluray 1080p 24Mb/s", 100, 24000000, 1920, 1080, 4, 40 },
122 { "Bluray 720p 40Mb/s", 100, 40000000, 1280, 720, 6, 41 },
123 { "Bluray 720p 24Mb/s", 100, 24000000, 1280, 720, 6, 40 },
124 { "Bluray PAL 40Mb/s", 100, 40000000, 720, 576, 6, 41 },
125 { "Bluray PAL 24Mb/s", 100, 24000000, 720, 576, 6, 32 },
126 { "Bluray PAL 16Mb/s", 100, 16800000, 720, 576, 6, 31 },
127 { "Bluray PAL 12Mb/s", 100, 12000000, 720, 576, 5, 30 },
128 { "Bluray NTSC 40Mb/s", 100, 40000000, 720, 480, 6, 41 },
129 { "Bluray NTSC 24Mb/s", 100, 24000000, 720, 480, 6, 32 },
130 { "Bluray NTSC 16Mb/s", 100, 16800000, 720, 480, 6, 31 },
131 { "Bluray NTSC 12Mb/s", 100, 12000000, 720, 480, 6, 30 },
136 const H264LevelDescriptor *level;
139 #define CHECK(expected, format, ...) do { \
140 if (expected ? (!level || level->level_idc != expected) \
142 av_log(NULL, AV_LOG_ERROR, "Incorrect level for " \
143 format ": expected %d, got %d.\n", __VA_ARGS__, \
144 expected, level ? level->level_idc : -1); \
149 for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) {
150 level = ff_h264_guess_level(0, 0, test_sizes[i].width,
151 test_sizes[i].height, 0);
152 CHECK(test_sizes[i].level_idc, "size %dx%d",
153 test_sizes[i].width, test_sizes[i].height);
156 for (i = 0; i < FF_ARRAY_ELEMS(test_dpb); i++) {
157 level = ff_h264_guess_level(0, 0, test_dpb[i].width,
159 test_dpb[i].dpb_size);
160 CHECK(test_dpb[i].level_idc, "size %dx%d dpb %d",
161 test_dpb[i].width, test_dpb[i].height,
162 test_dpb[i].dpb_size);
165 for (i = 0; i < FF_ARRAY_ELEMS(test_bitrate); i++) {
166 level = ff_h264_guess_level(test_bitrate[i].profile_idc,
167 test_bitrate[i].bitrate,
169 CHECK(test_bitrate[i].level_idc, "bitrate %"PRId64" profile %d",
170 test_bitrate[i].bitrate, test_bitrate[i].profile_idc);
173 for (i = 0; i < FF_ARRAY_ELEMS(test_all); i++) {
174 level = ff_h264_guess_level(test_all[i].profile_idc,
178 test_all[i].dpb_frames);
179 CHECK(test_all[i].level_idc, "%s", test_all[i].name);