@@ -166,35 +166,33 @@ static int h264_mp4toannexb_init(AVBSFContext *ctx)
return 0;
}
-static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt)
+static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *pkt)
{
H264BSFContext *s = ctx->priv_data;
- AVPacket *in;
uint8_t unit_type, new_idr, sps_seen, pps_seen;
const uint8_t *buf;
const uint8_t *buf_end;
+ AVBufferRef *out_buf = NULL;
uint8_t *out;
uint64_t out_size;
int ret;
- ret = ff_bsf_get_packet(ctx, &in);
+ ret = ff_bsf_get_packet_ref(ctx, pkt);
if (ret < 0)
return ret;
/* nothing to filter */
if (!s->extradata_parsed) {
- av_packet_move_ref(opkt, in);
- av_packet_free(&in);
return 0;
}
- buf_end = in->data + in->size;
+ buf_end = pkt->data + pkt->size;
#define LOG_ONCE(...) \
if (j) \
av_log(__VA_ARGS__)
for (int j = 0; j < 2; j++) {
- buf = in->data;
+ buf = pkt->data;
new_idr = s->new_idr;
sps_seen = s->idr_sps_seen;
pps_seen = s->idr_pps_seen;
@@ -273,28 +271,25 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt)
ret = AVERROR(ERANGE);
goto fail;
}
- ret = av_new_packet(opkt, out_size);
+ ret = ff_buffer_padded_realloc(&out_buf, out_size);
if (ret < 0)
goto fail;
- out = opkt->data;
+ out = out_buf->data;
}
}
#undef LOG_ONCE
- av_assert1(out_size == opkt->size);
+ ff_packet_replace_buffer(pkt, out_buf);
+
+ av_assert1(out_size == pkt->size);
s->new_idr = new_idr;
s->idr_sps_seen = sps_seen;
s->idr_pps_seen = pps_seen;
- ret = av_packet_copy_props(opkt, in);
- if (ret < 0)
- goto fail;
-
fail:
if (ret < 0)
- av_packet_unref(opkt);
- av_packet_free(&in);
+ av_packet_unref(pkt);
return ret;
}
This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavcodec/h264_mp4toannexb_bsf.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)