cisco / openh264

Open Source H.264 Codec
BSD 2-Clause "Simplified" License
5.52k stars 1.78k forks source link

[h264 @ 0x7f802c2121c0] sps_id 1 out of range(ffplay), Warning:UpdateAccessUnit():::::Key frame lost(h264dec.exe) #3695

Open shitizenlism opened 10 months ago

shitizenlism commented 10 months ago

I modified wels_enc.cpp as follows: int FillSpecificParametersMerge (SEncParamExt& sParam) { / Test for temporal, spatial, SNR scalability / sParam.iUsageType = CAMERA_VIDEO_REAL_TIME; sParam.fMaxFrameRate = 30.0f; // input frame rate sParam.iPicWidth = 1920; // width of picture in samples sParam.iPicHeight = 1080; // height of picture in samples sParam.iTargetBitrate = 2000000; // target bitrate desired sParam.iMaxBitrate = UNSPECIFIED_BIT_RATE; sParam.iRCMode = RC_QUALITY_MODE; // rc mode control sParam.iTemporalLayerNum = 3; // layer number at temporal level sParam.iSpatialLayerNum = 4; // layer number at spatial level sParam.bEnableDenoise = 0; // denoise control sParam.bEnableBackgroundDetection = 1; // background detection control sParam.bEnableAdaptiveQuant = 1; // adaptive quantization control sParam.bEnableFrameSkip = 1; // frame skipping sParam.bEnableLongTermReference = 1; // long term reference control sParam.iLTRRefNum = 1; sParam.iLtrMarkPeriod = 15; sParam.uiIntraPeriod = 150; // period of Intra frame. GOP=5s sParam.eSpsPpsIdStrategy = SPS_PPS_LISTING; sParam.bPrefixNalAddingCtrl = 0; sParam.iComplexityMode = MEDIUM_COMPLEXITY; sParam.bSimulcastAVC = false; sParam.bFixRCOverShoot = true; sParam.iIdrBitrateRatio = IDR_BITRATE_RATIO * 100;

int iIndexLayer = 0; sParam.sSpatialLayers[iIndexLayer].uiProfileIdc = PRO_BASELINE; sParam.sSpatialLayers[iIndexLayer].iVideoWidth = 480; sParam.sSpatialLayers[iIndexLayer].iVideoHeight = 270; sParam.sSpatialLayers[iIndexLayer].fFrameRate = 7.5f; sParam.sSpatialLayers[iIndexLayer].iSpatialBitrate = 200000; sParam.sSpatialLayers[iIndexLayer].iMaxSpatialBitrate = UNSPECIFIED_BIT_RATE; sParam.sSpatialLayers[iIndexLayer].sSliceArgument.uiSliceMode = SM_SINGLE_SLICE;

iIndexLayer = 1; sParam.sSpatialLayers[iIndexLayer].uiProfileIdc = PRO_SCALABLE_BASELINE; sParam.sSpatialLayers[iIndexLayer].iVideoWidth = 960; sParam.sSpatialLayers[iIndexLayer].iVideoHeight = 540; sParam.sSpatialLayers[iIndexLayer].fFrameRate = 15.0f; sParam.sSpatialLayers[iIndexLayer].iSpatialBitrate = 400000; sParam.sSpatialLayers[iIndexLayer].iMaxSpatialBitrate = UNSPECIFIED_BIT_RATE; sParam.sSpatialLayers[iIndexLayer].sSliceArgument.uiSliceMode = SM_SINGLE_SLICE;

iIndexLayer = 2; sParam.sSpatialLayers[iIndexLayer].uiProfileIdc = PRO_SCALABLE_BASELINE; sParam.sSpatialLayers[iIndexLayer].iVideoWidth = 1280; sParam.sSpatialLayers[iIndexLayer].iVideoHeight = 720; sParam.sSpatialLayers[iIndexLayer].fFrameRate = 30.0f; sParam.sSpatialLayers[iIndexLayer].iSpatialBitrate = 600000; sParam.sSpatialLayers[iIndexLayer].iMaxSpatialBitrate = UNSPECIFIED_BIT_RATE; sParam.sSpatialLayers[iIndexLayer].sSliceArgument.uiSliceMode = SM_SINGLE_SLICE; sParam.sSpatialLayers[iIndexLayer].sSliceArgument.uiSliceNum = 1;

iIndexLayer = 3; sParam.sSpatialLayers[iIndexLayer].uiProfileIdc = PRO_SCALABLE_BASELINE; sParam.sSpatialLayers[iIndexLayer].iVideoWidth = 1920; sParam.sSpatialLayers[iIndexLayer].iVideoHeight = 1080; sParam.sSpatialLayers[iIndexLayer].fFrameRate = 30.0f; sParam.sSpatialLayers[iIndexLayer].iSpatialBitrate = 800000; sParam.sSpatialLayers[iIndexLayer].iMaxSpatialBitrate = UNSPECIFIED_BIT_RATE; sParam.sSpatialLayers[iIndexLayer].sSliceArgument.uiSliceMode = SM_SINGLE_SLICE; sParam.sSpatialLayers[iIndexLayer].sSliceArgument.uiSliceNum = 1;

return 0; }

      if (sSvcParam.iSpatialLayerNum == 1 || fs.bEnableMultiBsFile == false)
        fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs[0]); // write pure bit stream into file
      else { //multi bs file write
        unsigned char five_bits = pLayerBsInfo->pBsBuf[4] & 0x1f;
        if (pLayerBsInfo->uiSpatialId == 0) {
          // unsigned char five_bits = pLayerBsInfo->pBsBuf[4] & 0x1f;
          if ((five_bits == 0x07) || (five_bits == 0x08)) { //sps or pps
            for (int i = 0; i < sSvcParam.iSpatialLayerNum; ++i) {
              fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs[i]);
            }
          } else {
            fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs[0]);
          }

          fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs2[0]); //0+1
          fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs2[1]); //0+1+2
          fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs2[2]); //0+1+2+3
        } else {
          fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs[pLayerBsInfo->uiSpatialId]);
          {
            if (pLayerBsInfo->uiSpatialId == 1) {
              fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs2[0]);
              fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs2[1]);
              fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs2[2]);
            } else if (pLayerBsInfo->uiSpatialId == 2) {
              fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs2[1]);
              fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs2[2]);
            } else {
              fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs2[2]);
            }
          }
        }
      }

And test result shows as below. $ ./svcEncodeYuv -sw 1920 -sh 1080 -frms 600 -org ./res/mixkit-camels_1920x1080.yuv -mfile 1 -bf ./out/mixkit-camels.264 -rw-r--r-- 1 admin staff 784127 Nov 10 14:54 mixkit-camel_layer0.264 -rw-r--r-- 1 admin staff 2341006 Nov 10 14:54 mixkit-camel_layer01.264 -rw-r--r-- 1 admin staff 3908420 Nov 10 14:54 mixkit-camel_layer012.264 -rw-r--r-- 1 admin staff 6824772 Nov 10 14:54 mixkit-camel_layer0123.264 -rw-r--r-- 1 admin staff 1556906 Nov 10 14:54 mixkit-camel_layer1.264 -rw-r--r-- 1 admin staff 1567441 Nov 10 14:55 mixkit-camel_layer2.264 -rw-r--r-- 1 admin staff 2916379 Nov 10 14:55 mixkit-camel_layer3.264

% ./ffplay ./out/mixkit-camel_layer01.264

Input #0, h264, from './out/mixkit-camel_layer01.264': Duration: N/A, bitrate: N/A Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 480x270, 25 fps, 25 tbr, 1200k tbn [h264 @ 0x7f802c2121c0] sps_id 1 out of range [h264 @ 0x7f802c2121c0] Error decoding the extradata [h264 @ 0x7f802c2121c0] sps_id 1 out of range [h264 @ 0x7f802c2121c0] sps_id 2 out of range [h264 @ 0x7f802c051a80] sps_id 1 out of range57KB sq= 0B f=0/0
[h264 @ 0x7f802c051a80] sps_id 2 out of range [h264 @ 0x7f802c066980] sps_id 1 out of range26KB sq= 0B f=0/0
[h264 @ 0x7f802c066980] sps_id 2 out of range nan M-V: nan fd= 0 aq= 0KB vq= 0KB sq= 0B f=0/0

% ./h264dec out/mixkit-camel_layer01.264 [OpenH264] this = 0x0x139808800, Warning:UpdateAccessUnit():::::Key frame lost.....CAN NOT find IDR from current AU. [OpenH264] this = 0x0x139808800, Warning:UpdateAccessUnit():::::Key frame lost.....CAN NOT find IDR from current AU. [OpenH264] this = 0x0x139808800, Warning:UpdateAccessUnit():::::Key frame lost.....CAN NOT find IDR from current AU. ... [OpenH264] this = 0x0x139808800, Warning:UpdateAccessUnit():::::Key frame lost.....CAN NOT find IDR from current AU.

iWidth: 960 height: 540 Frames: 300 decode time: 0.161631 sec FPS: 1856.079589 fps

Please experts kindly help me on this. Thanks in advance.

shitizenlism commented 10 months ago

admin@A9C-Stallman-A9ED testenv % ./h264dec out/mixkit-camel_layer0.264 H264 source file name: out/mixkit-camel_layer0.264.. Can not find any output file to write..


iWidth: 480 height: 270 Frames: 100 decode time: 0.027790 sec FPS: 3598.416697 fps

admin@A9C-Stallman-A9ED testenv % ./h264dec out/mixkit-camel_layer1.264 H264 source file name: out/mixkit-camel_layer1.264.. Can not find any output file to write..


iWidth: 960 height: 540 Frames: 200 decode time: 0.121354 sec FPS: 1648.070933 fps

admin@A9C-Stallman-A9ED testenv % ./h264dec out/mixkit-camel_layer2.264 H264 source file name: out/mixkit-camel_layer2.264.. Can not find any output file to write..


iWidth: 1280 height: 720 Frames: 400 decode time: 0.232415 sec FPS: 1721.059312 fps

admin@A9C-Stallman-A9ED testenv % ./h264dec out/mixkit-camel_layer3.264 H264 source file name: out/mixkit-camel_layer3.264.. Can not find any output file to write..


iWidth: 1920 height: 1080 Frames: 400 decode time: 0.478718 sec FPS: 835.564988 fps

shitizenlism commented 10 months ago

Actually I do not know how to play svc-streaming. Choose a layer to play? Or play layer[0] + layer[1] + layer[2] + layer[3]? I believe it's the latter. The video is played layer plus layer to achieve the effect from blur to clarity. Am I right?