36 const uint8_t *sps_pps, uint32_t sps_pps_size,
39 uint32_t
offset = *poutbuf_size;
40 uint8_t nal_header_size = offset ? 3 : 4;
43 *poutbuf_size += sps_pps_size + in_size + nal_header_size;
50 memcpy(*poutbuf + offset, sps_pps, sps_pps_size);
51 memcpy(*poutbuf + sps_pps_size + nal_header_size + offset, in, in_size);
53 AV_WB32(*poutbuf + sps_pps_size, 1);
55 (*poutbuf + offset + sps_pps_size)[0] =
56 (*poutbuf + offset + sps_pps_size)[1] = 0;
57 (*poutbuf + offset + sps_pps_size)[2] = 1;
66 uint64_t total_size = 0;
68 sps_seen = 0, pps_seen = 0;
70 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
71 int length_size = (*extradata++ & 0x3) + 1;
74 unit_nb = *extradata++ & 0x1f;
85 total_size += unit_size + 4;
86 if (total_size > INT_MAX - padding) {
88 "Too big extradata size, corrupted stream or invalid MP4/AVCC bitstream\n");
94 "corrupted stream or invalid MP4/AVCC bitstream\n");
98 if ((err =
av_reallocp(&out, total_size + padding)) < 0)
100 memcpy(out + total_size - unit_size - 4, nalu_header, 4);
101 memcpy(out + total_size - unit_size, extradata + 2, unit_size);
102 extradata += 2 + unit_size;
104 if (!unit_nb && !sps_done++) {
105 unit_nb = *extradata++;
116 "Warning: SPS NALU missing or invalid. "
117 "The resulting stream may not play.\n");
121 "Warning: PPS NALU missing or invalid. "
122 "The resulting stream may not play.\n");
133 uint8_t **poutbuf,
int *poutbuf_size,
141 uint32_t cumul_size = 0;
142 const uint8_t *buf_end = buf + buf_size;
148 *poutbuf_size = buf_size;
171 nal_size = (nal_size << 8) | buf[i];
174 unit_type = *buf & 0x1f;
176 if (buf + nal_size > buf_end || nal_size < 0)
179 if (unit_type == 7 || unit_type == 8)
185 if (!ctx->
new_idr && unit_type == 5 && (buf[1] & 0x80))
197 NULL, 0, buf, nal_size)) < 0)
199 if (!ctx->
new_idr && unit_type == 1) {
207 }
while (cumul_size < buf_size);
218 .
name =
"h264_mp4toannexb",