Avoid reading one extra frame at the end of the input file.

This patch fixes that the encoder tries to read one extra frame beyond the end of input file and generates a garbage frame.