51 const uint8_t *sps_pps, uint32_t sps_pps_size,
54 uint32_t
offset = *poutbuf_size;
55 uint8_t nal_header_size = offset ? 3 : 4;
58 *poutbuf_size += sps_pps_size + in_size + nal_header_size;
65 memcpy(*poutbuf + offset, sps_pps, sps_pps_size);
66 memcpy(*poutbuf + sps_pps_size + nal_header_size + offset, in, in_size);
68 AV_WB32(*poutbuf + sps_pps_size, 1);
70 (*poutbuf + offset + sps_pps_size)[0] =
71 (*poutbuf + offset + sps_pps_size)[1] = 0;
72 (*poutbuf + offset + sps_pps_size)[2] = 1;
81 uint64_t total_size = 0;
83 sps_seen = 0, pps_seen = 0;
85 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
86 int length_size = (*extradata++ & 0x3) + 1;
91 unit_nb = *extradata++ & 0x1f;
102 unit_size =
AV_RB16(extradata);
103 total_size += unit_size + 4;
104 if (total_size > INT_MAX - padding) {
106 "Too big extradata size, corrupted stream or invalid MP4/AVCC bitstream\n");
112 "corrupted stream or invalid MP4/AVCC bitstream\n");
116 if ((err =
av_reallocp(&out, total_size + padding)) < 0)
118 memcpy(out + total_size - unit_size - 4, nalu_header, 4);
119 memcpy(out + total_size - unit_size, extradata + 2, unit_size);
120 extradata += 2 + unit_size;
122 if (!unit_nb && !sps_done++) {
123 unit_nb = *extradata++;
132 memset(out + total_size, 0, padding);
136 "Warning: SPS NALU missing or invalid. "
137 "The resulting stream may not play.\n");
141 "Warning: PPS NALU missing or invalid. "
142 "The resulting stream may not play.\n");
157 uint8_t **poutbuf,
int *poutbuf_size,
165 uint32_t cumul_size = 0;
166 const uint8_t *buf_end = buf + buf_size;
172 *poutbuf_size = buf_size;
178 if (args && strstr(args,
"private_spspps_buf"))
199 nal_size = (nal_size << 8) | buf[i];
202 unit_type = *buf & 0x1f;
204 if (nal_size > buf_end - buf || nal_size < 0)
209 else if (unit_type == 8) {
214 av_log(avctx,
AV_LOG_WARNING,
"SPS not present in the stream, nor in AVCC, stream may be unreadable\n");
230 if (!ctx->
new_idr && unit_type == 5 && (buf[1] & 0x80))
243 av_log(avctx,
AV_LOG_WARNING,
"PPS not present in the stream, nor in AVCC, stream may be unreadable\n");
245 NULL, 0, buf, nal_size)) < 0)
253 NULL, 0, buf, nal_size)) < 0)
255 if (!ctx->
new_idr && unit_type == 1) {
265 }
while (cumul_size < buf_size);
283 .
name =
"h264_mp4toannexb",
#define AV_LOG_WARNING
Something somehow does not look correct.
memory handling functions
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_WB24 unsigned int_TMPL AV_RB16
static int h264_extradata_to_annexb(H264BSFContext *ctx, AVCodecContext *avctx, const int padding)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
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, uint8_t clip)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
static const uint8_t offset[127][2]
Libavcodec external API header.
main external API structure.
static void h264_mp4toannexb_filter_close(AVBitStreamFilterContext *bsfc)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static int alloc_and_copy(uint8_t **poutbuf, int *poutbuf_size, const uint8_t *sps_pps, uint32_t sps_pps_size, const uint8_t *in, uint32_t in_size)
AVBitStreamFilter ff_h264_mp4toannexb_bsf