A method for encoding a plurality of frames, comprising: identifying an allocated number of reference picture buffers; calculating a maximum number of picture IDs as equal to or greater than the allocated number; assigning, using a processor, a picture ID to a respective reference picture assigned to a respective reference picture buffer of a plurality of reference picture buffers to no higher than the maximum number of picture IDs, each picture ID having a value not assigned to any other reference pictures assigned to the plurality of reference picture buffers by: defining a first array of the allocated number of reference picture buffers, each entry in the first array marked as unused or marked with the picture ID of its assigned reference picture; defining a second array of the maximum number of picture IDs, each entry in the second array marked as unused or marked with a picture ID of a reference picture freed from the plurality of reference picture buffers; and selecting a picture ID for a reference picture that is not the same as in the first array and is not the same as in the second array until the second array is full; freeing the picture ID when its associated reference picture is no longer assigned to the reference picture buffer; periodically re-using a freed picture ID when assigning the picture IDs; encoding one or more frames of the plurality of frames into an encoded video stream using the reference pictures assigned to the plurality of reference picture buffers; and including the picture IDs in the encoded video stream for decoding by a decoder. identifying an allocated number of reference picture buffers; calculating a maximum number of picture IDs as equal to or greater than the allocated number; assigning, using a processor, a picture ID to a respective reference picture assigned to a respective reference picture buffer of a plurality of reference picture buffers to no higher than the maximum number of picture IDs, each picture ID having a value not assigned to any other reference pictures assigned to the plurality of reference picture buffers by: defining a first array of the allocated number of reference picture buffers, each entry in the first array marked as unused or marked with the picture ID of its assigned reference picture; defining a second array of the maximum number of picture IDs, each entry in the second array marked as unused or marked with a picture ID of a reference picture freed from the plurality of reference picture buffers; and selecting a picture ID for a reference picture that is not the same as in the first array and is not the same as in the second array until the second array is full; defining a first array of the allocated number of reference picture buffers, each entry in the first array marked as unused or marked with the picture ID of its assigned reference picture; defining a second array of the maximum number of picture IDs, each entry in the second array marked as unused or marked with a picture ID of a reference picture freed from the plurality of reference picture buffers; and selecting a picture ID for a reference picture that is not the same as in the first array and is not the same as in the second array until the second array is full; freeing the picture ID when its associated reference picture is no longer assigned to the reference picture buffer; periodically re-using a freed picture ID when assigning the picture IDs; encoding one or more frames of the plurality of frames into an encoded video stream using the reference pictures assigned to the plurality of reference picture buffers; and including the picture IDs in the encoded video stream for decoding by a decoder.