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;
96 if (extradata_size < 7) {
106 length_size = (bytestream2_get_byteu(gb) & 0x3) + 1;
109 unit_nb = bytestream2_get_byteu(gb) & 0x1f;
118 unit_size = bytestream2_get_be16u(gb);
119 total_size += unit_size + 4;
123 "corrupted stream or invalid MP4/AVCC bitstream\n");
129 memcpy(
out + total_size - unit_size - 4, nalu_header, 4);
132 if (!unit_nb && !sps_done++) {
133 unit_nb = bytestream2_get_byteu(gb);
134 pps_offset = total_size;
139 memset(
out + total_size, 0, padding);
144 s->sps_size = pps_offset;
151 memcpy(
s->sps,
out,
s->sps_size);
154 "Warning: SPS NALU missing or invalid. "
155 "The resulting stream may not play.\n");
157 if (pps_offset < total_size) {
160 s->pps_size = total_size - pps_offset;
168 memcpy(
s->pps,
out + pps_offset,
s->pps_size);
171 "Warning: PPS NALU missing or invalid. "
172 "The resulting stream may not play.\n");
176 ctx->par_out->extradata =
out;
177 ctx->par_out->extradata_size = total_size;
179 s->length_size = length_size;
183 s->extradata_parsed = 1;
189 unsigned *dst_buf_size,
190 const uint8_t *nal, uint32_t nal_size,
193 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
194 const int start_code_size =
sizeof(nalu_header);
207 memcpy(ptr +
size, nalu_header, start_code_size);
208 size += start_code_size;
209 memcpy(ptr +
size, nal, nal_size);
219 const uint8_t *buf_end)
226 uint32_t nal_size = 0;
229 for (
int i = 0;
i <
s->length_size;
i++)
230 nal_size = (nal_size << 8) | buf[
i];
232 buf +=
s->length_size;
236 if ((
int64_t)nal_size > buf_end - buf)
242 unit_type = *buf & 0x1f;
246 nal_size, !sps_count);
250 nal_size, !pps_count);
255 }
while (buf < buf_end);
262 int extra_size =
ctx->par_in->extradata_size;
266 (extra_size >= 3 &&
AV_RB24(
ctx->par_in->extradata) == 1) ||
267 (extra_size >= 4 &&
AV_RB32(
ctx->par_in->extradata) == 1)) {
269 "The input looks like it is Annex B already\n");
273 ctx->par_in->extradata,
274 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;
296 if (extradata && extradata[0] == 1) {
305 if (!
s->extradata_parsed) {
316 #define LOG_ONCE(...) \
319 for (
int j = 0; j < 2; j++) {
321 new_idr =
s->new_idr;
322 sps_seen =
s->idr_sps_seen;
323 pps_seen =
s->idr_pps_seen;
327 uint32_t nal_size = 0;
331 for (
int i = 0;
i <
s->length_size;
i++)
332 nal_size = (nal_size << 8) | buf[
i];
334 buf +=
s->length_size;
338 if ((
int64_t)nal_size > buf_end - buf) {
346 unit_type = *buf & 0x1f;
349 sps_seen = new_idr = 1;
351 pps_seen = new_idr = 1;
372 !sps_seen && !pps_seen) {
411 }
while (buf < buf_end);
428 s->new_idr = new_idr;
429 s->idr_sps_seen = sps_seen;
430 s->idr_pps_seen = pps_seen;
458 s->new_idr =
s->extradata_parsed;
466 .
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)
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 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.
av_cold void CBS_FUNC() close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
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)
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 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)