Backport video encoding and decoding fixes from master branch