[Libav-user] How to properly seek in audio?

Anton Shekhovtsov shekh.anton at gmail.com
Fri May 13 18:30:21 CEST 2016

2016-05-13 18:42 GMT+03:00 Gonzalo <ggarra13 at gmail.com>:

> El 13/05/16 a las 11:25, Anton Shekhovtsov escribiĆ³:
>> Thanks for reply.
>> I decided I can loop through index_entries and if there is no 'keyframes'
>> When it comes to seeking I do not select id, I just have it. The code
>> deals with single stream (audio), other streams are AVDISCARD_ALL.
>> For pos something like this, but why do you ask?
>> int64_t pos = (destination_sample-discard_samples) * time_base.den /
>> time_base.num;
> I ask because the docs say:
>  * @param timestamp Timestamp in AVStream.time_base units
> And you are multiplying the denominator / numerator when in fact it should
> be the opposite.  With that, you should be able to multiply, say 1 sec, and
> get the right place in pos.
> --
> Gonzalo GarramuƱo
> ggarra13 at gmail.com
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user

"and time_base is product of stream time_base and sample_rate"

I will expand this:
  AVRational tb = stream->time_base;
  av_reduce(&time_base.num, &time_base.den, codec->sample_rate*tb.num,
tb.den, INT_MAX);

There is no mistake, it actually works. My problem was that seek failed
with any pos (even plain 0) because avi has no 'keyframe' flags (maybe this
is bug).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20160513/c93ecd2d/attachment.html>

More information about the Libav-user mailing list