0

I am creating an H264 byte stream by depacketizing the video fragments from an IP camera.

I am using the following syntax:

0x000001[SPS] 0x000001[PPS] 0x000001[I slice]

After decoding this byte stream, I get a half-blurred image. I am assuming this is because of the missing P-slices

How do I append the P-frames after the I-frames to get the correct video frame? Should it be like below:

 0x000001[SPS] 0x000001[PPS] 0x000001[I slice] 0x000001[P] 0x000001[P]. . .  

Thanks in Advance!

Sangam Belose
  • 4,262
  • 8
  • 26
  • 48
  • I don't understand what you are doing. You receive the stream through RTP? If yes, you are not creating the stream. It is already there. Maybe you want to convert? What are your video fragments mentioned in the question? Since I-Frames don't depend on other frames, they can't depend on P-Frames. Are your I-Frames also blurred after decoding? If yes, maybe the I-Frame data is truncated somewhere? – micha137 Apr 13 '18 at 15:55
  • You are right. I am capturing the video stream in a .264 file for conversion. I am confused if I should be adding the "0x000001" separator before each P-slice like I do for the I-slices? – Srijith Vijay Apr 20 '18 at 06:19

1 Answers1

0

What you are doing looks right. A .h264 file contains raw H.264 NAL units, separated by a start code prefix equal to 0x000001. That is the Byte stream format defined in ISO/IEC 14496-10, Annex B. The standard says "The order of byte stream NAL units in the byte stream shall follow the decoding order of the NAL units contained in the byte stream NAL units". So you can just append your P-frames, since you should have received them in decoding order from your camera.

Probably your problem has a different cause. How do you handle the emulation prevention byte? "A byte equal to 0x03 that may be present within a NAL unit. The presence of emulation prevention bytes ensures that no sequence of consecutive byte-aligned bytes in the NAL unit contains a start code prefix."

So the .h264 file must contain emulation prevention bytes. But do your video fragments contain them?

micha137
  • 1,195
  • 8
  • 22
  • The stream that I receive already takes care of the emulation prevention bytes. I am now able to decode the bytestream successfully. However, the decoded file has a FPS of 417 fps but the video stream is from a camera of 30fps. How do I make sure the fps is the same? – Srijith Vijay Apr 20 '18 at 11:24
  • A raw .h264 file has no information about the frame rate. You have to specify it. – micha137 Apr 20 '18 at 17:20
  • Probably the 417 fps you got is the fastest your decoder can go. – micha137 Apr 20 '18 at 17:34
  • Thanks, @micha137 you were right! It was indeed the max fps the decoder can go. Is the byte stream format (Annex-B or AVCC) just the way we create the H264 file or is it dependent on the IP camera? Does the SPS indicate which format to use? – Srijith Vijay Apr 25 '18 at 11:03