FFmpeg
Loading...
Searching...
No Matches
codecstring.c
Go to the documentation of this file.
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 License
6 * 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
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * 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 <stdio.h>
20#include <string.h>
21
22#include "libavutil/bprint.h"
23#include "libavutil/macros.h"
24#include "libavutil/mem.h"
26#include "libavcodec/defs.h"
28
29/* Extradata of a 160x120 encoding: libx264 High profile, libx265 Main
30 * profile. */
31static const uint8_t h264_annexb[] = {
32 0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x0b, 0xac, 0xd9, 0x42, 0x84,
33 0x7e, 0x5c, 0x04, 0x40, 0x00, 0x00, 0x03, 0x00, 0x40, 0x00, 0x00, 0x0c,
34 0x83, 0xc5, 0x0a, 0x65, 0x80,
35};
36
37static const uint8_t h264_avcc[] = {
38 0x01, 0x64, 0x00, 0x0b, 0xff, 0xe1,
39};
40
41static const uint8_t hevc_annexb[] = {
42 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03,
43 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x1e, 0xa0, 0x14,
44 0x20, 0x79, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xbc, 0x05, 0xa0, 0x20, 0x00,
45 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x03, 0x03, 0x21, 0x00,
46};
47
48static const uint8_t hevc_annexb_3byte_start_code[] = {
49 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03, 0x00,
50 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x1e, 0xa0, 0x14, 0x20,
51 0x79, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xbc, 0x05, 0xa0, 0x20, 0x00, 0x00,
52 0x03, 0x00, 0x20, 0x00, 0x00, 0x03, 0x03, 0x21, 0x00,
53};
54
55static const uint8_t hevc_hvcc[] = {
56 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
58};
59
60static const uint8_t hevc_hvcc_version0[] = {
61 0x00, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
63};
64
65static const uint8_t hevc_hvcc_zeroed[] = {
66 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
68};
69
70static const uint8_t hevc_hvcc_profile_space[] = {
71 0x01, 0x41, 0x60, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
72 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
73};
74
75static const uint8_t hevc_hvcc_constraints[] = {
76 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x00, 0x10, 0x00, 0x00, 0x00,
77 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
78};
79
80static const uint8_t hevc_hvcc_constraints_full[] = {
81 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x10, 0x20, 0x30, 0x40, 0x50,
82 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
83};
84
85static const uint8_t hevc_annexb_leading_zero[] = {
86 0x00, 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00,
87 0x03, 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x1e, 0xa0,
88 0x14, 0x20, 0x79, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xbc, 0x05, 0xa0, 0x20,
89 0x00, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x03, 0x03, 0x21, 0x00,
90};
91
92/* hevc_annexb with the maximum of 32 long-term reference pictures */
93static const uint8_t hevc_annexb_32_long_term_refs[] = {
94 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03,
95 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x1e, 0xa0, 0x14,
96 0x20, 0x79, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xc1, 0x08, 0x00, 0x04, 0x04,
97 0x03, 0x02, 0x01, 0x40, 0xc0, 0x70, 0x40, 0x24, 0x14, 0x0b, 0x06, 0x03,
98 0x41, 0xc0, 0xf0, 0x80, 0x44, 0x24, 0x13, 0x0a, 0x05, 0x42, 0xc1, 0x70,
99 0xc0, 0x64, 0x34, 0x1b, 0x0e, 0x07, 0x43, 0xc1, 0xf7, 0x80, 0xb4, 0x04,
100 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x64, 0x20,
101};
102
103typedef struct TestCase {
104 const char *name;
106 uint32_t codec_tag;
108 const uint8_t *extradata;
110} TestCase;
111
112static const TestCase cases[] = {
113 { "h264-annexb", AV_CODEC_ID_H264, 0,
115 { "h264-annexb-avc3", AV_CODEC_ID_H264, MKTAG('a', 'v', 'c', '3'),
117 { "h264-avcc", AV_CODEC_ID_H264, MKTAG('a', 'v', 'c', '1'),
119 { "hevc-annexb-hvc1", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'),
121 { "hevc-annexb-hev1", AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', '1'),
123 { "hevc-annexb-3byte-start-code", AV_CODEC_ID_HEVC,
124 MKTAG('h', 'v', 'c', '1'), AV_PROFILE_UNKNOWN,
126 { "hevc-annexb-untagged", AV_CODEC_ID_HEVC, 0,
128 { "hevc-hvcc-hvc1", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'),
130 { "hevc-hvcc-hev1", AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', '1'),
132 { "hevc-hvcc-version0", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'),
134 { "hevc-hvcc-zeroed", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'),
136 { "hevc-hvcc-profile-space", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'),
138 sizeof(hevc_hvcc_profile_space) },
139 { "hevc-hvcc-constraints", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'),
141 sizeof(hevc_hvcc_constraints) },
142 { "hevc-hvcc-constraints-full", AV_CODEC_ID_HEVC,
143 MKTAG('h', 'v', 'c', '1'), AV_PROFILE_UNKNOWN,
145 { "hevc-annexb-32-long-term-refs", AV_CODEC_ID_HEVC,
146 MKTAG('h', 'v', 'c', '1'), AV_PROFILE_UNKNOWN,
148 { "hevc-annexb-leading-zero", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'),
150 sizeof(hevc_annexb_leading_zero) },
151 { "aac-lc", AV_CODEC_ID_AAC, 0,
153};
154
155static int run_case(const TestCase *test)
156{
158 AVBPrint out;
159 int ret;
160
161 if (!par)
162 return AVERROR(ENOMEM);
163 par->codec_id = test->codec_id;
164 par->codec_tag = test->codec_tag;
165 par->profile = test->profile;
166 if (test->extradata_size) {
167 par->extradata = av_mallocz(test->extradata_size +
169 if (!par->extradata) {
171 return AVERROR(ENOMEM);
172 }
173 memcpy(par->extradata, test->extradata, test->extradata_size);
174 par->extradata_size = test->extradata_size;
175 }
176
178 ret = av_mime_codec_str(par, (AVRational){ 1, 0 }, &out);
179 printf("%s: %s\n", test->name, ret < 0 ? "error" : out.str);
182
183 return ret == AVERROR(ENOMEM) ? ret : 0;
184}
185
186int main(void)
187{
188 for (size_t i = 0; i < FF_ARRAY_ELEMS(cases); i++)
189 if (run_case(&cases[i]) < 0)
190 return 1;
191 return 0;
192}
static FILE * out
Main libavformat public API header.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
AVBPrint public header.
#define AV_BPRINT_SIZE_UNLIMITED
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
AVCodecParameters * avcodec_parameters_alloc(void)
Definition codec_par.c:57
void avcodec_parameters_free(AVCodecParameters **ppar)
Definition codec_par.c:67
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
Misc types and constants that do not belong anywhere else.
#define AV_PROFILE_UNKNOWN
Definition defs.h:65
#define AV_PROFILE_AAC_LOW
Definition defs.h:69
#define AV_PROFILE_HEVC_MAIN
Definition defs.h:173
int ret
Definition ffplay.c:391
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
@ AV_CODEC_ID_AAC
Definition codec_id.h:461
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
int av_mime_codec_str(const AVCodecParameters *par, AVRational frame_rate, struct AVBPrint *out)
Make a RFC 4281/6381 like string describing a codec for MIME types.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:234
#define AVERROR(e)
Definition error.h:45
Utility Preprocessor macros.
#define MKTAG(a, b, c, d)
Definition macros.h:55
Memory handling functions.
#define FF_ARRAY_ELEMS(a)
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition codec_par.h:135
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Rational number (pair of numerator and denominator).
Definition rational.h:58
uint32_t codec_tag
enum AVCodecID codec_id
const char * name
int extradata_size
const uint8_t * extradata
Definition idctdsp.c:35
const char * name
Definition idctdsp.c:36
#define av_mallocz(s)
static const uint8_t hevc_annexb[]
Definition codecstring.c:41
static const uint8_t hevc_annexb_3byte_start_code[]
Definition codecstring.c:48
static const uint8_t hevc_hvcc_version0[]
Definition codecstring.c:60
static const uint8_t hevc_hvcc[]
Definition codecstring.c:55
int main(void)
static const uint8_t hevc_hvcc_constraints_full[]
Definition codecstring.c:80
static const uint8_t hevc_hvcc_constraints[]
Definition codecstring.c:75
static const uint8_t hevc_hvcc_zeroed[]
Definition codecstring.c:65
static const uint8_t hevc_annexb_32_long_term_refs[]
Definition codecstring.c:93
static const uint8_t hevc_hvcc_profile_space[]
Definition codecstring.c:70
static const uint8_t hevc_annexb_leading_zero[]
Definition codecstring.c:85
static const uint8_t h264_annexb[]
Definition codecstring.c:31
static const uint8_t h264_avcc[]
Definition codecstring.c:37
static int run_case(const TestCase *test)
static const TestCase cases[]