4 Replies Latest reply on Jul 6, 2015 1:48 AM by brooks

    AMF fails to decode live h.264 stream.

    brooks

      Hi, dear masters

           On top of the AMF sample pipelinePlayback in media sdk 1.1, I wrote some code to decode the realtime h.264 stream from another video server. Instead of AMFDataStreamFile, which is created during initialization of playback pipeline, I provided my own 'live source' data stream and inside it, I directed reading from file to live source from network. According to my understanding to pipeline working mechanism, at the beginning of job, I blocked the on-demand reading for PPS/SPS, requested  by the pipeline and until the SPS/PPS is got, the reading call is freed to return back. After that, with synchronization skills, I ensured each reading,afterwards, could retrieve the data from my network buffer,which is holding continuous feed h.264 data. That's basically the outline of my implementation.

         Now, I managed to playback the stream from IP camera successfully, but 2 problems are remarkable,

      a. The latency is big, about 2 or 3 seconds. For example, I suddenly move my hand in front of camera, only after 2 or 3 seconds, I could see this motion in my playback window. I do not see such a big latency with 3rd party tool, like onvif manager.

      b. The decoded picture's quaility is bad when motion is relatively far. I could see obvious blur blocks surrounding moving objects. When stopped for a whiles, the blur could dissappear.

       

        And I think, the worst poblem is that I could not get the real-time h.264 stream from video server,( mentioned above ), to be decoded. Always, the command line window shows the following errors,

       

      2015-05-31 10:32:23.859      534 [h264parser_util]   Error: ..\..\..\..\..\impl\components\VideoStreamParser\parsers\h264\h264_util.cpp(91):Assertion failed:false

      2015-05-31 10:32:23.877      534 [H264Parser]   Error: ..\..\..\..\..\impl\components\VideoStreamParser\parsers\h264\H264Parser.cpp(2947):GetDPBSize() undefined level_idc=0

       

      Something is wrong? But I am sure that SPS/PPS has been obtained by pipeline, by debugging.

      Could anyone do me a favor to analyze the reason?

       

      Thanks.

      Brooks Li.

        • Re: AMF fails to decode live h.264 stream.
          amit.agarwal

          Hi, 1. Easiest way to do it is to use the H264 Parser present in the MediaSDK 1.1 in addition to decode component. 2. If you are using an external parser, then present NAL units to the decoder BUT remember to put the length of the NAL unit at the head of NAL buffer in 4 bytes 3. If this doesn’t help, then set SPS/PPS as extra-data parameters in the first frame Regarding latency You have problem providing the correct SPS/PPS.  There are many streaming protocols but all standard ones deliver SPS/PPS via initial negotiation outside of elementary H264 stream.  For example, RTP protocol usually is preceded by SDP negotiation protocol.  SDP includes SPS/PPS in form of extradata – similar to FFMEG, AMF, etc.  If this is not possible and you have to wait till SPS/PPS comes in the stream you should delay decoding and drop all frames coming before SPS/PPS.  They normally come in IDR frame.  All delays that you see can be attributed to your synchronization.  You should take in account dropped frames and adjust time stamps before you passing them to the presenter. Hope this helps. Please feel free to get in touch with us for any further query. Thank You

          1 of 1 people found this helpful
            • Re: AMF fails to decode live h.264 stream.
              brooks

              Hi, Amit

                  I tried your suggstion #1, and take AvcParser as the 'H264 parser' as you mentioned. It finally works, after tweaking the code a little. That is inisde the constructor of AvcParser, changing

              "

              stream->Seek(AMF_FileSeekBegin, 0);

              FindSPSandPPS();

              "

              to

              "

              stream->Seek(AMF_FileSeekBegin, 0);

                while( this->m_Extradata.GetSize() == 0 )

                {

                     FindSPSandPPS();

                }

              "

              The purpose is to block the decoder's initialization untile the SPS and PPS is got. The video is presented perfectly after such an initialization is completed. But in constrast to original video, the picture brightness is somewhat darker. Is it adjustable?

              Ofcause, putting an endless loop in constructor is not a good sulution, I will seek the better one afterwards.

               

              Anyway, thanks a lot for your helpful guidance!

               

              BTW, are you Israelite?