Go to the documentation of this file.
47 const uint8_t *in,
int in_size,
int ps,
int copy)
49 uint8_t start_code_size = ps < 0 ? 0 : *
out_size == 0 || ps ? 4 : 3;
52 memcpy(*
out + start_code_size, in, in_size);
53 if (start_code_size == 4) {
55 }
else if (start_code_size) {
60 *
out += start_code_size + in_size;
62 *
out_size += start_code_size + in_size;
70 uint32_t total_size = 0;
71 uint8_t *
out =
NULL, unit_nb, sps_done = 0;
72 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
73 int length_size, pps_offset = 0;
80 length_size = (bytestream2_get_byteu(gb) & 0x3) + 1;
83 unit_nb = bytestream2_get_byteu(gb) & 0x1f;
92 unit_size = bytestream2_get_be16u(gb);
93 total_size += unit_size + 4;
97 "corrupted stream or invalid MP4/AVCC bitstream\n");
103 memcpy(
out + total_size - unit_size - 4, nalu_header, 4);
106 if (!unit_nb && !sps_done++) {
107 unit_nb = bytestream2_get_byteu(gb);
108 pps_offset = total_size;
113 memset(
out + total_size, 0, padding);
117 s->sps_size = pps_offset;
120 "Warning: SPS NALU missing or invalid. "
121 "The resulting stream may not play.\n");
123 if (pps_offset < total_size) {
124 s->pps =
out + pps_offset;
125 s->pps_size = total_size - pps_offset;
128 "Warning: PPS NALU missing or invalid. "
129 "The resulting stream may not play.\n");
133 ctx->par_out->extradata =
out;
134 ctx->par_out->extradata_size = total_size;
142 int extra_size =
ctx->par_in->extradata_size;
147 (extra_size >= 3 &&
AV_RB24(
ctx->par_in->extradata) == 1) ||
148 (extra_size >= 4 &&
AV_RB32(
ctx->par_in->extradata) == 1)) {
150 "The input looks like it is Annex B already\n");
151 }
else if (extra_size >= 7) {
156 s->length_size =
ret;
160 s->extradata_parsed = 1;
173 uint8_t unit_type, new_idr, sps_seen, pps_seen;
175 const uint8_t *buf_end;
185 if (!
s->extradata_parsed) {
193 #define LOG_ONCE(...) \
196 for (
int j = 0; j < 2; j++) {
198 new_idr =
s->new_idr;
199 sps_seen =
s->idr_sps_seen;
200 pps_seen =
s->idr_pps_seen;
204 uint32_t nal_size = 0;
207 for (
int i = 0;
i <
s->length_size;
i++)
208 nal_size = (nal_size << 8) | buf[
i];
210 buf +=
s->length_size;
214 if ((int64_t)nal_size > buf_end - buf) {
222 unit_type = *buf & 0x1f;
225 sps_seen = new_idr = 1;
227 pps_seen = new_idr = 1;
247 if (
ctx->par_out->extradata)
249 ctx->par_out->extradata_size, -1, j);
269 }
while (buf < buf_end);
286 s->new_idr = new_idr;
287 s->idr_sps_seen = sps_seen;
288 s->idr_pps_seen = pps_seen;
308 s->new_idr =
s->extradata_parsed;
316 .
name =
"h264_mp4toannexb",
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt)
#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 void h264_mp4toannexb_flush(AVBSFContext *ctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static enum AVCodecID codec_ids[]
static void flush(AVCodecContext *avctx)
const AVBitStreamFilter ff_h264_mp4toannexb_bsf
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.
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_init(AVBSFContext *ctx)
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)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
static void count_or_copy(uint8_t **out, uint64_t *out_size, const uint8_t *in, int in_size, int ps, int copy)
#define AV_INPUT_BUFFER_PADDING_SIZE
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
static int h264_extradata_to_annexb(AVBSFContext *ctx, const int padding)
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.