31 #define MIN_HEVCC_LENGTH 23
55 int length_size, num_arrays, i, j;
59 size_t new_extradata_size = 0;
64 length_size = (bytestream2_get_byte(&gb) & 3) + 1;
65 num_arrays = bytestream2_get_byte(&gb);
67 for (i = 0; i < num_arrays; i++) {
68 int type = bytestream2_get_byte(&gb) & 0x3f;
69 int cnt = bytestream2_get_be16(&gb);
79 for (j = 0; j < cnt; j++) {
80 int nalu_len = bytestream2_get_be16(&gb);
90 AV_WB32(new_extradata + new_extradata_size, 1);
92 new_extradata_size += 4 + nalu_len;
105 if (!new_extradata_size)
116 uint8_t **poutbuf,
int *poutbuf_size,
134 "The input looks like it is Annex B already\n");
138 *poutbuf_size = buf_size;
141 if (args && strstr(args,
"private_spspps_buf"))
157 uint32_t nalu_size = 0;
159 int is_irap, add_extradata, extra_size;
162 nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb);
164 nalu_type = (bytestream2_peek_byte(&gb) >> 1) & 0x3f;
167 is_irap = nalu_type >= 16 && nalu_type <= 23;
168 add_extradata = is_irap && !got_irap;
172 if (SIZE_MAX - out_size < 4 ||
173 SIZE_MAX - out_size - 4 < nalu_size ||
174 SIZE_MAX - out_size - 4 - nalu_size < extra_size) {
179 ret =
av_reallocp(&out, out_size + 4 + nalu_size + extra_size);
184 memcpy(out + out_size, ctx->
spspps_buf, extra_size);
185 AV_WB32(out + out_size + extra_size, 1);
187 out_size += 4 + nalu_size + extra_size;
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
memory handling functions
static int hevc_mp4toannexb_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
int logged_nonmp4_warning
static int hevc_extradata_to_annexb(HEVCBSFContext *ctx, AVCodecContext *avctx)
Libavcodec external API header.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
main external API structure.
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
static void hevc_mp4toannexb_close(AVBitStreamFilterContext *bsfc)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
AVBitStreamFilter ff_hevc_mp4toannexb_bsf