[FFmpeg-cvslog] alacenc: calculate a new max frame size for the final small frame
Justin Ruggles
git at videolan.org
Sun Feb 12 01:34:07 CET 2012
ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Thu Feb 2 16:03:41 2012 -0500| [302daf580027c7151668395ff3ec706c92d2ccc6] | committer: Justin Ruggles
alacenc: calculate a new max frame size for the final small frame
Gives a better estimate of buffer requirements and a better decision of
whether or not to use verbatim mode.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=302daf580027c7151668395ff3ec706c92d2ccc6
---
libavcodec/alacenc.c | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c
index 9e632ae..bd8ab35 100644
--- a/libavcodec/alacenc.c
+++ b/libavcodec/alacenc.c
@@ -377,6 +377,11 @@ static void write_compressed_frame(AlacEncodeContext *s)
}
}
+static av_always_inline int get_max_frame_size(int frame_size, int ch, int bps)
+{
+ return FFALIGN(55 + bps * ch * frame_size + 3, 8) / 8;
+}
+
static av_cold int alac_encode_close(AVCodecContext *avctx)
{
AlacEncodeContext *s = avctx->priv_data;
@@ -420,8 +425,9 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
s->rc.k_modifier = 14;
s->rc.rice_modifier = 4;
- s->max_coded_frame_size = 8 + (avctx->frame_size * avctx->channels *
- DEFAULT_SAMPLE_SIZE >> 3);
+ s->max_coded_frame_size = get_max_frame_size(avctx->frame_size,
+ avctx->channels,
+ DEFAULT_SAMPLE_SIZE);
// FIXME: consider wasted_bytes
s->write_sample_size = DEFAULT_SAMPLE_SIZE + avctx->channels - 1;
@@ -511,8 +517,15 @@ static int alac_encode_frame(AVCodecContext *avctx, uint8_t *frame,
AlacEncodeContext *s = avctx->priv_data;
PutBitContext *pb = &s->pbctx;
int i, out_bytes, verbatim_flag = 0;
+ int max_frame_size;
+
+ if (avctx->frame_size < DEFAULT_FRAME_SIZE)
+ max_frame_size = get_max_frame_size(avctx->frame_size, avctx->channels,
+ DEFAULT_SAMPLE_SIZE);
+ else
+ max_frame_size = s->max_coded_frame_size;
- if (buf_size < 2 * s->max_coded_frame_size) {
+ if (buf_size < 2 * max_frame_size) {
av_log(avctx, AV_LOG_ERROR, "buffer size is too small\n");
return -1;
}
@@ -537,7 +550,7 @@ verbatim:
flush_put_bits(pb);
out_bytes = put_bits_count(pb) >> 3;
- if (out_bytes > s->max_coded_frame_size) {
+ if (out_bytes > max_frame_size) {
/* frame too large. use verbatim mode */
if (verbatim_flag || s->compression_level == 0) {
/* still too large. must be an error. */
More information about the ffmpeg-cvslog
mailing list