Go to the documentation of this file.
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",
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int hevc_extradata_to_annexb(AVBSFContext *ctx, const uint8_t *extradata, int extradata_size, uint8_t **out_extradata, int *out_extradata_size)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static void hevc_mp4toannexb_close(AVBSFContext *ctx)
@ 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...
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
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.
#define AV_LOG_VERBOSE
Detailed information.
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.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
The bitstream filter state.
static av_cold void close(AVCodecParserContext *s)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static int hevc_mp4toannexb_init(AVBSFContext *ctx)
static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVFormatContext * ctx
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
AVCodecID
Identify the syntax and semantics of the bitstream.
@ HEVC_NAL_RSV_IRAP_VCL23
AVBitStreamFilter p
The public AVBitStreamFilter.
int(* init)(AVBSFContext *ctx)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
#define i(width, name, range_min, range_max)
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
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
static enum AVCodecID codec_ids[]
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
#define AV_INPUT_BUFFER_PADDING_SIZE
This structure stores compressed data.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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
void * priv_data
Format private data.