Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP4ReadSample #52

Open
1121518wo opened this issue Aug 30, 2024 · 0 comments
Open

MP4ReadSample #52

1121518wo opened this issue Aug 30, 2024 · 0 comments

Comments

@1121518wo
Copy link

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;  
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant