2 * Copyright (C) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
3 * Copyright (C) 2011 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
5 * This file is part of FFmpeg.
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.
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.
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
24 * Timecode helpers header
27 #ifndef AVCODEC_TIMECODE_H
28 #define AVCODEC_TIMECODE_H
32 #include "libavutil/rational.h"
34 #define TIMECODE_OPT(ctx, flags) \
35 "timecode", "set timecode value following hh:mm:ss[:;.]ff format, " \
36 "use ';' or '.' before frame number for drop frame", \
37 offsetof(ctx, tc.str), \
38 AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, flags
41 char *str; ///< string following the hh:mm:ss[:;.]ff format
42 int start; ///< timecode frame start
43 int drop; ///< drop flag (1 if drop, else 0)
44 AVRational rate; ///< Frame rate in rational form
48 * @brief Adjust frame number for NTSC drop frame time code
49 * @param frame_num Actual frame number to adjust
50 * @return Adjusted frame number
51 * @warning Adjustment is only valid in NTSC 29.97
53 int avpriv_framenum_to_drop_timecode(int frame_num);
56 * @brief Convert frame id (timecode) to SMPTE 12M binary representation
57 * @param frame Frame number
58 * @param fps Frame rate
59 * @param drop Drop flag
60 * @return The actual binary representation
62 uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop);
65 * @brief Load timecode string in buf
66 * @param buf Destination buffer
67 * @param tc Timecode struct pointer
68 * @param frame Frame id (timecode frame is computed with tc->start+frame)
69 * @return a pointer to the buf parameter
70 * @note timecode representation can be a negative timecode and have
72 * @note buf must have enough space to store the timecode representation: 16
73 * bytes is the minimum required size.
75 char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame);
78 * Check if timecode rate is valid and consistent with the drop flag.
80 * @return 0 on success, negative value on failure
82 int avpriv_check_timecode_rate(void *avcl, AVRational rate, int drop);
85 * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields
86 * from tc struct must be set.
88 * @param avcl A pointer to an arbitrary struct of which the first field is a
89 * pointer to an AVClass struct (used for av_log).
90 * @param tc Timecode struct pointer
91 * @return 0 on success, negative value on failure
92 * @warning Adjustement is only valid in NTSC 29.97
94 int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc);
96 #if FF_API_OLD_TIMECODE
97 attribute_deprecated int ff_framenum_to_drop_timecode(int frame_num);
98 attribute_deprecated uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop);
99 attribute_deprecated int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc);
102 #endif /* AVCODEC_TIMECODE_H */