1 /*
2 * This file is part of FFmpeg.
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <inttypes.h>
20 #include <stddef.h>
21
25
26 static const struct {
31 // First level usable at some standard sizes.
32 // (From H.264 table A-6.)
33 { 176, 144, 10 }, // QCIF
34 { 352, 288, 11 }, // CIF
35 { 640, 480, 22 }, // VGA
36 { 720, 480, 22 }, // NTSC
37 { 720, 576, 22 }, // PAL
38 { 800, 600, 31 }, // SVGA
39 { 1280, 720, 31 }, // 720p
40 { 1280, 1024, 32 }, // SXGA
41 { 1920, 1080, 40 }, // 1080p
42 { 2048, 1080, 42 }, // 2Kx1080
43 { 2048, 1536, 50 }, // 4XGA
44 { 3840, 2160, 51 }, // 4K
45 { 7680, 4320, 60 }, // 8K
46
47 // Overly wide or tall sizes.
48 { 1, 256, 10 },
49 { 1, 512, 11 },
50 { 1, 1024, 21 },
51 { 1, 1808, 22 },
52 { 1, 1824, 31 },
53 { 256, 1, 10 },
54 { 512, 1, 11 },
55 { 1024, 1, 21 },
56 { 1808, 1, 22 },
57 { 1824, 1, 31 },
58 { 512, 4096, 40 },
59 { 256, 4112, 42 },
60 { 8688, 1024, 51 },
61 { 8704, 512, 60 },
62 { 16880, 1, 60 },
63 { 16896, 1, 0 },
64 };
65
66 static const struct {
72 // Some typical sizes and frame rates.
73 // (From H.264 table A-1 and table A-6)
74 { 176, 144, 15, 10 },
75 { 176, 144, 16, 11 },
76 { 320, 240, 10, 11 },
77 { 320, 240, 20, 12 },
78 { 320, 240, 40, 21 },
79 { 352, 288, 30, 13 },
80 { 352, 288, 51, 22 },
81 { 352, 576, 25, 21 },
82 { 352, 576, 26, 30 },
83 { 640, 480, 33, 30 },
84 { 640, 480, 34, 31 },
85 { 720, 480, 50, 31 },
86 { 720, 576, 25, 30 },
87 { 800, 600, 55, 31 },
88 { 1024, 768, 35, 31 },
89 { 1024, 768, 70, 32 },
90 { 1280, 720, 30, 31 },
91 { 1280, 720, 31, 32 },
92 { 1280, 960, 45, 32 },
93 { 1280, 960, 46, 40 },
94 { 1280, 1024, 42, 32 },
95 { 1600, 1200, 32, 40 },
96 { 1600, 1200, 33, 42 },
97 { 1920, 1088, 30, 40 },
98 { 1920, 1088, 55, 42 },
99 { 2048, 1024, 30, 40 },
100 { 2048, 1024, 62, 42 },
101 { 2048, 1088, 60, 42 },
102 { 3680, 1536, 26, 50 },
103 { 4096, 2048, 30, 51 },
104 { 4096, 2048, 59, 52 },
105 { 4096, 2160, 60, 52 },
106 };
107
108 static const struct {
114 // First level usable for some DPB sizes.
115 // (From H.264 table A-7.)
116 { 176, 144, 4, 10 },
117 { 176, 144, 8, 11 },
118 { 176, 144, 16, 12 },
119 { 1280, 720, 1, 31 },
120 { 1280, 720, 5, 31 },
121 { 1280, 720, 9, 40 },
122 { 1280, 720, 10, 50 },
123 { 1920, 1080, 1, 40 },
124 { 1920, 1080, 5, 50 },
125 { 1920, 1080, 13, 50 },
126 { 1920, 1080, 14, 51 },
127 { 3840, 2160, 5, 51 },
128 { 3840, 2160, 6, 60 },
129 { 3840, 2160, 16, 60 },
130 { 7680, 4320, 5, 60 },
131 { 7680, 4320, 6, 0 },
132 };
133
134 static const struct {
139 // Values where profile affects level at a given bitrate.
140 { 2500000, 77, 21 },
141 { 2500000, 100, 20 },
142 { 2500000, 244, 13 },
143 { 100000000, 77, 50 },
144 { 100000000, 100, 50 },
145 { 100000000, 244, 41 },
146 { 999999999, 77, 0 },
147 { 999999999, 100, 62 },
148 // Check level 1b.
149 { 32 * 1200, 66, 10 },
150 { 32 * 1500, 100, 10 },
151 { 96 * 1200, 66, 11 },
152 { 96 * 1500, 100, 9 },
153 { 144 * 1200, 66, 11 },
154 { 144 * 1500, 100, 11 },
155 };
156
157 static const struct {
166 { "Bluray 1080p 40Mb/s", 100, 40000000, 1920, 1080, 4, 41 },
167 { "Bluray 1080p 24Mb/s", 100, 24000000, 1920, 1080, 4, 40 },
168 { "Bluray 720p 40Mb/s", 100, 40000000, 1280, 720, 6, 41 },
169 { "Bluray 720p 24Mb/s", 100, 24000000, 1280, 720, 6, 40 },
170 { "Bluray PAL 40Mb/s", 100, 40000000, 720, 576, 6, 41 },
171 { "Bluray PAL 24Mb/s", 100, 24000000, 720, 576, 6, 32 },
172 { "Bluray PAL 16Mb/s", 100, 16800000, 720, 576, 6, 31 },
173 { "Bluray PAL 12Mb/s", 100, 12000000, 720, 576, 5, 30 },
174 { "Bluray NTSC 40Mb/s", 100, 40000000, 720, 480, 6, 41 },
175 { "Bluray NTSC 24Mb/s", 100, 24000000, 720, 480, 6, 32 },
176 { "Bluray NTSC 16Mb/s", 100, 16800000, 720, 480, 6, 31 },
177 { "Bluray NTSC 12Mb/s", 100, 12000000, 720, 480, 6, 30 },
178 };
179
181 {
184
185 #define CHECK(expected, format, ...) do { \
186 if (expected ? (!level || level->level_idc != expected) \
187 : !!level) { \
188 av_log(NULL, AV_LOG_ERROR, "Incorrect level for " \
189 format ": expected %d, got %d.\n", __VA_ARGS__, \
190 expected, level ? level->level_idc : -1); \
191 return 1; \
192 } \
193 } while (0)
194
200 }
201
209 }
210
218 }
219
223 0, 0, 0, 0);
226 }
227
231 0,
236 }
237
238 return 0;
239 }