34#define MIN_HEVCC_LENGTH 23
44 const uint8_t *extradata,
int extradata_size,
45 uint8_t **out_extradata,
int *out_extradata_size)
49 int length_size, num_arrays,
i, j;
52 uint8_t *new_extradata =
NULL;
53 size_t new_extradata_size = 0;
58 length_size = (bytestream2_get_byte(&gb) & 3) + 1;
59 num_arrays = bytestream2_get_byte(&gb);
61 for (
i = 0;
i < num_arrays;
i++) {
62 int type = bytestream2_get_byte(&gb) & 0x3f;
63 int cnt = bytestream2_get_be16(&gb);
73 for (j = 0; j < cnt; j++) {
74 const int nalu_len = bytestream2_get_be16(&gb);
86 AV_WB32(new_extradata + new_extradata_size, 1);
88 new_extradata_size += 4 + nalu_len;
93 if (!new_extradata_size)
96 if (out_extradata && out_extradata_size) {
100 if (!(*out_extradata)) {
104 *out_extradata_size = new_extradata_size;
105 memcpy(*out_extradata, new_extradata, new_extradata_size);
106 memset(*out_extradata + new_extradata_size, 0,
111 s->extradata = new_extradata;
112 s->extradata_size = new_extradata_size;
114 s->length_size = length_size;
115 s->extradata_parsed = 1;
130 "The input looks like it is Annex B already\n");
133 ctx->par_in->extradata,
134 ctx->par_in->extradata_size,
135 &
ctx->par_out->extradata,
136 &
ctx->par_out->extradata_size);
151 int got_ps = 0, seen_irap_ps = 0;
153 size_t extradata_size = 0;
154 uint8_t *extradata =
NULL;
163 ((extradata[0] == 1) ||
164 (extradata[0] == 0 && (extradata[1] || extradata[2] > 1)))) {
173 if (!
s->extradata_parsed) {
182 uint32_t nalu_size = 0;
189 for (
i = 0;
i <
s->length_size;
i++)
190 nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb);
197 nalu_type = (bytestream2_peek_byte(&gb) >> 1) & 0x3f;
203 seen_irap_ps = got_irap && got_ps;
204 got_irap = got_ps = 0;
209 uint32_t nalu_size = 0;
211 int is_irap, is_ps, add_extradata, extra_size, prev_size;
217 for (
i = 0;
i <
s->length_size;
i++)
218 nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb);
225 nalu_type = (bytestream2_peek_byte(&gb) >> 1) & 0x3f;
231 add_extradata = (is_ps || is_irap) && !got_ps && !got_irap;
232 extra_size = add_extradata *
s->extradata_size;
236 if (
FFMIN(INT_MAX, SIZE_MAX) < 4ULL + nalu_size + extra_size) {
241 prev_size =
out->size;
248 memcpy(
out->data + prev_size,
s->extradata, extra_size);
249 AV_WB32(
out->data + prev_size + extra_size, 1);
276 .p.name =
"hevc_mp4toannexb",
static enum AVCodecID codec_ids[]
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
const FFBitStreamFilter ff_hevc_mp4toannexb_bsf
int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
Called by the bitstream filters to get the next packet for filtering.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define i(width, name, range_min, range_max)
Misc types and constants that do not belong anywhere else.
int(* init)(AVBSFContext *ctx)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_packet_side_data_remove(AVPacketSideData *sd, int *pnb_sd, enum AVPacketSideDataType type)
Remove side data of the given type from a side data array.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
static int hevc_mp4toannexb_init(AVBSFContext *ctx)
static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
static int hevc_extradata_to_annexb(AVBSFContext *ctx, const uint8_t *extradata, int extradata_size, uint8_t **out_extradata, int *out_extradata_size)
static void hevc_mp4toannexb_close(AVBSFContext *ctx)
@ HEVC_NAL_RSV_IRAP_VCL23
Memory handling functions.
The bitstream filter state.
This structure stores compressed data.
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)