FFmpeg
Loading...
Searching...
No Matches
timecode_internal.c
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#include "timecode_internal.h"
23
24static unsigned bcd2uint(uint8_t bcd)
25{
26 unsigned low = bcd & 0xf;
27 unsigned high = bcd >> 4;
28 if (low > 9 || high > 9)
29 return 0;
30 return low + 10*high;
31}
32
33void ff_timecode_set_smpte(unsigned *drop, unsigned *hh, unsigned *mm, unsigned *ss, unsigned *ff,
34 AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
35{
36 *hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
37 *mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
38 *ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
39 *ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
40 *drop = tcsmpte & 1<<30 && !prevent_df; // 1-bit drop if not arbitrary bit
41
42 if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
43 *ff <<= 1;
44 if (!skip_field) {
45 if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
46 *ff += !!(tcsmpte & 1 << 7);
47 else
48 *ff += !!(tcsmpte & 1 << 23);
49 }
50 }
51}
#define ss(width, name, subs,...)
Definition cbs_vp9.c:202
int high
Definition dovi_rpuenc.c:39
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition rational.h:89
static unsigned bcd2uint(uint8_t bcd)
void ff_timecode_set_smpte(unsigned *drop, unsigned *hh, unsigned *mm, unsigned *ss, unsigned *ff, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
Convert SMPTE 12M binary representation to sei info.
Rational number (pair of numerator and denominator).
Definition rational.h:58
Timecode helpers header.