Go to the documentation of this file.
55 const uint8_t *in,
int in_size,
enum PsSource ps,
int copy)
57 uint8_t start_code_size;
70 memcpy(*
out + start_code_size, in, in_size);
71 if (start_code_size == 4) {
73 }
else if (start_code_size) {
78 *
out += start_code_size + in_size;
80 *
out_size += start_code_size + in_size;
84 uint8_t *extradata,
int extradata_size)
89 uint32_t total_size = 0;
90 uint8_t *
out =
NULL, unit_nb, sps_done = 0;
91 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
93 int length_size, pps_offset = 0;
100 length_size = (bytestream2_get_byteu(gb) & 0x3) + 1;
103 unit_nb = bytestream2_get_byteu(gb) & 0x1f;
112 unit_size = bytestream2_get_be16u(gb);
113 total_size += unit_size + 4;
117 "corrupted stream or invalid MP4/AVCC bitstream\n");
123 memcpy(
out + total_size - unit_size - 4, nalu_header, 4);
126 if (!unit_nb && !sps_done++) {
127 unit_nb = bytestream2_get_byteu(gb);
128 pps_offset = total_size;
133 memset(
out + total_size, 0, padding);
138 s->sps_size = pps_offset;
145 memcpy(
s->sps,
out,
s->sps_size);
148 "Warning: SPS NALU missing or invalid. "
149 "The resulting stream may not play.\n");
151 if (pps_offset < total_size) {
154 s->pps_size = total_size - pps_offset;
162 memcpy(
s->pps,
out + pps_offset,
s->pps_size);
165 "Warning: PPS NALU missing or invalid. "
166 "The resulting stream may not play.\n");
170 ctx->par_out->extradata =
out;
171 ctx->par_out->extradata_size = total_size;
173 s->length_size = length_size;
177 s->extradata_parsed = 1;
183 unsigned *dst_buf_size,
184 const uint8_t *nal, uint32_t nal_size,
187 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
188 const int start_code_size =
sizeof(nalu_header);
201 memcpy(ptr +
size, nalu_header, start_code_size);
202 size += start_code_size;
203 memcpy(ptr +
size, nal, nal_size);
213 const uint8_t *buf_end)
220 uint32_t nal_size = 0;
223 for (
int i = 0;
i <
s->length_size;
i++)
224 nal_size = (nal_size << 8) | buf[
i];
226 buf +=
s->length_size;
230 if ((
int64_t)nal_size > buf_end - buf)
236 unit_type = *buf & 0x1f;
240 nal_size, !sps_count);
244 nal_size, !pps_count);
249 }
while (buf < buf_end);
256 int extra_size =
ctx->par_in->extradata_size;
260 (extra_size >= 3 &&
AV_RB24(
ctx->par_in->extradata) == 1) ||
261 (extra_size >= 4 &&
AV_RB32(
ctx->par_in->extradata) == 1)) {
263 "The input looks like it is Annex B already\n");
264 }
else if (extra_size >= 7) {
266 ctx->par_in->extradata,
267 ctx->par_in->extradata_size);
280 uint8_t unit_type, new_idr, sps_seen, pps_seen;
282 const uint8_t *buf_end;
286 size_t extradata_size;
302 if (!
s->extradata_parsed) {
313 #define LOG_ONCE(...) \
316 for (
int j = 0; j < 2; j++) {
318 new_idr =
s->new_idr;
319 sps_seen =
s->idr_sps_seen;
320 pps_seen =
s->idr_pps_seen;
324 uint32_t nal_size = 0;
328 for (
int i = 0;
i <
s->length_size;
i++)
329 nal_size = (nal_size << 8) | buf[
i];
331 buf +=
s->length_size;
335 if ((
int64_t)nal_size > buf_end - buf) {
343 unit_type = *buf & 0x1f;
346 sps_seen = new_idr = 1;
348 pps_seen = new_idr = 1;
394 }
while (buf < buf_end);
411 s->new_idr = new_idr;
412 s->idr_sps_seen = sps_seen;
413 s->idr_pps_seen = pps_seen;
441 s->new_idr =
s->extradata_parsed;
449 .
p.
name =
"h264_mp4toannexb",
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_LOG_WARNING
Something somehow does not look correct.
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 void count_or_copy(uint8_t **out, uint64_t *out_size, const uint8_t *in, int in_size, enum PsSource ps, int copy)
@ 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...
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
#define AV_LOG_VERBOSE
Detailed information.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
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 enum AVCodecID codec_ids[]
static int h264_mp4toannexb_filter_ps(H264BSFContext *s, const uint8_t *buf, const uint8_t *buf_end)
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int h264_mp4toannexb_init(AVBSFContext *ctx)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
const FFBitStreamFilter ff_h264_mp4toannexb_bsf
void(* flush)(AVBSFContext *ctx)
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
AVCodecID
Identify the syntax and semantics of the bitstream.
AVBitStreamFilter p
The public AVBitStreamFilter.
int(* init)(AVBSFContext *ctx)
static void copy(const float *p1, float *p2, const int length)
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
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 int h264_mp4toannexb_save_ps(uint8_t **dst, int *dst_size, unsigned *dst_buf_size, const uint8_t *nal, uint32_t nal_size, int first)
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
#define i(width, name, range_min, range_max)
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
static void h264_mp4toannexb_close(AVBSFContext *ctx)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt)
#define AV_INPUT_BUFFER_PADDING_SIZE
static int h264_extradata_to_annexb(AVBSFContext *ctx, uint8_t *extradata, int extradata_size)
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int 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.
static void h264_mp4toannexb_flush(AVBSFContext *ctx)