+ } else if (extradd != 0) {
+ /* Move the AUD up to the beginning of the frame, where the H.264
+ * spec requires it to appear. Emit the extradata after it. */
+ PutByteContext pb;
+ const int new_pkt_size = pkt->size + 1 + extradd;
+ data = av_malloc(new_pkt_size);
+ if (!data)
+ return AVERROR(ENOMEM);
+ bytestream2_init_writer(&pb, data, new_pkt_size);
+ bytestream2_put_byte(&pb, 0x00);
+ bytestream2_put_buffer(&pb, found_aud, found_aud_end - found_aud);
+ bytestream2_put_buffer(&pb, st->codecpar->extradata, extradd);
+ bytestream2_put_buffer(&pb, pkt->data, found_aud - pkt->data);
+ bytestream2_put_buffer(&pb, found_aud_end, buf_end - found_aud_end);
+ av_assert0(new_pkt_size == bytestream2_tell_p(&pb));
+ buf = data;
+ size = new_pkt_size;