gavl

timecode.h
1/*****************************************************************
2 * gavl - a general purpose audio/video processing library
3 *
4 * Copyright (c) 2001 - 2024 Members of the Gmerlin project
5 * http://github.com/bplaum
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * *****************************************************************/
20
21
22
23#ifndef GAVL_TIMECODE_H_INCLUDED
24#define GAVL_TIMECODE_H_INCLUDED
25
26#ifdef __cplusplus
27 extern "C" {
28#endif
29
30#include <gavl/gavldefs.h>
31
43
44 typedef uint64_t gavl_timecode_t;
45
46#define GAVL_TIMECODE_SIGN_MASK (0x1LL<<62)
47#define GAVL_TIMECODE_INVALID_MASK (0x1LL<<63)
48
49#define GAVL_TIMECODE_DROP_FRAME (1<<0)
50
51#define GAVL_TIMECODE_UNDEFINED GAVL_TIMECODE_INVALID_MASK
52
59
60 typedef struct
61 {
62 uint32_t int_framerate;
63 uint32_t flags;
64 } gavl_timecode_format_t;
65
71
72GAVL_PUBLIC
73 void gavl_timecode_format_copy(gavl_timecode_format_t * dst,
74 const gavl_timecode_format_t * src);
75
76
84
85GAVL_PUBLIC
86 void gavl_timecode_to_hmsf(gavl_timecode_t tc,
87 int * hours,
88 int * minutes,
89 int * seconds,
90 int * frames);
91
98
99GAVL_PUBLIC
100 void gavl_timecode_to_ymd(gavl_timecode_t tc,
101 int * year,
102 int * month,
103 int * day);
104
112
113GAVL_PUBLIC
114 void gavl_timecode_from_hmsf(gavl_timecode_t * tc,
115 int hours,
116 int minutes,
117 int seconds,
118 int frames);
119
126
127GAVL_PUBLIC
128 void gavl_timecode_from_ymd(gavl_timecode_t * tc,
129 int year,
130 int month,
131 int day);
132
141
142GAVL_PUBLIC
143int64_t gavl_timecode_to_framecount(const gavl_timecode_format_t * tf,
144 gavl_timecode_t tc);
145
154
155GAVL_PUBLIC
156 gavl_timecode_t gavl_timecode_from_framecount(const gavl_timecode_format_t * tf,
157 int64_t fc);
158
165
166GAVL_PUBLIC
167 void gavl_timecode_dump(const gavl_timecode_format_t * tf,
168 gavl_timecode_t tc);
169
170
171/* -YYYY-MM-DD-HH:MM:SS.FFFF */
172
173#define GAVL_TIMECODE_STRING_LEN 26
175
185
186GAVL_PUBLIC
187 void gavl_timecode_prettyprint(const gavl_timecode_format_t * tf,
188 gavl_timecode_t tc,
189 char str[GAVL_TIMECODE_STRING_LEN]);
190
191/* -HH:MM:SS:FF */
192
193#define GAVL_TIMECODE_STRING_LEN_SHORT 13
195
202
203GAVL_PUBLIC
204 void gavl_timecode_prettyprint_short(gavl_timecode_t tc,
205 char str[GAVL_TIMECODE_STRING_LEN_SHORT]);
206
207
211
212#ifdef __cplusplus
213}
214#endif
215
216#endif /* GAVL_TIMECODE_H_INCLUDED */
217
gavl_timecode_prettyprint_short
GAVL_PUBLIC void gavl_timecode_prettyprint_short(gavl_timecode_t tc, char str[GAVL_TIMECODE_STRING_LEN_SHORT])
Print a short timecode into a string.
gavl_timecode_from_framecount
GAVL_PUBLIC gavl_timecode_t gavl_timecode_from_framecount(const gavl_timecode_format_t *tf, int64_t fc)
Get a timecode from the frame count.
gavl_timecode_format_copy
GAVL_PUBLIC void gavl_timecode_format_copy(gavl_timecode_format_t *dst, const gavl_timecode_format_t *src)
Copy one timecode format to another.
gavl_timecode_t
uint64_t gavl_timecode_t
Typedef for timecodes.
Definition timecode.h:44
gavl_timecode_to_hmsf
GAVL_PUBLIC void gavl_timecode_to_hmsf(gavl_timecode_t tc, int *hours, int *minutes, int *seconds, int *frames)
Extract the time part of the timecode.
gavl_timecode_from_hmsf
GAVL_PUBLIC void gavl_timecode_from_hmsf(gavl_timecode_t *tc, int hours, int minutes, int seconds, int frames)
Set the time part of the timecode.
gavl_timecode_from_ymd
GAVL_PUBLIC void gavl_timecode_from_ymd(gavl_timecode_t *tc, int year, int month, int day)
Set the date part of the timecode.
gavl_timecode_to_framecount
GAVL_PUBLIC int64_t gavl_timecode_to_framecount(const gavl_timecode_format_t *tf, gavl_timecode_t tc)
Get the frame count from the timecode.
gavl_timecode_dump
GAVL_PUBLIC void gavl_timecode_dump(const gavl_timecode_format_t *tf, gavl_timecode_t tc)
Dump a timecode to stderr.
gavl_timecode_prettyprint
GAVL_PUBLIC void gavl_timecode_prettyprint(const gavl_timecode_format_t *tf, gavl_timecode_t tc, char str[GAVL_TIMECODE_STRING_LEN])
Print a full timecode into a string.
GAVL_TIMECODE_STRING_LEN_SHORT
#define GAVL_TIMECODE_STRING_LEN_SHORT
Definition timecode.h:193
gavl_timecode_to_ymd
GAVL_PUBLIC void gavl_timecode_to_ymd(gavl_timecode_t tc, int *year, int *month, int *day)
Extract the date part of the timecode.
GAVL_TIMECODE_STRING_LEN
#define GAVL_TIMECODE_STRING_LEN
Definition timecode.h:173
gavl_timecode_format_t
Timecode format.
Definition timecode.h:61
gavl_timecode_format_t::flags
uint32_t flags
Zero or more of the flags defined above.
Definition timecode.h:63
gavl_timecode_format_t::int_framerate
uint32_t int_framerate
Integer framerate. A value of zero signals, that no timecodes are available.
Definition timecode.h:62