用Mp4V2将H264和aac合成的mp4文件,在播放时拖拽的话,会出现卡顿现象(时间轴在走动,但画面会停滞几秒)
合成MP4文件的大概过程是(以下是部分代码片段):
while(len = ReadOneNaluFromBuf(pData,size,pos,nalu))
{
if(nalu.type == 0x07 && !m_isHaveAddSPS) // sps
{
// 添加h264 track
m_videoId = MP4AddH264VideoTrack
(m_hMp4File,
m_nTimeScale,
m_nTimeScale / m_nFrameRate,
m_nWidth, // width
m_nHeight, // height
nalu.data[1], // sps[1] AVCProfileIndication
nalu.data[2], // sps[2] profile_compat
nalu.data[3], // sps[3] AVCLevelIndication
3); // 4 bytes length before each NAL unit
if (m_videoId == MP4_INVALID_TRACK_ID)
{
printf("add video track failed.\n");
return false;
}
MP4SetVideoProfileLevel(m_hMp4File, 0xf); // Simple Profile @ Level 3
MP4AddH264SequenceParameterSet(m_hMp4File,m_videoId,nalu.data,nalu.size);
m_isHaveAddSPS = true;
}
else if(nalu.type == 0x08 && !m_isHaveAddPPS) // pps
{
MP4AddH264PictureParameterSet(m_hMp4File,m_videoId,nalu.data,nalu.size);
m_isHaveAddPPS = true;
}
//未加头信息时,直接跳过该帧
if(!m_isHaveAddSPS && !m_isHaveAddPPS)
{
pData += len;
size -= len;
continue;
}
if(nalu.type == 0x07 || nalu.type == 0x08 || nalu.type == 0x06 || nalu.type == 0x05 || nalu.type == 0x01)
{
if(pSampleNaluStart==NULL){pSampleNaluStart=nalu.data-4;}
sampleNaluLenth += len;
/*if(nalu.type == 0x07)
{
//m_curVideoTimeStamp += m_nTimeScale / m_nFrameRate;
if(!m_isHaveAddSPS){m_isHaveAddSPS = true;}else {pData += len;size -= len;continue;}
}
if(nalu.type == 0x08)
{
if(!m_isHaveAddPPS){m_isHaveAddPPS = true;}else {pData += len;size -= len;continue;}
}*/
if(nalu.type == 0x05)
{
//if(!bIsHaveSEI){if(m_frontFmtNalu.size==5){m_frontFmtNalu.data[3] += 1;}WriteSampleData(m_frontFmtNalu);}
//m_curVideoTimeStamp += m_nTimeScale / m_nFrameRate;
}
else if(nalu.type == 0x01)
{
//if(!bIsHaveSEI){if(m_frontFmtNalu.size==5){m_frontFmtNalu.data[3] += 1;}WriteSampleData(m_frontFmtNalu);}
//m_curVideoTimeStamp += m_nTimeScale / m_nFrameRate;
}
else if(nalu.type == 0x06)
{
/*if(m_frontFmtNalu.data==NULL){long len = sizeof(unsigned char)*1024; m_frontFmtNalu.data=(unsigned char*)malloc(len);memset(m_frontFmtNalu.data,0,len);}
memcpy(m_frontFmtNalu.data, nalu.data,nalu.size);
m_frontFmtNalu.size = nalu.size;
bIsHaveSEI = true;*/
printf("111111");
}
//WriteSampleData(nalu);
ret = true;
}
else
{
return false;
}
pData += len;
size -= len;
}
总之,合成后的mp4文件让它自动播放的话,完全正常。但是当将时间轴拖拽到某个时间点时,会卡顿几秒后,才开始正常播放。请问各位高手,这是什么原因啊