39 const uint8_t *sps_pps, uint32_t sps_pps_size,
42 uint32_t
offset = *poutbuf_size;
43 uint8_t nal_header_size = offset ? 3 : 4;
46 *poutbuf_size += sps_pps_size + in_size + nal_header_size;
53 memcpy(*poutbuf + offset, sps_pps, sps_pps_size);
54 memcpy(*poutbuf + sps_pps_size + nal_header_size + offset, in, in_size);
56 AV_WB32(*poutbuf + sps_pps_size, 1);
58 (*poutbuf + offset + sps_pps_size)[0] =
59 (*poutbuf + offset + sps_pps_size)[1] = 0;
60 (*poutbuf + offset + sps_pps_size)[2] = 1;
69 uint64_t total_size = 0;
71 sps_seen = 0, pps_seen = 0;
73 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
74 int length_size = (*extradata++ & 0x3) + 1;
79 unit_nb = *extradata++ & 0x1f;
91 total_size += unit_size + 4;
92 if (total_size > INT_MAX - padding) {
94 "Too big extradata size, corrupted stream or invalid MP4/AVCC bitstream\n");
100 "corrupted stream or invalid MP4/AVCC bitstream\n");
104 if ((err =
av_reallocp(&out, total_size + padding)) < 0)
106 memcpy(out + total_size - unit_size - 4, nalu_header, 4);
107 memcpy(out + total_size - unit_size, extradata + 2, unit_size);
108 extradata += 2 + unit_size;
110 if (!unit_nb && !sps_done++) {
111 unit_nb = *extradata++;
120 memset(out + total_size, 0, padding);
124 "Warning: SPS NALU missing or invalid. "
125 "The resulting stream may not play.\n");
129 "Warning: PPS NALU missing or invalid. "
130 "The resulting stream may not play.\n");
141 uint8_t **poutbuf,
int *poutbuf_size,
149 uint32_t cumul_size = 0;
150 const uint8_t *buf_end = buf + buf_size;
156 *poutbuf_size = buf_size;
180 nal_size = (nal_size << 8) | buf[i];
183 unit_type = *buf & 0x1f;
185 if (buf + nal_size > buf_end || nal_size < 0)
190 else if (unit_type == 8) {
195 av_log(avctx,
AV_LOG_WARNING,
"SPS not present in the stream, nor in AVCC, stream may be unreadable\n");
211 if (!ctx->
new_idr && unit_type == 5 && (buf[1] & 0x80))
224 av_log(avctx,
AV_LOG_WARNING,
"PPS not present in the stream, nor in AVCC, stream may be unreadable\n");
226 NULL, 0, buf, nal_size)) < 0)
234 NULL, 0, buf, nal_size)) < 0)
236 if (!ctx->
new_idr && unit_type == 1) {
246 }
while (cumul_size < buf_size);
257 .
name =
"h264_mp4toannexb",