Preseek was effetively hardcoded to value 25 and that only for codecs
with B frames, which is not correct. It was supposed to be set to GOP
size, but that is not always constant. Also is should be used for all
codecs with delayed output capability.
ffmpeg_can_scan() function relied on preseek value to determine
whether seeking to next key frame is necessary or not.
This is resolved by actually seeking to key frame for current and
requested frame. After seeking, packet is read just to compare PTS of
these packets. If PTS is same, these are the same packet and therefore
both frames belong to same GOP and no seeking is necessary.
Seeking disrupts internal state of decoding process and it is necessary
to seek back to last position. This is done by seeking by frame and
reading packets in loop until packet PTS matches last read packet PTS
stored in anim struct in next_packet field. This seems like a
wasteful approach, but it is very fast. Still it would be nice to find
better method.
This change does have minor positive effect on performance. It is most
visible on files with GOP sizes bigger than 50. On files with marginally
greater GOP size, like 500 the effect is, that UI doesn't freeze for 2
seconds, but only for one.
TODO:
- First video frame is not decoded properly