mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/extract_extradata: don't allocate more space than needed when removing NALUs in h264/hevc
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
43205df645
commit
2536bd8632
|
@ -62,7 +62,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
|
||||||
ExtractExtradataContext *s = ctx->priv_data;
|
ExtractExtradataContext *s = ctx->priv_data;
|
||||||
|
|
||||||
H2645Packet h2645_pkt = { 0 };
|
H2645Packet h2645_pkt = { 0 };
|
||||||
int extradata_size = 0;
|
int extradata_size = 0, filtered_size = 0;
|
||||||
const int *extradata_nal_types;
|
const int *extradata_nal_types;
|
||||||
int nb_extradata_nal_types;
|
int nb_extradata_nal_types;
|
||||||
int i, has_sps = 0, has_vps = 0, ret = 0;
|
int i, has_sps = 0, has_vps = 0, ret = 0;
|
||||||
|
@ -90,6 +90,8 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
|
||||||
} else {
|
} else {
|
||||||
if (nal->type == H264_NAL_SPS) has_sps = 1;
|
if (nal->type == H264_NAL_SPS) has_sps = 1;
|
||||||
}
|
}
|
||||||
|
} else if (s->remove) {
|
||||||
|
filtered_size += nal->raw_size + 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,11 +102,13 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
|
||||||
uint8_t *extradata, *filtered_data;
|
uint8_t *extradata, *filtered_data;
|
||||||
|
|
||||||
if (s->remove) {
|
if (s->remove) {
|
||||||
filtered_buf = av_buffer_alloc(pkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
|
filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
|
||||||
if (!filtered_buf) {
|
if (!filtered_buf) {
|
||||||
ret = AVERROR(ENOMEM);
|
ret = AVERROR(ENOMEM);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
||||||
|
|
||||||
filtered_data = filtered_buf->data;
|
filtered_data = filtered_buf->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,9 +141,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
|
||||||
av_buffer_unref(&pkt->buf);
|
av_buffer_unref(&pkt->buf);
|
||||||
pkt->buf = filtered_buf;
|
pkt->buf = filtered_buf;
|
||||||
pkt->data = filtered_buf->data;
|
pkt->data = filtered_buf->data;
|
||||||
pkt->size = filtered_data - filtered_buf->data;
|
pkt->size = filtered_size;
|
||||||
|
|
||||||
memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue