}
}
- // Only insert the SEI in access units containing SPSs.
- if (has_sps && ctx->sei_user_data) {
+ // Insert the SEI in access units containing SPSs, and also
+ // unconditionally in the first access unit we ever see.
+ if (ctx->sei_user_data && (has_sps || !ctx->sei_first_au)) {
- H264RawSEI *sei;
- H264RawSEIPayload *payload;
- H264RawSEIUserDataUnregistered *udu;
- int sei_pos, sei_new;
+ H264RawSEIPayload payload = {
+ .payload_type = H264_SEI_TYPE_USER_DATA_UNREGISTERED,
+ };
+ H264RawSEIUserDataUnregistered *udu =
+ &payload.payload.user_data_unregistered;
- for (i = 0; i < au->nb_units; i++) {
- if (au->units[i].type == H264_NAL_SEI ||
- au->units[i].type == H264_NAL_SLICE ||
- au->units[i].type == H264_NAL_IDR_SLICE)
- break;
- }
- sei_pos = i;
-
- if (sei_pos < au->nb_units &&
- au->units[sei_pos].type == H264_NAL_SEI) {
- sei_new = 0;
- sei = au->units[sei_pos].content;
- } else {
- sei_new = 1;
- sei = &ctx->sei_nal;
- memset(sei, 0, sizeof(*sei));
-
- sei->nal_unit_header.nal_unit_type = H264_NAL_SEI;
-
- err = ff_cbs_insert_unit_content(ctx->cbc, au, sei_pos,
- H264_NAL_SEI, sei, NULL);
- if (err < 0) {
- av_log(bsf, AV_LOG_ERROR, "Failed to insert SEI.\n");
- goto fail;
- }
- }
-
- payload = &sei->payload[sei->payload_count];
-
- payload->payload_type = H264_SEI_TYPE_USER_DATA_UNREGISTERED;
- udu = &payload->payload.user_data_unregistered;
-
+ ctx->sei_first_au = 1;
+
for (i = j = 0; j < 32 && ctx->sei_user_data[i]; i++) {
int c, v;
c = ctx->sei_user_data[i];