测试发现,通过SkeyePlayer拉取网络摄像机的流, 其音频可能是G711,G726等,而写MP4或者转推RTMP等都不支持这些音频格式,那么我们就需要将其音频转码成AAC,可以使用libSkeyeAACEncoder库进行转码,然后写MP4或者推送;然而,在实际应用中,我们发现转码过程其实还是比较耗时的,它甚至会导致解码线程来不及从而使直播延时增大,所以,我们采用队列缓存+线程的方式来优化录像和抓图。
实现如下:
- 录像优化
1> 开启录像
if (pThread->manuRecording == 0x01 && NULL==pThread->m_pMP4Writer && frameinfo.type==Skeye_SDK_VIDEO_FRAME_I)//开启录制
{
//EnterCriticalSection(&pThread->critRecQueue);
if (!pThread->m_pMP4Writer)
{
pThread->m_pMP4Writer = new SkeyeMP4Writer();
}
unsigned int timestamp = (unsigned int)time(NULL);
time_t tt = timestamp;
struct tm *_time = localtime(&tt);
char szTime[64] = {0,};
strftime(szTime, 32, "%Y%m%d%H%M