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
This commit is contained in:
parent
79d46cbea6
commit
79c85beba8
9
ffmpeg.c
9
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;
|
||||
|
Loading…
Reference in New Issue
Block a user