Skip to content

Instantly share code, notes, and snippets.

@emcodem
Last active February 6, 2023 14:53
Show Gist options
  • Save emcodem/aec03e12b69e3ad041ddd9b9f56550ad to your computer and use it in GitHub Desktop.
Save emcodem/aec03e12b69e3ad041ddd9b9f56550ad to your computer and use it in GitHub Desktop.
$ git diff libavcodec/cbs_h2645.c
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 80e48829af..30e213a289 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -726,7 +726,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx,
case H264_NAL_PPS:
{
H264RawPPS *pps = unit->content;
-
err = cbs_h264_read_pps(ctx, &gbc, pps);
if (err < 0)
return err;
@@ -1244,7 +1243,8 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
max_size = 0;
for (i = 0; i < frag->nb_units; i++) {
// Start code + content with worst-case emulation prevention.
- max_size += 4 + frag->units[i].data_size * 3 / 2;
+ //max_size += 4 + frag->units[i].data_size * 3 / 2;
+ max_size += 4 + frag->units[i].data_size + 1000000; //emcodem: todo: calculate max_data_size correctly
}
data = av_realloc(NULL, max_size + AV_INPUT_BUFFER_PADDING_SIZE);
@@ -1273,6 +1273,7 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
data[dp++] = 1;
zero_run = 0;
+
for (sp = 0; sp < unit->data_size; sp++) {
if (zero_run < 2) {
if (unit->data[sp] == 0)
@@ -1287,8 +1288,16 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
zero_run = unit->data[sp] == 0;
}
data[dp++] = unit->data[sp];
+
}
+
+ //emcodem: example adding 1000 bytes to each and every NAL
+ //you can e.g. check unit->type here and pad sps and or pps accordingly.
+ //example: count bytes until first slice is there and if slice is there, prepend it with missing bytes until 77824 was reached.
+ //77824 is found to be start of first slice in each and every xavc file
+ dp += 1000;
}
+
av_assert0(dp <= max_size);
err = av_reallocp(&data, dp + AV_INPUT_BUFFER_PADDING_SIZE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment