场景
私有协议文件读取H265码流,解码失败,提示如下:
[hevc @ 000001bdf5976f00] PPS id out of range: 0B sq= 0B f=0/0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
[hevc @ 000001bdf5976f00] PPS id out of range: 0B sq= 0B f=0/0
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
[hevc @ 000001bdf5976f00] PPS id out of range: 0B sq= 0B f=0/0
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 2 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0B sq= 0B f=0/0
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 1 times
[hevc @ 000001bdf5976f00] Error parsing NAL unit #1.
[hevc @ 000001bdf5976f00] Truncating likely oversized SPS (4520 > 4096)
[hevc @ 000001bdf5976f00] PPS id out of range: 0
Last message repeated 5 times
[hevc @ 000001bdf5976f00] PPS id out of range: 0B sq= 0B f=0/0
[hevc @ 000001bdf5988d40] The cu_qp_delta 30 is outside the valid range [-26, 25].
[hevc @ 000001bdfd561b40] The cu_qp_delta 26 is outside the valid range [-26, 25].
[hevc @ 000001bdf5988680] Could not find ref with POC 12 0B f=0/0
[hevc @ 000001bdf5988d40] The cu_qp_delta 43 is outside the valid range [-26, 25].
[hevc @ 000001bdfd5f1040] Could not find ref with POC 16 0B f=0/0
[hevc @ 000001bdfd4b0b40] Could not find ref with POC 18 0B f=0/0
[hevc @ 000001bdfd5f1040] The cu_qp_delta 52 is outside the valid range [-26, 25].
[hevc @ 000001bdfd4b0b40] CABAC_MAX_BIN : 7 68KB sq= 0B f=0/0
[hevc @ 000001bdfd4b0b40] The cu_qp_delta -1094995529 is outside the valid range [-26, 25].
[hevc @ 000001bdf5988680] Could not find ref with POC 4 0B f=0/0
[hevc @ 000001bdf5988d40] CABAC_MAX_BIN : 7 73KB sq= 0B f=0/0
[hevc @ 000001bdf5988d40] The cu_qp_delta 1094995529 is outside the valid range [-26, 25].
[hevc @ 000001bdfd5f1040] The cu_qp_delta -35 is outside the valid range [-26, 25].
[hevc @ 000001bdfd4b0b40] Could not find ref with POC 8
[hevc @ 000001bdfd561b40] The cu_qp_delta 27 is outside the valid range [-26, 25].
[hevc @ 000001bdf5988680] The cu_qp_delta 59 is outside the valid range [-26, 25].
[hevc @ 000001bdfd5f1040] The cu_qp_delta -35 is outside the valid range [-26, 25].
[hevc @ 000001bdfd4b0b40] Could not find ref with POC 14 0B f=0/0
[hevc @ 000001bdfd561b40] The cu_qp_delta 49 is outside the valid range [-26, 25].
[hevc @ 000001bdf5988680] CABAC_MAX_BIN : 7
[hevc @ 000001bdf5988680] The cu_qp_delta -1094995529 is outside the valid range [-26, 25].
[hevc @ 000001bdf5988d40] Could not find ref with POC 18 0B f=0/0
[hevc @ 000001bdf5988d40] CABAC_MAX_BIN : 7 64KB sq= 0B f=0/0
[hevc @ 000001bdf5988d40] The cu_qp_delta 1094995529 is outside the valid range [-26, 25].
[hevc @ 000001bdfd5f1040] Could not find ref with POC 20
[NULL @ 000001bdf5976f00] PPS id out of range: 0B sq= 0B f=0/0
[hevc @ 000001bdfd561b40] CABAC_MAX_BIN : 7
[hevc @ 000001bdfd561b40] The cu_qp_delta -1094995529 is outside the valid range [-26, 25].
[NULL @ 000001bdf5976f00] PPS id out of range: 0
[hevc @ 000001bdf5988d40] Truncating likely oversized SPS (4520 > 4096)
测试提取代码
std::uint8_t CheckSumFunc(std::uint8_t *pszData, int nDataLen)
{
std::uint8_t cSum = 0x00;
int i;
for (i = 0; i < nDataLen; i++)
{
cSum += pszData[i];
}
return cSum;
}
void ReadPrivateVideoDataAndParseToH265File()
{
FILE* fpInputeHandle = NULL;
errno_t err = fopen_s(&fpInputeHandle, "F:/ffmpeg/study/ReceivedTofile-UDP-2023_6_5_8-59-13.265", "rb+");
if (!fpInputeHandle)
{
std::cout << "打开文件读取模式失败,请检查文件所在的位置" << std::endl;
return;
}
FILE *fpOutputHandle = fopen("F:/ffmpeg/study/raw.H265", "wb");
if (!fpOutputHandle)
{
std::cout << "打开文件写入失败,请检查是否有权限创建文件" << std::endl;
return;
}
int nHasReadFileLen = 0;
int nEachPacketSize = 244;
std::uint8_t *pszPrivateDataBuffer = (std::uint8_t *)calloc(nEachPacketSize, sizeof(std::uint8_t));
bool bFirst = true;
std::int32_t nLastPacketSequence = 0;
while (1)
{
memset(pszPrivateDataBuffer, 0x00, nEachPacketSize);
if (fread(pszPrivateDataBuffer, 1, nEachPacketSize, fpInputeHandle) != nEachPacketSize)
{
std::cout << "剩余文件长度不足以读取244字节数据,退出循环" << std::endl;
break;
}
nHasReadFileLen += nEachPacketSize;
if ((0x4E != pszPrivateDataBuffer[0]) && (0x4E != pszPrivateDataBuffer[1]))
{
std::cout << "当前的包不符合读取标准,开头不是4E 4E开头,扔掉" << std::endl;
continue;
}
if (0xEA != pszPrivateDataBuffer[8])
{
std::cout << "当前的包不是一个视频数据包,扔掉" << std::endl;
continue;
}
//去掉前面4个字节,然后剩下的数据进行累加,和最后一位校验和进行对比,看下是否数据传输有异常
std::uint8_t cCheckSum = CheckSumFunc(&pszPrivateDataBuffer[4], 243 - 4);
if (cCheckSum != pszPrivateDataBuffer[243])
{
std::cout << "校验不准确,扔掉" << std::endl;
continue;
}
//计算当前包的序号
std::int32_t nCurrentPacketSequence = (pszPrivateDataBuffer[5] << 8) + pszPrivateDataBuffer[6];
//std::cout << std::setbase(16) << (int)pszPrivateDataBuffer[5] << " " << (int)pszPrivateDataBuffer[6] << std::endl;
if (0 == nLastPacketSequence)
{
nLastPacketSequence = nCurrentPacketSequence;
}
else
{
if (1 != (nCurrentPacketSequence - nLastPacketSequence))
{
std::cout << "包序号不连续,出现丢包情况,丢包数量:" << nCurrentPacketSequence - nLastPacketSequence << std::endl;
}
nLastPacketSequence = nCurrentPacketSequence;
}
if (bFirst)
{
if ((0x00 == pszPrivateDataBuffer[9]) && (0x00 == pszPrivateDataBuffer[10])&& (0x00 == pszPrivateDataBuffer[11]) && (0x01 == pszPrivateDataBuffer[12]) && (0x40 == pszPrivateDataBuffer[13]))
{
bFirst = false;
}
else
{
//continue;
}
}
//写文件输出
fwrite(&pszPrivateDataBuffer[9], 1, 234, fpOutputHandle);
}
free(pszPrivateDataBuffer);
fclose(fpInputeHandle);
fclose(fpOutputHandle);
}
结果
根据序号发现存在丢包情况,导致解码失败