diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 0260ba6f67..47679eca1b 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -357,7 +357,8 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx, if (!buf) return AVERROR(ENOMEM); - av_init_packet(pkt); + av_buffer_unref(&pkt->buf); + pkt->buf = buf; pkt->data = frag->data; pkt->size = frag->data_size; diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 967dcd1468..5260a39c63 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -297,7 +297,8 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, /** * Write the bitstream of a fragment to the extradata in codec parameters. * - * This replaces any existing extradata in the structure. + * Modifies context and fragment as ff_cbs_write_fragment_data does and + * replaces any existing extradata in the structure. */ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, @@ -305,6 +306,13 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, /** * Write the bitstream of a fragment to a packet. + * + * Modifies context and fragment as ff_cbs_write_fragment_data does. + * + * On success, the packet's buf is unreferenced and its buf, data and + * size fields are set to the corresponding values from the newly updated + * fragment; other fields are not touched. On failure, the packet is not + * touched at all. */ int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt,