Go to the documentation of this file.
56 const uint8_t *in,
int in_size,
enum PsSource ps,
int copy)
58 uint8_t start_code_size;
71 memcpy(*
out + start_code_size, in, in_size);
72 if (start_code_size == 4) {
74 }
else if (start_code_size) {
79 *
out += start_code_size + in_size;
81 *
out_size += start_code_size + in_size;
85 uint8_t *extradata,
int extradata_size)
90 uint32_t total_size = 0;
91 uint8_t *
out =
NULL, unit_nb, sps_done = 0;
92 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
94 int length_size, pps_offset = 0;
101 length_size = (bytestream2_get_byteu(gb) & 0x3) + 1;
104 unit_nb = bytestream2_get_byteu(gb) & 0x1f;
113 unit_size = bytestream2_get_be16u(gb);
114 total_size += unit_size + 4;
118 "corrupted stream or invalid MP4/AVCC bitstream\n");
124 memcpy(
out + total_size - unit_size - 4, nalu_header, 4);
127 if (!unit_nb && !sps_done++) {
128 unit_nb = bytestream2_get_byteu(gb);
129 pps_offset = total_size;
134 memset(
out + total_size, 0, padding);
139 s->sps_size = pps_offset;
146 memcpy(
s->sps,
out,
s->sps_size);
149 "Warning: SPS NALU missing or invalid. "
150 "The resulting stream may not play.\n");
152 if (pps_offset < total_size) {
155 s->pps_size = total_size - pps_offset;
163 memcpy(
s->pps,
out + pps_offset,
s->pps_size);
166 "Warning: PPS NALU missing or invalid. "
167 "The resulting stream may not play.\n");
171 ctx->par_out->extradata =
out;
172 ctx->par_out->extradata_size = total_size;
174 s->length_size = length_size;
178 s->extradata_parsed = 1;
184 unsigned *dst_buf_size,
185 const uint8_t *nal, uint32_t nal_size,
188 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
189 const int start_code_size =
sizeof(nalu_header);
202 memcpy(ptr +
size, nalu_header, start_code_size);
203 size += start_code_size;
204 memcpy(ptr +
size, nal, nal_size);
214 const uint8_t *buf_end)
221 uint32_t nal_size = 0;
224 for (
int i = 0;
i <
s->length_size;
i++)
225 nal_size = (nal_size << 8) | buf[
i];
227 buf +=
s->length_size;
231 if ((
int64_t)nal_size > buf_end - buf)
237 unit_type = *buf & 0x1f;
241 nal_size, !sps_count);
245 nal_size, !pps_count);
250 }
while (buf < buf_end);
257 int extra_size =
ctx->par_in->extradata_size;
261 (extra_size >= 3 &&
AV_RB24(
ctx->par_in->extradata) == 1) ||
262 (extra_size >= 4 &&
AV_RB32(
ctx->par_in->extradata) == 1)) {
264 "The input looks like it is Annex B already\n");
265 }
else if (extra_size >= 7) {
267 ctx->par_in->extradata,
268 ctx->par_in->extradata_size);
281 uint8_t unit_type, new_idr, sps_seen, pps_seen;
283 const uint8_t *buf_end;
287 size_t extradata_size;
303 if (!
s->extradata_parsed) {
314 #define LOG_ONCE(...) \
317 for (
int j = 0; j < 2; j++) {
319 new_idr =
s->new_idr;
320 sps_seen =
s->idr_sps_seen;
321 pps_seen =
s->idr_pps_seen;
325 uint32_t nal_size = 0;
329 for (
int i = 0;
i <
s->length_size;
i++)
330 nal_size = (nal_size << 8) | buf[
i];
332 buf +=
s->length_size;
336 if ((
int64_t)nal_size > buf_end - buf) {
344 unit_type = *buf & 0x1f;
347 sps_seen = new_idr = 1;
349 pps_seen = new_idr = 1;
370 !sps_seen && !pps_seen) {
409 }
while (buf < buf_end);
426 s->new_idr = new_idr;
427 s->idr_sps_seen = sps_seen;
428 s->idr_pps_seen = pps_seen;
456 s->new_idr =
s->extradata_parsed;
464 .
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.
void(* filter)(uint8_t *src, int stride, int qscale)
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)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
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
@ SEI_TYPE_BUFFERING_PERIOD
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)