mp4v2
mp4v2 copied to clipboard
MP4ReadSample
When using the MP4ReadSample interface to read data from an MP4 video file not recorded with the MP4v2 interface, it is found that the stream data cannot be decoded successfully. Analyzing the stream structure reveals various issues, such as the inability to locate key frames and encountering Audit Units (AUD) continuously.
for example:
while (MP4ReadSample(pReplay->mp4File, pReplay->videoTrackId, pReplay->iVSampleInx++, &pSampleData, &nSampleSize, &nStartTime, &nDuration, &nOffset, &bIsKeyFrame)) {
// if ((pReplay->video_codeType == 2 && ((pSampleData[4] & 0x7E) >> 1) == 39) || // H.265 SEI
// (pReplay->video_codeType == 1 && (pSampleData[4] & 0x1F) == 6)) // H.264 SEI
// {
// MP4Free(pSampleData);
// pSampleData = NULL;
// continue;
// }
//printf("bIsKeyFrame=================%d\n",bIsKeyFrame);
uint8_t nal_unit_type = pSampleData[4] & 0x1F;
//printf("Sample ID: %u, NAL Unit Type: %u, Sample Size: %u\n", pReplay->iVSampleInx - 1, nal_unit_type, nSampleSize);
if (nal_unit_type == 6 || nal_unit_type == 9) {
MP4Free(pSampleData);
pSampleData = NULL;
continue;
}
if (bIsKeyFrame && pReplay->pVencBuf)
{
if (pReplay->video_codeType == 2)
{
memcpy(pReplay->pVencBuf + nFrameSize, pReplay->ucVpsBuf, pReplay->nVpsLen);
nFrameSize += pReplay->nVpsLen;
}
memcpy(pReplay->pVencBuf + nFrameSize, pReplay->ucSpsBuf, pReplay->nSpsLen);
nFrameSize += pReplay->nSpsLen;
memcpy(pReplay->pVencBuf + nFrameSize, pReplay->ucPpsBuf, pReplay->nPpsLen);
nFrameSize += pReplay->nPpsLen;
}
pSampleData[0] = 0;
pSampleData[1] = 0;
pSampleData[2] = 0;
pSampleData[3] = 0x01;
if (pReplay->pVencBuf)
{
memcpy(pReplay->pVencBuf + nFrameSize, pSampleData, nSampleSize);
nFrameSize += nSampleSize;
nRet = nFrameSize;
}
MP4Free(pSampleData);
pSampleData = NULL;
break;
}