audio seems correct, but need more elegant way, and still bad interleaving

This commit is contained in:
sirius 2019-10-30 00:01:25 +08:00
parent 49ff1a5827
commit a7c2a65ebc
2 changed files with 15 additions and 5 deletions

View file

@ -237,6 +237,11 @@ void CVideo::nextVideoFrame()
void CVideo::nextAudioFrame(short* pData) void CVideo::nextAudioFrame(short* pData)
{ {
if (m_Recording && m_HasAudio) if (m_Recording && m_HasAudio)
{
m_aseq += 1;
for(int i=0; i < 1024; i++)
m_aBuffer[i+(m_aseq%2)*1024] = pData[i];
if(m_aseq % 2)
{ {
m_ProcessingAudioFrame = true; m_ProcessingAudioFrame = true;
m_AudioStream.frame->pts = m_AudioStream.enc->frame_number; m_AudioStream.frame->pts = m_AudioStream.enc->frame_number;
@ -262,14 +267,14 @@ void CVideo::nextAudioFrame(short* pData)
// ); // );
// dbg_msg("video_recorder", "dst_nb_samples: %d", dst_nb_samples); // dbg_msg("video_recorder", "dst_nb_samples: %d", dst_nb_samples);
fwrite(pData, sizeof(short), 1024, m_dbgfile); //fwrite(pData, sizeof(short), 1024, m_dbgfile);
av_samples_fill_arrays( av_samples_fill_arrays(
(uint8_t**)m_AudioStream.tmp_frame->data, (uint8_t**)m_AudioStream.tmp_frame->data,
0, // pointer to linesize (int*) 0, // pointer to linesize (int*)
(const uint8_t*)pData, (const uint8_t*)m_aBuffer,
2, // channels 2, // channels
m_AudioStream.tmp_frame->nb_samples, m_AudioStream.tmp_frame->nb_samples * 2,
AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16,
0 // align 0 // align
); );
@ -283,9 +288,9 @@ void CVideo::nextAudioFrame(short* pData)
ret = swr_convert( ret = swr_convert(
m_AudioStream.swr_ctx, m_AudioStream.swr_ctx,
m_AudioStream.frame->data, m_AudioStream.frame->data,
m_AudioStream.frame->nb_samples, m_AudioStream.frame->nb_samples * 2,
(const uint8_t **)m_AudioStream.tmp_frame->data, (const uint8_t **)m_AudioStream.tmp_frame->data,
m_AudioStream.tmp_frame->nb_samples m_AudioStream.tmp_frame->nb_samples * 2
); );
if (ret < 0) if (ret < 0)
@ -304,6 +309,7 @@ void CVideo::nextAudioFrame(short* pData)
m_ProcessingAudioFrame = false; m_ProcessingAudioFrame = false;
} }
}
} }
void CVideo::fill_audio_frame() void CVideo::fill_audio_frame()
@ -510,6 +516,8 @@ void CVideo::open_audio()
dbg_msg("video_recorder", "Failed to initialize the resampling context"); dbg_msg("video_recorder", "Failed to initialize the resampling context");
exit(1); exit(1);
} }
m_aseq = 0;
} }

View file

@ -94,6 +94,8 @@ private:
int m_Height; int m_Height;
char m_Name[256]; char m_Name[256];
FILE *m_dbgfile; FILE *m_dbgfile;
int m_aseq;
short m_aBuffer[2048];
int m_FPS; int m_FPS;