You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avutil/timecode: add ff_timecode_set_smpte
This commit is contained in:
@ -180,6 +180,7 @@ OBJS = adler32.o \
|
||||
threadmessage.o \
|
||||
time.o \
|
||||
timecode.o \
|
||||
timecode_internal.o \
|
||||
timestamp.o \
|
||||
tree.o \
|
||||
twofish.o \
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <stdio.h>
|
||||
#include "common.h"
|
||||
#include "timecode.h"
|
||||
#include "timecode_internal.h"
|
||||
#include "log.h"
|
||||
#include "error.h"
|
||||
|
||||
@ -127,32 +128,10 @@ char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum_arg)
|
||||
return buf;
|
||||
}
|
||||
|
||||
static unsigned bcd2uint(uint8_t bcd)
|
||||
{
|
||||
unsigned low = bcd & 0xf;
|
||||
unsigned high = bcd >> 4;
|
||||
if (low > 9 || high > 9)
|
||||
return 0;
|
||||
return low + 10*high;
|
||||
}
|
||||
|
||||
char *av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
|
||||
{
|
||||
unsigned hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
|
||||
unsigned mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
|
||||
unsigned ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
|
||||
unsigned ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
|
||||
unsigned drop = tcsmpte & 1<<30 && !prevent_df; // 1-bit drop if not arbitrary bit
|
||||
|
||||
if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
|
||||
ff <<= 1;
|
||||
if (!skip_field) {
|
||||
if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
|
||||
ff += !!(tcsmpte & 1 << 7);
|
||||
else
|
||||
ff += !!(tcsmpte & 1 << 23);
|
||||
}
|
||||
}
|
||||
unsigned hh, mm, ss, ff, drop;
|
||||
ff_timecode_set_smpte(&drop, &hh, &mm, &ss, &ff, rate, tcsmpte, prevent_df, skip_field);
|
||||
|
||||
snprintf(buf, AV_TIMECODE_STR_SIZE, "%02u:%02u:%02u%c%02u",
|
||||
hh, mm, ss, drop ? ';' : ':', ff);
|
||||
|
51
libavutil/timecode_internal.c
Normal file
51
libavutil/timecode_internal.c
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
|
||||
* Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "timecode_internal.h"
|
||||
|
||||
static unsigned bcd2uint(uint8_t bcd)
|
||||
{
|
||||
unsigned low = bcd & 0xf;
|
||||
unsigned high = bcd >> 4;
|
||||
if (low > 9 || high > 9)
|
||||
return 0;
|
||||
return low + 10*high;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
*hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
|
||||
*mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
|
||||
*ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
|
||||
*ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
|
||||
*drop = tcsmpte & 1<<30 && !prevent_df; // 1-bit drop if not arbitrary bit
|
||||
|
||||
if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
|
||||
*ff <<= 1;
|
||||
if (!skip_field) {
|
||||
if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
|
||||
*ff += !!(tcsmpte & 1 << 7);
|
||||
else
|
||||
*ff += !!(tcsmpte & 1 << 23);
|
||||
}
|
||||
}
|
||||
}
|
51
libavutil/timecode_internal.h
Normal file
51
libavutil/timecode_internal.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
|
||||
* Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Timecode helpers header
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_TIMECODE_INTERNAL_H
|
||||
#define AVUTIL_TIMECODE_INTERNAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "rational.h"
|
||||
|
||||
/**
|
||||
* Convert SMPTE 12M binary representation to sei info.
|
||||
*
|
||||
* @param drop drop flag output
|
||||
* @param hh hour output
|
||||
* @param mm minute output
|
||||
* @param ss second output
|
||||
* @param ff frame number output
|
||||
* @param rate frame rate of the timecode
|
||||
* @param tcsmpte the 32-bit SMPTE timecode
|
||||
* @param prevent_df prevent the use of a drop flag when it is known the DF bit
|
||||
* is arbitrary
|
||||
* @param skip_field prevent the use of a field flag when it is known the field
|
||||
* bit is arbitrary (e.g. because it is used as PC flag)
|
||||
*/
|
||||
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);
|
||||
|
||||
#endif /* AVUTIL_TIMECODE_INTERNAL_H */
|
Reference in New Issue
Block a user