From 79c85beba860a1e2e286d2630c862ad7d1b278a6 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 10 Jun 2010 19:40:56 +0000 Subject: Allocate enough memory for audio_buf to fit a full output frame. Also, use audio_buf when encoding the final frame. Fixes Issue 1921. Originally committed as revision 23570 to svn://svn.ffmpeg.org/ffmpeg/trunk --- ffmpeg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ffmpeg.c') diff --git a/ffmpeg.c b/ffmpeg.c index cb691b1844..9828628d2b 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -813,6 +813,7 @@ need_realloc: audio_buf_size= (allocated_for_size + isize*dec->channels - 1) / (isize*dec->channels); audio_buf_size= (audio_buf_size*enc->sample_rate + dec->sample_rate) / dec->sample_rate; audio_buf_size= audio_buf_size*2 + 10000; //safety factors for the deprecated resampling API + audio_buf_size= FFMAX(audio_buf_size, enc->frame_size); audio_buf_size*= osize*enc->channels; audio_out_size= FFMAX(audio_buf_size, enc->frame_size * osize * enc->channels); @@ -1832,17 +1833,17 @@ static int output_packet(AVInputStream *ist, int ist_index, int osize = av_get_bits_per_sample_format(enc->sample_fmt) >> 3; int fs_tmp = enc->frame_size; - av_fifo_generic_read(ost->fifo, samples, fifo_bytes, NULL); + av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL); if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) { enc->frame_size = fifo_bytes / (osize * enc->channels); } else { /* pad */ int frame_bytes = enc->frame_size*osize*enc->channels; - if (samples_size < frame_bytes) + if (allocated_audio_buf_size < frame_bytes) av_exit(1); - memset((uint8_t*)samples+fifo_bytes, 0, frame_bytes - fifo_bytes); + memset((uint8_t*)audio_buf+fifo_bytes, 0, frame_bytes - fifo_bytes); } - ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, samples); + ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf); pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den, ost->st->time_base.num, enc->sample_rate); enc->frame_size = fs_tmp; -- cgit v1.2.3