File: timecodefunctions.h

package info (click to toggle)
olive-editor 20200620-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,228 kB
  • sloc: cpp: 51,932; sh: 56; makefile: 7; xml: 7
file content (77 lines) | stat: -rw-r--r-- 2,734 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/***

  Olive - Non-Linear Video Editor
  Copyright (C) 2019 Olive Team

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

***/

#ifndef TIMECODEFUNCTIONS_H
#define TIMECODEFUNCTIONS_H

#include <QString>

#include "common/rational.h"

OLIVE_NAMESPACE_ENTER

/**
 * @brief Functions for converting times/timecodes/timestamps
 *
 * Olive uses the following terminology through its code:
 *
 * `time` - time in seconds presented in a rational form
 * `timebase` - the base time unit of an audio/video stream in seconds
 * `timestamp` - an integer representation of a time in timebase units (in many cases is used like a frame number)
 * `timecode` a user-friendly string representation of a time according to Timecode::Display
 */
class Timecode {
public:
  enum Display {
    kTimecodeDropFrame,
    kTimecodeNonDropFrame,
    kTimecodeSeconds,
    kFrames,
    kMilliseconds
  };

  /**
   * @brief Convert a timestamp (according to a rational timebase) to a user-friendly string representation
   */
  static QString timestamp_to_timecode(const int64_t &timestamp, const rational& timebase, const Display &display, bool show_plus_if_positive = false);

  static int64_t timecode_to_timestamp(const QString& timecode, const rational& timebase, const Display& display, bool *ok = nullptr);

  static rational snap_time_to_timebase(const rational& time, const rational& timebase);

  static int64_t time_to_timestamp(const rational& time, const rational& timebase);
  static int64_t time_to_timestamp(const double& time, const rational& timebase);

  static int64_t rescale_timestamp(const int64_t& ts, const rational& source, const rational& dest);
  static int64_t rescale_timestamp_ceil(const int64_t& ts, const rational& source, const rational& dest);

  static rational timestamp_to_time(const int64_t& timestamp, const rational& timebase);

  static QString time_to_timecode(const rational& time, const rational& timebase, const Display &display, bool show_plus_if_positive = false);

  static bool TimebaseIsDropFrame(const rational& timebase);

  static QString TimeToString(int64_t ms);

};

OLIVE_NAMESPACE_EXIT

#endif // TIMECODEFUNCTIONS_H