MP4(3)

NAME

MP4GetSampleIdFromTime - Get the closest sample of a track to a specified time

SYNTAX

#include <mp4.h>

MP4SampleId MP4GetSampleIdFromTime(
    MP4FileHandle hFile,
    MP4TrackId trackId,
    MP4Timestamp when,
    bool wantSyncSample = false
);

ARGUMENTS

hFile
    Specifies the mp4 file to which the operation applies.

trackId
    Specifies the track to which the operation applies.

when
    Specifies the time in the track time scale that is desired.

wantSyncSample
    Specifies if the returned sample id must correspond to a sample whose sync/random access flag is true.

RETURN VALUES

Upon success, the sample id with the start time closest to the specified time. Upon an error, MP4_INVALID_SAMPLE_ID.

DESCRIPTION

MP4GetSampleIdFromTime returns the sample id of the track sample with the start time that is closest to the specified time. The specified time should be in the track time scale. See MP4ConvertToTrackTimestamp() for how to map a time value to this time scale.

Closest in this case is taken to be the start time with the smallest positive difference with the given time. I.e. samples that start before the given time are excluded. If the alternative behavior is desired, then all the calling application needs to do is subtract one from the returned sample id.

If the calling application needs a sample that can be accessed randomly then the 'wantSyncSample' argument should be set to true. This could be the case for a player that is implementing a positioning function and needs to be able to start decoding a track from the returned sample id.

It is wise to use MP4GetSampleTime() with the returned sample id and adjust for any difference between the specified time and the actual time of the sample.

SEE ALSO

MP4(3)