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;
72 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
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");
101 if ((err =
av_reallocp(&out, total_size + padding)) < 0)
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);
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");
150 "The input looks like it is Annex B already\n");
151 }
else if (extra_size >= 7) {
193 #define LOG_ONCE(...) \ 196 for (
int j = 0; j < 2; j++) {
204 uint32_t nal_size = 0;
208 nal_size = (nal_size << 8) | buf[
i];
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;
269 }
while (buf < buf_end);
316 .
name =
"h264_mp4toannexb",
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVCodecParameters * par_out
Parameters of the output stream.
static void copy(const float *p1, float *p2, const int length)
static void flush(AVCodecContext *avctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
The bitstream filter state.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static int h264_mp4toannexb_init(AVBSFContext *ctx)
void * priv_data
Opaque filter-specific private data.
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
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
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
static int h264_extradata_to_annexb(AVBSFContext *ctx, const int padding)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
#define AV_LOG_VERBOSE
Detailed information.
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
H.264 common definitions.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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
static void h264_mp4toannexb_flush(AVBSFContext *ctx)
simple assert() macros that are a bit more flexible than ISO C assert().
int extradata_size
Size of the extradata content in bytes.
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
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_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Libavcodec external API header.
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 av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static enum AVCodecID codec_ids[]
int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
Called by the bitstream filters to get the next packet for filtering.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
const AVBitStreamFilter ff_h264_mp4toannexb_bsf
static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt)
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
This structure stores compressed data.
AVCodecParameters * par_in
Parameters of the input stream.