Timestamp operator-(const Timestamp &left, const Timestamp &right) noexcept { // Use more good precision auto tb = std::min(left.timebase(), right.timebase()); auto tsleft = left.timebase().rescale(left.timestamp(), tb); auto tsright = right.timebase().rescale(right.timestamp(), tb); auto ts = tsleft - tsright; return {ts, tb}; }
Timestamp operator+(const Timestamp &left, const Timestamp &right) noexcept { // Use more good precision if (left.timebase() < right.timebase()) { auto ts = av_add_stable(left.timebase(), left.timestamp(), right.timebase(), right.timestamp()); return {ts, left.timebase()}; } else { auto ts = av_add_stable(right.timebase(), right.timestamp(), left.timebase(), left.timestamp()); return {ts, right.timebase()}; } }
Timestamp operator/(const Timestamp &left, const Timestamp &right) noexcept { int num, den; // Use more good precision auto tb = std::min(left.timebase(), right.timebase()); auto tsleft = left.timebase().rescale(left.timestamp(), tb); auto tsright = right.timebase().rescale(right.timestamp(), tb); int64_t ts = 1; if (tsleft > tsright) { ts = tsleft / tsright; tsleft %= tsright; if (tsleft == 0) { tsleft = 1; tsright = 1; } } av_reduce(&num, &den, tsleft, tsright, INT64_MAX); return {ts, {num, den}}; }
void FormatContext::seek(const Timestamp ×tamp, size_t streamIndex, bool anyFrame, OptionalErrorCode ec) { auto st = stream(streamIndex); if (st.isValid()) seek(timestamp.timestamp(st.timeBase()), static_cast<int>(streamIndex), anyFrame ? AVSEEK_FLAG_ANY : 0, ec); }
void FormatContext::seek(const Timestamp& timestamp, bool anyFrame, OptionalErrorCode ec) { seek(timestamp.timestamp(AV_TIME_BASE_Q), -1, anyFrame ? AVSEEK_FLAG_ANY : 0, ec); }
void FormatContext::seek(const Timestamp& timestamp, size_t streamIndex, OptionalErrorCode ec) { auto st = stream(streamIndex, ec); if (st.isValid()) seek(timestamp.timestamp(st.timeBase()), static_cast<int>(streamIndex), 0, ec); }
void FormatContext::seek(const Timestamp ×tamp, OptionalErrorCode ec) { seek(timestamp.timestamp(AV_TIME_BASE_Q), -1, 0, ec); }
void Packet::setDts(const Timestamp &dts) { m_raw.dts = dts.timestamp(m_timeBase); }
void Packet::setPts(const Timestamp &pts) { m_raw.pts = pts.timestamp(m_timeBase); }
Timestamp operator*(const Timestamp &left, const Timestamp &right) noexcept { auto ts = left.timestamp() * right.timestamp(); auto tb = left.timebase() * right.timebase(); return {ts, tb}; }