1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/common.h"
#include "libavcodec/h264_levels.h"
static const struct {
int width;
int height;
int level_idc;
} test_sizes[] = {
// First level usable at some standard sizes.
// (From H.264 table A-6.)
{ 176, 144, 10 }, // QCIF
{ 352, 288, 11 }, // CIF
{ 640, 480, 22 }, // VGA
{ 720, 480, 22 }, // NTSC
{ 720, 576, 22 }, // PAL
{ 800, 600, 31 }, // SVGA
{ 1280, 720, 31 }, // 720p
{ 1280, 1024, 32 }, // SXGA
{ 1920, 1080, 40 }, // 1080p
{ 2048, 1080, 42 }, // 2Kx1080
{ 2048, 1536, 50 }, // 4XGA
{ 3840, 2160, 51 }, // 4K
{ 7680, 4320, 60 }, // 8K
// Overly wide or tall sizes.
{ 1, 256, 10 },
{ 1, 512, 11 },
{ 1, 1024, 21 },
{ 1, 1808, 22 },
{ 1, 1824, 31 },
{ 256, 1, 10 },
{ 512, 1, 11 },
{ 1024, 1, 21 },
{ 1808, 1, 22 },
{ 1824, 1, 31 },
{ 512, 4096, 40 },
{ 256, 4112, 42 },
{ 8688, 1024, 51 },
{ 8704, 512, 60 },
{ 16880, 1, 60 },
{ 16896, 1, 0 },
};
static const struct {
int width;
int height;
int dpb_size;
int level_idc;
} test_dpb[] = {
// First level usable for some DPB sizes.
// (From H.264 table A-7.)
{ 176, 144, 4, 10 },
{ 176, 144, 8, 11 },
{ 176, 144, 16, 12 },
{ 1280, 720, 1, 31 },
{ 1280, 720, 5, 31 },
{ 1280, 720, 9, 40 },
{ 1280, 720, 10, 50 },
{ 1920, 1080, 1, 40 },
{ 1920, 1080, 5, 50 },
{ 1920, 1080, 13, 50 },
{ 1920, 1080, 14, 51 },
{ 3840, 2160, 5, 51 },
{ 3840, 2160, 6, 60 },
{ 3840, 2160, 16, 60 },
{ 7680, 4320, 5, 60 },
{ 7680, 4320, 6, 0 },
};
static const struct {
int64_t bitrate;
int profile_idc;
int level_idc;
} test_bitrate[] = {
// Values where profile affects level at a given bitrate.
{ 2500000, 77, 21 },
{ 2500000, 100, 20 },
{ 2500000, 244, 13 },
{ 100000000, 77, 50 },
{ 100000000, 100, 50 },
{ 100000000, 244, 41 },
{ 999999999, 77, 0 },
{ 999999999, 100, 62 },
// Check level 1b.
{ 32 * 1200, 66, 10 },
{ 32 * 1500, 100, 10 },
{ 96 * 1200, 66, 11 },
{ 96 * 1500, 100, 9 },
{ 144 * 1200, 66, 11 },
{ 144 * 1500, 100, 11 },
};
static const struct {
const char *name;
int profile_idc;
int64_t bitrate;
int width;
int height;
int dpb_frames;
int level_idc;
} test_all[] = {
{ "Bluray 1080p 40Mb/s", 100, 40000000, 1920, 1080, 4, 41 },
{ "Bluray 1080p 24Mb/s", 100, 24000000, 1920, 1080, 4, 40 },
{ "Bluray 720p 40Mb/s", 100, 40000000, 1280, 720, 6, 41 },
{ "Bluray 720p 24Mb/s", 100, 24000000, 1280, 720, 6, 40 },
{ "Bluray PAL 40Mb/s", 100, 40000000, 720, 576, 6, 41 },
{ "Bluray PAL 24Mb/s", 100, 24000000, 720, 576, 6, 32 },
{ "Bluray PAL 16Mb/s", 100, 16800000, 720, 576, 6, 31 },
{ "Bluray PAL 12Mb/s", 100, 12000000, 720, 576, 5, 30 },
{ "Bluray NTSC 40Mb/s", 100, 40000000, 720, 480, 6, 41 },
{ "Bluray NTSC 24Mb/s", 100, 24000000, 720, 480, 6, 32 },
{ "Bluray NTSC 16Mb/s", 100, 16800000, 720, 480, 6, 31 },
{ "Bluray NTSC 12Mb/s", 100, 12000000, 720, 480, 6, 30 },
};
int main(void)
{
const H264LevelDescriptor *level;
int i;
#define CHECK(expected, format, ...) do { \
if (expected ? (!level || level->level_idc != expected) \
: !!level) { \
av_log(NULL, AV_LOG_ERROR, "Incorrect level for " \
format ": expected %d, got %d.\n", __VA_ARGS__, \
expected, level ? level->level_idc : -1); \
return 1; \
} \
} while (0)
for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) {
level = ff_h264_guess_level(0, 0, test_sizes[i].width,
test_sizes[i].height, 0);
CHECK(test_sizes[i].level_idc, "size %dx%d",
test_sizes[i].width, test_sizes[i].height);
}
for (i = 0; i < FF_ARRAY_ELEMS(test_dpb); i++) {
level = ff_h264_guess_level(0, 0, test_dpb[i].width,
test_dpb[i].height,
test_dpb[i].dpb_size);
CHECK(test_dpb[i].level_idc, "size %dx%d dpb %d",
test_dpb[i].width, test_dpb[i].height,
test_dpb[i].dpb_size);
}
for (i = 0; i < FF_ARRAY_ELEMS(test_bitrate); i++) {
level = ff_h264_guess_level(test_bitrate[i].profile_idc,
test_bitrate[i].bitrate,
0, 0, 0);
CHECK(test_bitrate[i].level_idc, "bitrate %"PRId64" profile %d",
test_bitrate[i].bitrate, test_bitrate[i].profile_idc);
}
for (i = 0; i < FF_ARRAY_ELEMS(test_all); i++) {
level = ff_h264_guess_level(test_all[i].profile_idc,
test_all[i].bitrate,
test_all[i].width,
test_all[i].height,
test_all[i].dpb_frames);
CHECK(test_all[i].level_idc, "%s", test_all[i].name);
}
return 0;
}
|