41 const uint8_t *sps_pps, uint32_t sps_pps_size,
42 const uint8_t *
in, uint32_t in_size,
int ps)
45 uint8_t start_code_size = offset == 0 || ps ? 4 : 3;
48 err =
av_grow_packet(out, sps_pps_size + in_size + start_code_size);
53 memcpy(out->
data + offset, sps_pps, sps_pps_size);
54 memcpy(out->
data + sps_pps_size + start_code_size + offset, in, in_size);
55 if (start_code_size == 4) {
58 (out->
data + offset + sps_pps_size)[0] =
59 (out->
data + offset + sps_pps_size)[1] = 0;
60 (out->
data + offset + sps_pps_size)[2] = 1;
70 uint64_t total_size = 0;
72 sps_seen = 0, pps_seen = 0;
74 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
80 unit_nb = *extradata++ & 0x1f;
92 total_size += unit_size + 4;
93 if (total_size > INT_MAX - padding) {
95 "Too big extradata size, corrupted stream or invalid MP4/AVCC bitstream\n");
101 "corrupted stream or invalid MP4/AVCC bitstream\n");
105 if ((err =
av_reallocp(&out, total_size + padding)) < 0)
107 memcpy(out + total_size - unit_size - 4, nalu_header, 4);
108 memcpy(out + total_size - unit_size, extradata + 2, unit_size);
109 extradata += 2 + unit_size;
111 if (!unit_nb && !sps_done++) {
112 unit_nb = *extradata++;
121 memset(out + total_size, 0, padding);
125 "Warning: SPS NALU missing or invalid. " 126 "The resulting stream may not play.\n");
130 "Warning: PPS NALU missing or invalid. " 131 "The resulting stream may not play.\n");
151 "The input looks like it is Annex B already\n");
152 }
else if (extra_size >= 6) {
177 uint32_t cumul_size = 0;
204 nal_size = (nal_size << 8) | buf[i];
207 unit_type = *buf & 0x1f;
209 if (nal_size > buf_end - buf || nal_size < 0)
214 else if (unit_type == 8) {
219 av_log(ctx,
AV_LOG_WARNING,
"SPS not present in the stream, nor in AVCC, stream may be unreadable\n");
224 buf, nal_size, 1)) < 0)
235 if (!s->
new_idr && unit_type == 5 && (buf[1] & 0x80))
242 buf, nal_size, 1)) < 0)
248 av_log(ctx,
AV_LOG_WARNING,
"PPS not present in the stream, nor in AVCC, stream may be unreadable\n");
253 buf, nal_size, 1)) < 0)
256 if ((ret=
alloc_and_copy(out,
NULL, 0, buf, nal_size, unit_type == 7 || unit_type == 8)) < 0)
258 if (!s->
new_idr && unit_type == 1) {
268 }
while (cumul_size < buf_size);
287 .
name =
"h264_mp4toannexb",
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVCodecParameters * par_out
Parameters of the output stream.
#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 int h264_mp4toannexb_init(AVBSFContext *ctx)
void * priv_data
Opaque filter-specific private data.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
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)
#define AV_LOG_VERBOSE
Detailed information.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint8_t offset[127][2]
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 int alloc_and_copy(AVPacket *out, const uint8_t *sps_pps, uint32_t sps_pps_size, const uint8_t *in, uint32_t in_size, int ps)
static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
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.
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)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
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.
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
#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
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.