aboutsummaryrefslogtreecommitdiffstats
path: root/ffmpeg.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2010-06-10 19:40:56 +0000
committerJustin Ruggles <justin.ruggles@gmail.com>2010-06-10 19:40:56 +0000
commit79c85beba860a1e2e286d2630c862ad7d1b278a6 (patch)
treef958b742fca8ae885ca91ad20ee0c3b60851e835 /ffmpeg.c
parent79d46cbea6c30c11de8da9ca64ac293b773966e2 (diff)
downloadffmpeg-79c85beba860a1e2e286d2630c862ad7d1b278a6.tar.gz
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
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c9
1 files changed, 5 insertions, 4 deletions
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;