avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
av::Timestamp Class Reference

The Timestamp class represents timestamp value and it timebase. More...

#include <timestamp.h>

Public Member Functions

 Timestamp (int64_t timestamp, const Rational &timebase) noexcept
 Create a timestamp from a value and its time base.
template<typename Duration, typename = typename Duration::period, typename = std::enable_if_t<std::is_integral_v<typename Duration::rep>>>
constexpr Timestamp (const Duration &duration)
 Create AvCpp/FFmpeg compatible timestamp value from the std::chrono::duration/boost::chrono::duration.
template<typename Duration, typename PrecisionPeriod, typename = typename Duration::period, typename = std::enable_if_t<std::is_floating_point_v<typename Duration::rep>>>
constexpr Timestamp (const Duration &duration, PrecisionPeriod)
 Create AvCpp/FFmpeg compatible timestamp value from the floating point std::chrono::duration/boost::chrono::duration with given precision.
template<typename Duration, typename = typename Duration::period, typename = std::enable_if_t<std::is_floating_point_v<typename Duration::rep>>>
constexpr Timestamp (const Duration &duration, const Rational &timebase)
 Create AvCpp/FFmpeg compatible timestamp value from the floating point std::chrono::duration/boost::chrono::duration with given precision.
int64_t timestamp () const noexcept
 The raw timestamp value.
int64_t timestamp (const Rational &timebase) const noexcept
 The timestamp converted to another time base.
const Rational & timebase () const noexcept
 The time base of the timestamp.
 operator bool () const noexcept
 Whether the timestamp carries a value.
bool isValid () const noexcept
 Whether the timestamp is usable.
bool isNoPts () const noexcept
 Whether the timestamp means "no timestamp".
 operator double () const noexcept
 The timestamp in seconds.
double seconds () const noexcept
 The timestamp in seconds.
template<typename Duration, typename = typename Duration::period, typename = typename Duration::rep>
constexpr Duration toDuration () const
 Convert to the std::chrono::duration compatible value.
Timestamp & operator+= (const Timestamp &other)
 Add another timestamp, aligning the time bases.
Timestamp & operator-= (const Timestamp &other)
 Subtract another timestamp, aligning the time bases.
Timestamp & operator*= (const Timestamp &other)
 Multiply by another timestamp.
Timestamp & operator/= (const Timestamp &other)
 Divide by another timestamp.

Detailed Description

Timestamp class can be treated as Fixed Point time representation where timestamp itself is a value and Time Base is a multiplicator. Be careful with construct Timestamp from the std::chrono::duration with floating point rep

Examples
api2-generate-subtitles.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-remux.cpp, and api2-timestamp.cpp.

Constructor & Destructor Documentation

◆ Timestamp() [1/4]

av::Timestamp::Timestamp ( int64_t timestamp,
const Rational & timebase )
noexcept
Parameters
timestampthe value in timebase units
timebasethe time base that gives the value its meaning

◆ Timestamp() [2/4]

template<typename Duration, typename = typename Duration::period, typename = std::enable_if_t<std::is_integral_v<typename Duration::rep>>>
av::Timestamp::Timestamp ( const Duration & duration)
inlineconstexpr

Duration class must not be a floating point to avoid lost precision: Timestamp in the FFmpeg internally are int64_t with integer AVRAtional as timebase that also uses int64_t internally to store numerator and denominator.

Parameters
durationthe duration to convert

◆ Timestamp() [3/4]

template<typename Duration, typename PrecisionPeriod, typename = typename Duration::period, typename = std::enable_if_t<std::is_floating_point_v<typename Duration::rep>>>
av::Timestamp::Timestamp ( const Duration & duration,
PrecisionPeriod  )
inlineconstexpr

PrecisionPeriod defines holded TimeBase

Parameters
durationthe duration to convert

◆ Timestamp() [4/4]

template<typename Duration, typename = typename Duration::period, typename = std::enable_if_t<std::is_floating_point_v<typename Duration::rep>>>
av::Timestamp::Timestamp ( const Duration & duration,
const Rational & timebase )
inlineconstexpr
Parameters
durationthe duration to convert
timebasethe time base to store with the timestamp

Member Function Documentation

◆ isNoPts()

bool av::Timestamp::isNoPts ( ) const
noexcept

◆ isValid()

bool av::Timestamp::isValid ( ) const
noexcept
Returns
true when the value is set and the time base is valid
Examples
api2-generate-subtitles.cpp, api2-hw-scale.cpp, and api2-hw-transcode.cpp.

◆ operator bool()

av::Timestamp::operator bool ( ) const
noexcept
Returns
true when it is not NoPts

◆ operator double()

av::Timestamp::operator double ( ) const
noexcept
Returns
the time in seconds as a floating point value

◆ operator*=()

Timestamp & av::Timestamp::operator*= ( const Timestamp & other)
Parameters
otherthe factor
Returns
this timestamp

◆ operator+=()

Timestamp & av::Timestamp::operator+= ( const Timestamp & other)
Parameters
otherthe timestamp to add
Returns
this timestamp

◆ operator-=()

Timestamp & av::Timestamp::operator-= ( const Timestamp & other)
Parameters
otherthe timestamp to subtract
Returns
this timestamp

◆ operator/=()

Timestamp & av::Timestamp::operator/= ( const Timestamp & other)
Parameters
otherthe divisor
Returns
this timestamp

◆ seconds()

◆ timebase()

const Rational & av::Timestamp::timebase ( ) const
noexcept
Returns
timestamp units per second

◆ timestamp() [1/2]

int64_t av::Timestamp::timestamp ( ) const
noexcept
Returns
the value in timebase() units, or NoPts when unset

◆ timestamp() [2/2]

int64_t av::Timestamp::timestamp ( const Rational & timebase) const
noexcept
Parameters
timebasethe time base to convert to
Returns
the value in timebase units

◆ toDuration()

template<typename Duration, typename = typename Duration::period, typename = typename Duration::rep>
Duration av::Timestamp::toDuration ( ) const
inlineconstexpr

It possible to convert to the floating point duration without additional casts. Convert to a std::chrono duration.

Template Parameters
Durationthe duration type to produce
Returns
the timestamp as that duration; integral durations are rescaled, floating point ones are computed directly

The documentation for this class was generated from the following file: