'av_seek_frame seek only every 12th frames

I use ffmpeg video player in my graphic aps.

Now I need to implement correct way to start video with specific frame (not only with first). I found good example here and at first thought, that it works for me perfectly:

    bool seek(uint64_t frame)
    {
        int64_t timeBase = (static_cast<int64_t>(_pContext->time_base.num) * AV_TIME_BASE)
                    / static_cast<int64_t>(_pContext->time_base.den);
        auto seekTarget = static_cast<int64_t>(frame) * timeBase;

        if( av_seek_frame(_pFile, -1, seekTarget, AVSEEK_FLAG_ANY) < 0)
            return false;

        avcodec_flush_buffers( _pContext );
        return true;
    }

However, lately I noticed that it seeks only every 12th frame:

seek(10); //gives 0 frame
seek(12); //gives 12 frame
seek(20); //gives 12 frame
seek(80); //gives 72 frame

I guess I calculate timeBase incorrectly, but actually I can't find inforamation how to do it in correct way. There are plenty of code examples, but I've tried many of them and it didn't work at all. It's even weired, that I found too many different ways to calculate the same variable.

P.S. It would be great if someone explain me the meaning of timeBase value, or share good explanation.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source