Hi!
I am trying to figure out the right way to convert PTS during demuxing to
frame number.
I came up with the following code:
int64_t timestamp_to_frame(Demuxer* demuxer, int64_t pts)
{
AVStream* stream = demuxer->fmtc->streams[demuxer->iVideoStream];
if (!stream || pts < 0)
{
fprintf(stderr, "Invalid stream or PTS.\n");
return -1;
}
// Get the frame rate (FPS)
const double fps = get_frame_rate(stream);//here returns 25.0
// Stream time base (e.g., 1/25000 for my case)
const AVRational timeBase = stream->time_base;
// Calculate frame duration in seconds
const double frameDurationInSeconds = 1.0 / fps;
const int64_t ptsIncrement = (int64_t)((frameDurationInSeconds *
timeBase.den) * frameDurationInSeconds + 0.5);
// Calculate the frame number by dividing PTS by the increment
const int64_t frameNumber = pts / ptsIncrement;
return frameNumber;
}
It works correctly, but I am not sure this is the right way to do that and
that it will work with any fps/time scale. Could someone review this code
and provide feedback, or an alternative way?
Much appreciated,
Mike.
_______________________________________________
Libav-user mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/libav-user
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".