Loading...
Searching...
No Matches
PlaybackTime.hpp
Go to the documentation of this file.
1#pragma once
2#include <Media/Libav.hpp>
3
4#if SCORE_HAS_LIBAV
5extern "C" {
6#include <libavformat/avformat.h>
7#include <libavutil/mathematics.h>
8}
9
10#include <ossia/detail/flicks.hpp>
11
12#include <algorithm>
13
29namespace Video
30{
31
33inline int64_t playbackStartPts(const AVFormatContext& fmt, const AVStream& st) noexcept
34{
35 if(fmt.start_time != AV_NOPTS_VALUE && fmt.start_time > 0)
36 return av_rescale_q_rnd(
37 fmt.start_time, AV_TIME_BASE_Q, st.time_base,
38 AVRounding(AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX));
39 if(fmt.start_time == AV_NOPTS_VALUE && st.start_time != AV_NOPTS_VALUE)
40 return std::max<int64_t>(st.start_time, 0);
41 return 0;
42}
43
44inline constexpr AVRational flicks_time_base{1, int(ossia::flicks_per_second<int64_t>)};
45
52inline int64_t flicksToPts(int64_t flicks, AVRational tb, int64_t start) noexcept
53{
54 constexpr int64_t slack = ossia::flicks_per_second<int64_t> / 1'000'000;
55 return av_rescale_q_rnd(
56 flicks + slack, flicks_time_base, tb,
57 AVRounding(AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX))
58 + start;
59}
60
62inline int64_t ptsToFlicks(int64_t pts, AVRational tb, int64_t start) noexcept
63{
64 return av_rescale_q(pts - start, tb, flicks_time_base);
65}
66
67}
68#endif
int64_t ptsToFlicks(int64_t pts, AVRational tb, int64_t start) noexcept
The playback time of a timestamp.
Definition PlaybackTime.hpp:62
int64_t playbackStartPts(const AVFormatContext &fmt, const AVStream &st) noexcept
The timestamp, in st's time base, shown at playback time 0.
Definition PlaybackTime.hpp:33
int64_t flicksToPts(int64_t flicks, AVRational tb, int64_t start) noexcept
Definition PlaybackTime.hpp:52