mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec/flacenc: Avoid copying packet data, allow user-supplied buffers
The FLAC encoder calculates the size in advance, so one can avoid an intermediate buffer for the packet data by using ff_get_encode_buffer() and also set AV_CODEC_CAP_DR1 at the same time. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
314c086a85
commit
5abb5c0415
@ -27,6 +27,7 @@
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "bswapdsp.h"
|
||||
#include "encode.h"
|
||||
#include "put_bits.h"
|
||||
#include "golomb.h"
|
||||
#include "internal.h"
|
||||
@ -1378,7 +1379,7 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
|
||||
}
|
||||
}
|
||||
|
||||
if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes, 0)) < 0)
|
||||
if ((ret = ff_get_encode_buffer(avctx, avpkt, frame_bytes, 0)) < 0)
|
||||
return ret;
|
||||
|
||||
out_bytes = write_frame(s, avpkt);
|
||||
@ -1396,10 +1397,11 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
|
||||
|
||||
avpkt->pts = frame->pts;
|
||||
avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
|
||||
avpkt->size = out_bytes;
|
||||
|
||||
s->next_pts = avpkt->pts + avpkt->duration;
|
||||
|
||||
av_shrink_packet(avpkt, out_bytes);
|
||||
|
||||
*got_packet_ptr = 1;
|
||||
return 0;
|
||||
}
|
||||
@ -1459,11 +1461,12 @@ const AVCodec ff_flac_encoder = {
|
||||
.long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),
|
||||
.type = AVMEDIA_TYPE_AUDIO,
|
||||
.id = AV_CODEC_ID_FLAC,
|
||||
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
|
||||
AV_CODEC_CAP_SMALL_LAST_FRAME,
|
||||
.priv_data_size = sizeof(FlacEncodeContext),
|
||||
.init = flac_encode_init,
|
||||
.encode2 = flac_encode_frame,
|
||||
.close = flac_encode_close,
|
||||
.capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY,
|
||||
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
|
||||
AV_SAMPLE_FMT_S32,
|
||||
AV_SAMPLE_FMT_NONE },
|
||||
|
Loading…
Reference in New Issue
Block a user