annotate lib/libavutil/timecode.h @ 2134:992d2e6f907d

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