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 const uint8_t *extradata,
int extradata_size,
86 uint8_t **out_extradata,
int *out_extradata_size)
91 uint32_t total_size = 0;
92 uint8_t *
out =
NULL, unit_nb, sps_done = 0;
93 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
95 int length_size, pps_offset = 0;
97 if (extradata_size < 7) {
107 length_size = (bytestream2_get_byteu(gb) & 0x3) + 1;
110 unit_nb = bytestream2_get_byteu(gb) & 0x1f;
119 unit_size = bytestream2_get_be16u(gb);
120 total_size += unit_size + 4;
124 "corrupted stream or invalid MP4/AVCC bitstream\n");
130 memcpy(
out + total_size - unit_size - 4, nalu_header, 4);
133 if (!unit_nb && !sps_done++) {
134 unit_nb = bytestream2_get_byteu(gb);
135 pps_offset = total_size;
140 memset(
out + total_size, 0, padding);
145 s->sps_size = pps_offset;
152 memcpy(
s->sps,
out,
s->sps_size);
155 "Warning: SPS NALU missing or invalid. "
156 "The resulting stream may not play.\n");
158 if (pps_offset < total_size) {
161 s->pps_size = total_size - pps_offset;
169 memcpy(
s->pps,
out + pps_offset,
s->pps_size);
172 "Warning: PPS NALU missing or invalid. "
173 "The resulting stream may not play.\n");
176 if (out_extradata && out_extradata_size) {
178 *out_extradata =
out;
179 *out_extradata_size = total_size;
183 s->length_size = length_size;
187 s->extradata_parsed = 1;
193 unsigned *dst_buf_size,
194 const uint8_t *
nal, uint32_t nal_size,
197 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
198 const int start_code_size =
sizeof(nalu_header);
211 memcpy(ptr +
size, nalu_header, start_code_size);
212 size += start_code_size;
213 memcpy(ptr +
size,
nal, nal_size);
223 const uint8_t *buf_end)
230 uint32_t nal_size = 0;
233 for (
int i = 0;
i <
s->length_size;
i++)
234 nal_size = (nal_size << 8) | buf[
i];
236 buf +=
s->length_size;
240 if ((
int64_t)nal_size > buf_end - buf)
246 unit_type = *buf & 0x1f;
250 nal_size, !sps_count);
254 nal_size, !pps_count);
259 }
while (buf < buf_end);
266 int extra_size =
ctx->par_in->extradata_size;
270 (extra_size >= 3 &&
AV_RB24(
ctx->par_in->extradata) == 1) ||
271 (extra_size >= 4 &&
AV_RB32(
ctx->par_in->extradata) == 1)) {
273 "The input looks like it is Annex B already\n");
277 ctx->par_in->extradata,
278 ctx->par_in->extradata_size,
279 &
ctx->par_out->extradata,
280 &
ctx->par_out->extradata_size);
287 uint8_t unit_type, new_idr, sps_seen, pps_seen;
289 const uint8_t *buf_end;
293 size_t extradata_size;
302 if (extradata && extradata[0] == 1) {
311 if (!
s->extradata_parsed) {
322 #define LOG_ONCE(...) \
325 for (
int j = 0; j < 2; j++) {
327 new_idr =
s->new_idr;
328 sps_seen =
s->idr_sps_seen;
329 pps_seen =
s->idr_pps_seen;
333 uint32_t nal_size = 0;
337 for (
int i = 0;
i <
s->length_size;
i++)
338 nal_size = (nal_size << 8) | buf[
i];
340 buf +=
s->length_size;
344 if ((
int64_t)nal_size > buf_end - buf) {
352 unit_type = *buf & 0x1f;
355 sps_seen = new_idr = 1;
357 pps_seen = new_idr = 1;
378 !sps_seen && !pps_seen) {
417 }
while (buf < buf_end);
434 s->new_idr = new_idr;
435 s->idr_sps_seen = sps_seen;
436 s->idr_pps_seen = pps_seen;
464 s->new_idr =
s->extradata_parsed;
472 .
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 av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
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)
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.
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 int h264_extradata_to_annexb(AVBSFContext *ctx, const uint8_t *extradata, int extradata_size, uint8_t **out_extradata, int *out_extradata_size)
static av_cold void close(AVCodecParserContext *s)
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.
static AVFormatContext * ctx
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.
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
#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 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.
static int FUNC() nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
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)
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt)
#define AV_INPUT_BUFFER_PADDING_SIZE
@ SEI_TYPE_BUFFERING_PERIOD
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)