|
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c |
|
index d39173b408..1f5c4f0525 100644 |
|
--- a/libavcodec/cbs_h2645.c |
|
+++ b/libavcodec/cbs_h2645.c |
|
@@ -565,9 +565,11 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, |
|
AVBufferRef *ref; |
|
size_t size = nal->size; |
|
|
|
+ if (nal->type != H264_NAL_SLICE && nal->type != H264_NAL_IDR_SLICE) { |
|
// Remove trailing zeroes. |
|
while (size > 0 && nal->data[size - 1] == 0) |
|
--size; |
|
+ } |
|
if (size == 0) |
|
continue; |
|
|
|
@@ -858,13 +860,13 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, |
|
|
|
pos = get_bits_count(&gbc); |
|
len = unit->data_size; |
|
- if (!unit->data[len - 1]) { |
|
+ /*if (!unit->data[len - 1]) { |
|
int z; |
|
for (z = 0; z < len && !unit->data[len - z - 1]; z++); |
|
av_log(ctx->log_ctx, AV_LOG_DEBUG, "Deleted %d trailing zeroes " |
|
"from slice data.\n", z); |
|
len -= z; |
|
- } |
|
+ }*/ |
|
|
|
slice->data_size = len - pos / 8; |
|
slice->data_ref = av_buffer_ref(unit->data_ref); |
|
@@ -1465,6 +1467,7 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, |
|
dp = 0; |
|
for (i = 0; i < frag->nb_units; i++) { |
|
CodedBitstreamUnit *unit = &frag->units[i]; |
|
+ size_t size; |
|
|
|
if (unit->data_bit_padding > 0) { |
|
if (i < frag->nb_units - 1) |
|
@@ -1491,7 +1494,10 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, |
|
data[dp++] = 1; |
|
|
|
zero_run = 0; |
|
- for (sp = 0; sp < unit->data_size; sp++) { |
|
+ size = unit->data_size; |
|
+ while (size > 0 && unit->data[size - 1] == 0) |
|
+ --size; |
|
+ for (sp = 0; sp < size; sp++) { |
|
if (zero_run < 2) { |
|
if (unit->data[sp] == 0) |
|
++zero_run; |
|
@@ -1506,6 +1512,9 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, |
|
} |
|
data[dp++] = unit->data[sp]; |
|
} |
|
+ size = unit->data_size - size; |
|
+ for (sp = 0; sp < size; sp++) |
|
+ data[dp++] = 0; |
|
} |
|
|
|
av_assert0(dp <= max_size); |