avformat/avidec: Speed up keyframe detection code