Search code examples
h.264x264libx264video-compression

Force x264 to encode all frames relative to the first (IDR) frame


I want to generate a h.264 stream in which P-frames are using references exclusively using a long-term reference to the first frame (an IDR frame). This would also require the first frame to be an IDR frame.

This is an academic experiment to understand the encoding behavior of long-term references and the consequences of forcing frames to refer to a specific (single) frame rather than several.

It would be great if I could do this from the command line, but if not possible I am open to modifying x264 for this purpose.

Could anyone point me to where in the source code it is determined:

  • the reference frame / macroblock / partition for the current macroblock
  • changes made to the short term, long term reference frame list
  • whether to use a short term reference frame or a long term reference frame.

Using another encoder like nvenc is also acceptable.


Solution

  • You don’t need to modify the source library. Just the command line tool. x264 has a feature called “reference frame invalidation”. You can just invalidate every frame after the first one. It is documented in the header file.