Get the width / height of the video from H.265 NALU from rtsp packet

172 views Asked by At

I am trying to get width / height from the received vps/sps/pps packet . i have tried parsing sps packet with following method but no luck

`void H265Codecs::extractWidthHeightFromSPS(byte* spsData, int spsSize, int& width, int& height)
{
// Ensure the SPS data starts with NAL unit header (0x00000001)
if (spsSize >= 4 && spsData[0] == 0 && spsData[1] == 0 && spsData[2] == 0 && spsData[3] == 1) {
    int nalType = (spsData[4] >> 1) & 0x3f;
    if (nalType == 32) { // SPS NAL unit
        // Extract the width and height from the SPS data

        int chromaFormatIdc = (spsData[5] >> 1) & 0x07; // Extracting 3 bits
        int picWidthInLumaSamples = ((spsData[13] & 0x03) << 8) | spsData[14];
        int picHeightInLumaSamples = ((spsData[15] & 0x0F) << 8) | spsData[16];

        if (chromaFormatIdc == 1) {
            picWidthInLumaSamples = (picWidthInLumaSamples + 1) * 2;
            picHeightInLumaSamples = (picHeightInLumaSamples + 1) * 2;
        }

        width = picWidthInLumaSamples;
        height = picHeightInLumaSamples;
    }
}

}` from the above code i am getting wrong height and width only

i am processing rtsp over tcp packets from a ip camera for recording video as h265.mp4 file** Anyway/method to get stream width-height?**

i have tried all parse sample avaliable over the internet i am using hikvision h265 support camera for testing

0

There are 0 answers