FFmpeg
timecode.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
3  * Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg 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 GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Timecode helpers header
25  */
26 
27 #ifndef AVUTIL_TIMECODE_H
28 #define AVUTIL_TIMECODE_H
29 
30 #include <stdint.h>
31 #include "rational.h"
32 
33 #define AV_TIMECODE_STR_SIZE 23
34 
36  AV_TIMECODE_FLAG_DROPFRAME = 1<<0, ///< timecode is drop frame
37  AV_TIMECODE_FLAG_24HOURSMAX = 1<<1, ///< timecode wraps after 24 hours
38  AV_TIMECODE_FLAG_ALLOWNEGATIVE = 1<<2, ///< negative time values are allowed
39 };
40 
41 typedef struct {
42  int start; ///< timecode frame start (first base frame number)
43  uint32_t flags; ///< flags such as drop frame, +24 hours support, ...
44  AVRational rate; ///< frame rate in rational form
45  unsigned fps; ///< frame per second; must be consistent with the rate field
46 } AVTimecode;
47 
48 /**
49  * Adjust frame number for NTSC drop frame time code.
50  *
51  * @param framenum frame number to adjust
52  * @param fps frame per second, 30 or 60
53  * @return adjusted frame number
54  * @warning adjustment is only valid in NTSC 29.97 and 59.94
55  */
56 int av_timecode_adjust_ntsc_framenum2(int framenum, int fps);
57 
58 /**
59  * Convert frame number to SMPTE 12M binary representation.
60  *
61  * @param tc timecode data correctly initialized
62  * @param framenum frame number
63  * @return the SMPTE binary representation
64  *
65  * @note Frame number adjustment is automatically done in case of drop timecode,
66  * you do NOT have to call av_timecode_adjust_ntsc_framenum2().
67  * @note The frame number is relative to tc->start.
68  * @note Color frame (CF), binary group flags (BGF) and biphase mark polarity
69  * correction (PC) bits are set to zero.
70  */
71 uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
72 
73 /**
74  * Convert sei info to SMPTE 12M binary representation.
75  *
76  * @param rate frame rate in rational form
77  * @param drop drop flag
78  * @param hh hour
79  * @param mm minute
80  * @param ss second
81  * @param ff frame number
82  * @return the SMPTE binary representation
83  */
84 uint32_t av_timecode_get_smpte(AVRational rate, int drop, int hh, int mm, int ss, int ff);
85 
86 /**
87  * Load timecode string in buf.
88  *
89  * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long
90  * @param tc timecode data correctly initialized
91  * @param framenum frame number
92  * @return the buf parameter
93  *
94  * @note Timecode representation can be a negative timecode and have more than
95  * 24 hours, but will only be honored if the flags are correctly set.
96  * @note The frame number is relative to tc->start.
97  */
98 char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum);
99 
100 /**
101  * Get the timecode string from the SMPTE timecode format.
102  *
103  * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long
104  * @param tcsmpte the 32-bit SMPTE timecode
105  * @param prevent_df prevent the use of a drop flag when it is known the DF bit
106  * is arbitrary
107  * @return the buf parameter
108  */
109 char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df);
110 
111 /**
112  * Get the timecode string from the 25-bit timecode format (MPEG GOP format).
113  *
114  * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long
115  * @param tc25bit the 25-bits timecode
116  * @return the buf parameter
117  */
118 char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit);
119 
120 /**
121  * Init a timecode struct with the passed parameters.
122  *
123  * @param log_ctx a pointer to an arbitrary struct of which the first field
124  * is a pointer to an AVClass struct (used for av_log)
125  * @param tc pointer to an allocated AVTimecode
126  * @param rate frame rate in rational form
127  * @param flags miscellaneous flags such as drop frame, +24 hours, ...
128  * (see AVTimecodeFlag)
129  * @param frame_start the first frame number
130  * @return 0 on success, AVERROR otherwise
131  */
132 int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx);
133 
134 /**
135  * Parse timecode representation (hh:mm:ss[:;.]ff).
136  *
137  * @param log_ctx a pointer to an arbitrary struct of which the first field is a
138  * pointer to an AVClass struct (used for av_log).
139  * @param tc pointer to an allocated AVTimecode
140  * @param rate frame rate in rational form
141  * @param str timecode string which will determine the frame start
142  * @return 0 on success, AVERROR otherwise
143  */
144 int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx);
145 
146 /**
147  * Check if the timecode feature is available for the given frame rate
148  *
149  * @return 0 if supported, <0 otherwise
150  */
152 
153 #endif /* AVUTIL_TIMECODE_H */
#define tc
Definition: regdef.h:69
uint32_t av_timecode_get_smpte(AVRational rate, int drop, int hh, int mm, int ss, int ff)
Convert sei info to SMPTE 12M binary representation.
Definition: timecode.c:84
timecode is drop frame
Definition: timecode.h:36
char * av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum)
Load timecode string in buf.
Definition: timecode.c:116
int start
timecode frame start (first base frame number)
Definition: timecode.h:42
int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx)
Parse timecode representation (hh:mm:ss[:;.
Definition: timecode.c:226
AVTimecodeFlag
Definition: timecode.h:35
unsigned fps
frame per second; must be consistent with the rate field
Definition: timecode.h:45
#define ss(width, name, subs,...)
Definition: cbs_vp9.c:261
timecode wraps after 24 hours
Definition: timecode.h:37
int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
Adjust frame number for NTSC drop frame time code.
Definition: timecode.c:34
AVRational rate
frame rate in rational form
Definition: timecode.h:44
int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx)
Init a timecode struct with the passed parameters.
Definition: timecode.c:216
static int frame_start(MpegEncContext *s)
Rational number (pair of numerator and denominator).
Definition: rational.h:58
int av_timecode_check_frame_rate(AVRational rate)
Check if the timecode feature is available for the given frame rate.
Definition: timecode.c:211
#define flags(name, subs,...)
Definition: cbs_av1.c:560
negative time values are allowed
Definition: timecode.h:38
char * av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df)
Get the timecode string from the SMPTE timecode format.
Definition: timecode.c:150
char * av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit)
Get the timecode string from the 25-bit timecode format (MPEG GOP format).
Definition: timecode.c:162
Utilties for rational number calculation.
uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum)
Convert frame number to SMPTE 12M binary representation.
Definition: timecode.c:55
uint32_t flags
flags such as drop frame, +24 hours support, ...
Definition: timecode.h:43