Assume the very first GOP has the following structure (in display order): BBIBBPBBP... and the GOP is not marked as closed (D2VWitch does this). Also assume that pictures are requested linearly, i.e., 0, 1, 2, ... Then when src/core/decode.cpp:decodeframe() is asked for picture 0, it will return picture 0 — fine. If now asked for picture 1, however, it will return frame 0 again: decodeframe() finds that the first I picture follows the requested picture, decides it has to start the decoding process again (which is superfluous, but not wrong), and set the picture offset to 0 (cf. “offset = n > f.offset ? 0 : f.offset - n” on line 313). When asked for picture 2 (i.e., the I picture), it again sets the offset to 0 (same source line) and will deliver picture 0 again, and after that it will deliver picture 1 when asked for 3, 2 for 4, etc.
This “only” results in duplicate pictures, but it also breaks frame-accurate access, because if frames are requested linearly, say, 0, 1, 2, ..., 100, spanning several GOPs, you will get pictures 0, 0, 0, 1, 2, ..., 98, but if you request picture 100 by jumping directly to it, you do get the correct picture, i.e., 100.
I have attached a patch but because I could not get my head around the current code, it is basically a complete re-write of decodeframe(). Feel free to laugh your behind off and dismiss it out of hand.
0001-BUG-If-the-very-first-GOP-is-a-sequence-of-say-BBIBB.patch.txt
PS: ffms2 seems to have the same problem.
Assume the very first GOP has the following structure (in display order): BBIBBPBBP... and the GOP is not marked as closed (D2VWitch does this). Also assume that pictures are requested linearly, i.e., 0, 1, 2, ... Then when src/core/decode.cpp:decodeframe() is asked for picture 0, it will return picture 0 — fine. If now asked for picture 1, however, it will return frame 0 again: decodeframe() finds that the first I picture follows the requested picture, decides it has to start the decoding process again (which is superfluous, but not wrong), and set the picture offset to 0 (cf. “offset = n > f.offset ? 0 : f.offset - n” on line 313). When asked for picture 2 (i.e., the I picture), it again sets the offset to 0 (same source line) and will deliver picture 0 again, and after that it will deliver picture 1 when asked for 3, 2 for 4, etc.
This “only” results in duplicate pictures, but it also breaks frame-accurate access, because if frames are requested linearly, say, 0, 1, 2, ..., 100, spanning several GOPs, you will get pictures 0, 0, 0, 1, 2, ..., 98, but if you request picture 100 by jumping directly to it, you do get the correct picture, i.e., 100.
I have attached a patch but because I could not get my head around the current code, it is basically a complete re-write of decodeframe(). Feel free to laugh your behind off and dismiss it out of hand.
0001-BUG-If-the-very-first-GOP-is-a-sequence-of-say-BBIBB.patch.txt
PS: ffms2 seems to have the same problem.