Skip to content

Commit

Permalink
Fix audio corruption when encoding using built-in AAC encoder.
Browse files Browse the repository at this point in the history
Was only processing half-the audio samples
  • Loading branch information
jyavenard committed Jun 19, 2013
1 parent 004dcf2 commit ef80f72
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mythtv/libs/libmythtv/avformatwriter.cpp
Expand Up @@ -320,9 +320,10 @@ int AVFormatWriter::WriteAudioFrame(unsigned char *buf, int fnum, long long &tim
int got_packet = 0;
int ret = 0;
int samples_per_avframe = m_audioFrameSize * m_audioChannels;
int sampleSize = AudioOutputSettings::SampleSize(FORMAT_S16);
int sampleSizeIn = AudioOutputSettings::SampleSize(FORMAT_S16);
AudioFormat format =
AudioOutputSettings::AVSampleFormatToFormat(m_audioStream->codec->sample_fmt);
int sampleSizeOut = AudioOutputSettings::SampleSize(format);

AVPacket pkt;
av_init_packet(&pkt);
Expand All @@ -332,7 +333,7 @@ int AVFormatWriter::WriteAudioFrame(unsigned char *buf, int fnum, long long &tim
if (av_get_packed_sample_fmt(m_audioStream->codec->sample_fmt) == AV_SAMPLE_FMT_FLT)
{
AudioOutputUtil::toFloat(FORMAT_S16, (void *)m_audioInBuf, (void *)buf,
samples_per_avframe * sampleSize);
samples_per_avframe * sampleSizeIn);
buf = m_audioInBuf;
}
if (av_sample_fmt_is_planar(m_audioStream->codec->sample_fmt))
Expand All @@ -341,12 +342,12 @@ int AVFormatWriter::WriteAudioFrame(unsigned char *buf, int fnum, long long &tim
m_audioChannels,
m_audioInPBuf,
buf,
samples_per_avframe * sampleSize);
samples_per_avframe * sampleSizeOut);

// init AVFrame for planar data (input is interleaved)
for (int j = 0, jj = 0; j < m_audioChannels; j++, jj += m_audioFrameSize)
{
m_audPicture->data[j] = (uint8_t*)(m_audioInPBuf + jj * sampleSize);
m_audPicture->data[j] = (uint8_t*)(m_audioInPBuf + jj * sampleSizeOut);
}
}
else
Expand Down

0 comments on commit ef80f72

Please sign in to comment.