From 7ee0ec4613c8af58bb9d0aaf5fd02cef2d0e518c Mon Sep 17 00:00:00 2001
From: jstebbins <jstebbins.hb@gmail.com>
Date: Sat, 16 Mar 2013 16:59:35 +0000
Subject: [PATCH] libhb: fix fdk-aac mono encoding

A minimum output buffer size of 8KB is needed by libav


git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5329 b64f7644-9d1e-0410-96f1-a4d463321fa5
---
 libhb/encavcodecaudio.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libhb/encavcodecaudio.c b/libhb/encavcodecaudio.c
index 2c4471bab..3633fed9e 100644
--- a/libhb/encavcodecaudio.c
+++ b/libhb/encavcodecaudio.c
@@ -189,8 +189,10 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job_t *job)
     pv->samples_per_frame = context->frame_size;
     pv->input_samples     = context->frame_size * context->channels;
     pv->input_buf         = malloc(pv->input_samples * sizeof(float));
-    pv->max_output_bytes  = (pv->input_samples *
-                             av_get_bytes_per_sample(context->sample_fmt));
+    // Some encoders in libav (e.g. fdk-aac) fail if the output buffer
+    // size is not some minumum value.  8K seems to be enough :(
+    pv->max_output_bytes  = MAX(8192, (pv->input_samples *
+                             av_get_bytes_per_sample(context->sample_fmt)));
 
     // sample_fmt conversion
     if (context->sample_fmt != AV_SAMPLE_FMT_FLT)
-- 
2.40.0