FFmpeg: Fix overflow and general issues with audio encoding

This commit is contained in:
Vicki Pfau 2017-04-04 02:00:10 -07:00
parent f36caedb95
commit f2ce0d11dc
2 changed files with 9 additions and 8 deletions

View File

@ -17,6 +17,7 @@ Bugfixes:
- Windows: Fix VDir.rewind
- SDL: Fix game crash check
- SDL: Fix race condition with audio thread when starting
- FFmpeg: Fix overflow and general issues with audio encoding
Misc:
- Qt: Improved HiDPI support
- Feature: Support ImageMagick 7

View File

@ -389,27 +389,27 @@ void _ffmpegPostAudioFrame(struct mAVStream* stream, int16_t left, int16_t right
encoder->audioBuffer[encoder->currentAudioSample * 2] = left;
encoder->audioBuffer[encoder->currentAudioSample * 2 + 1] = right;
++encoder->currentAudioFrame;
++encoder->currentAudioSample;
if ((encoder->currentAudioSample * 4) < encoder->audioBufferSize) {
if (encoder->currentAudioSample * 4 < encoder->audioBufferSize) {
return;
}
int channelSize = 2 * av_get_bytes_per_sample(encoder->audio->sample_fmt);
avresample_convert(encoder->resampleContext,
0, 0, 0,
avresample_convert(encoder->resampleContext, 0, 0, 0,
(uint8_t**) &encoder->audioBuffer, 0, encoder->audioBufferSize / 4);
encoder->currentAudioSample = 0;
if (avresample_available(encoder->resampleContext) < encoder->audioFrame->nb_samples) {
return;
}
#if LIBAVCODEC_VERSION_MAJOR >= 55
av_frame_make_writable(encoder->audioFrame);
#endif
avresample_read(encoder->resampleContext, encoder->audioFrame->data, encoder->postaudioBufferSize / channelSize);
int samples = avresample_read(encoder->resampleContext, encoder->audioFrame->data, encoder->postaudioBufferSize / channelSize);
encoder->audioFrame->pts = av_rescale_q(encoder->currentAudioFrame - encoder->currentAudioSample, encoder->audio->time_base, encoder->audioStream->time_base);
encoder->currentAudioSample = 0;
encoder->audioFrame->pts = av_rescale_q(encoder->currentAudioFrame, encoder->audio->time_base, encoder->audioStream->time_base);
encoder->currentAudioFrame += samples;
AVPacket packet;
av_init_packet(&packet);