35 const uint8_t *sps_pps, uint32_t sps_pps_size,
38 uint32_t
offset = *poutbuf_size;
39 uint8_t nal_header_size = offset ? 3 : 4;
42 *poutbuf_size += sps_pps_size + in_size + nal_header_size;
49 memcpy(*poutbuf + offset, sps_pps, sps_pps_size);
50 memcpy(*poutbuf + sps_pps_size + nal_header_size + offset, in, in_size);
52 AV_WB32(*poutbuf + sps_pps_size, 1);
54 (*poutbuf + offset + sps_pps_size)[0] =
55 (*poutbuf + offset + sps_pps_size)[1] = 0;
56 (*poutbuf + offset + sps_pps_size)[2] = 1;
65 uint64_t total_size = 0;
67 sps_seen = 0, pps_seen = 0;
69 static const uint8_t nalu_header[4] = { 0, 0, 0, 1 };
70 int length_size = (*extradata++ & 0x3) + 1;
73 unit_nb = *extradata++ & 0x1f;
84 total_size += unit_size + 4;
85 if (total_size > INT_MAX - padding) {
87 "Too big extradata size, corrupted stream or invalid MP4/AVCC bitstream\n");
93 "corrupted stream or invalid MP4/AVCC bitstream\n");
97 if ((err =
av_reallocp(&out, total_size + padding)) < 0)
99 memcpy(out + total_size - unit_size - 4, nalu_header, 4);
100 memcpy(out + total_size - unit_size, extradata + 2, unit_size);
101 extradata += 2 + unit_size;
103 if (!unit_nb && !sps_done++) {
104 unit_nb = *extradata++;
115 "Warning: SPS NALU missing or invalid. "
116 "The resulting stream may not play.\n");
120 "Warning: PPS NALU missing or invalid. "
121 "The resulting stream may not play.\n");
132 uint8_t **poutbuf,
int *poutbuf_size,
140 uint32_t cumul_size = 0;
141 const uint8_t *buf_end = buf + buf_size;
147 *poutbuf_size = buf_size;
169 nal_size = (nal_size << 8) | buf[i];
172 unit_type = *buf & 0x1f;
174 if (buf + nal_size > buf_end || nal_size < 0)
178 if (ctx->
first_idr && (unit_type == 5 || unit_type == 7 || unit_type == 8)) {
186 NULL, 0, buf, nal_size)) < 0)
194 }
while (cumul_size < buf_size);
205 .
name =
"h264_mp4toannexb",