avio_tell() return value doesn't change after avformat_seek_file()

25 views Asked by At

I have a C++ program that seeks into a video file.

The C++ code looks like the following:

int64_t before = avio_tell(formatContext);
int status = avformat_seek_file(formatContext, streamIndex, INT64_MIN, desiredPts, 
desiredPts, 0);
CHECK_EQ(status, 0);
avio_flush(formatContext->pb);
int64_t after = avio_tell(formatContext);

std::cout << "before=" << before << " after=" << after << std::endl;

The seek is successful. However, before and after are the exact same value.

In fact from my testing it seems like avio_tell() only returns a different value after avformat_read_frame().

The underlying problem I am trying to solve is very similar to this: How to seek with avformat_seek_file() but only if the seek jumps forward?

My strategy was going to be:

  1. Get the position using avio_tell()
  2. Seek using avformat_seek_file()
  3. Get the new position using avio_tell(). If it seeked backwards, undo the seek by doing a manual seek to the position from (1).

But this strategy doesn't work because avio_tell() doesn't change its return value after avformat_seek_file().

Any input would be appreciated.

0

There are 0 answers