1

I'm trying to understand how h.264 compression works. So far I have clear what I, P, and B frames are and how are they used. But I'm unsure of is if after this process the number of original input frames are kept or not.

In other words, if a raw video file containing 20 frames going into a h.264 encoder block, will the output compressed file have same number of frames?

2
  • 2
    Normally, yes. The encoding process will output all frames. Exceptions I can think of would be real-time streaming applications with a latency threshold.
    – Gyan
    Commented Sep 27, 2019 at 9:35
  • Understood , thanks Gyan.
    – pplur
    Commented Sep 27, 2019 at 12:51

1 Answer 1

0

I am not sure of my answer. The explanation at the end of it.*

Yes. The number of frames should not change. With one possible exception, I know of.

First of all, normally a compressor takes some steps.

  • Grab a keyframe

  • Compares the difference between groups of pixels and if the difference is below one defined parameter it uses the same data to render them.

  • And now compares the difference between adjacent frames and again, if the difference is below a threshold it uses the same data, using the keyframe as a reference to be compared with.

If the keyframe fails to load you see the glitches, where the image is smushed because you are seeing the "differences" of the frame, but with an incorrect reference image.


The exception is that some programs need to round the number of frames after a keyframe. Let us imagine you defined a keyframe every 10 frames for easy calculations.

Now your clip needs to have 105 frames. Some programs will render the exact number of frames, but some programs could try to render the full "group" of frames attached to the previous keyframe, trying to render 109 frames, or some other could try to end in a keyframe, 110 on this case.


  • I am not sure about my answer because, although it as happened to me on some programs, I can not recall that it was specifically using the h264 codec.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.