Color distortion when saving as video file
[...] I chose a white (hex-code #ffffff) background, which works very fine for a single png file. However, when importing the mpeg file [...] all subsequent frames have a slightly grayish background (hex-code #ebebeb).


Suspiciously 0xEB ends up being 235, which just happens to be the broadcast YCbCr BT.709 level. That might be a hint that your decoding is failing you. The decode should correctly scale that value back up to 255.

If you read any of the other diatribes I have written on the subject of codecs, encoding, and decoding, you will know that they are absolutely and horrifically bound to complexity. Is the encode correct? Are the proper flags set? Is the decode correct? Were the proper flags honoured? Is the GPU to fault? Is there something else somewhere that is bungled.

The long story short is that while we can't precisely answer your question, we can determine a few possible things:


Did your encoder encode the correct 255 8 bit value to 235? Check also with 0, which should be scaled up to 16.
Did your decoder decode the correct values and scale them back to their original positions?
How are you evaluating the output? Is it a screenshot from a full screen player? Windowed? Are there differences? Are there differences between players?


My best guess is that it encoded correctly but your player of choice is mis-guessing or not displaying the output correctly. Either that or it is encoded correctly but a flag that the player is looking for isn't set correctly.

Best advice is to check the encoded output with several players, at both full screen and windowed. Compare results. VLC, MPlayer, and your resident OS media player are good starting points.

Good luck...