Merge "Common encode/decode function to get reference frame"