FFmpeg
Functions
timecode.c File Reference
#include <stdio.h>
#include "timecode.h"
#include "log.h"
#include "error.h"

Go to the source code of this file.

Functions

int av_timecode_adjust_ntsc_framenum2 (int framenum, int fps)
 Adjust frame number for NTSC drop frame time code. More...
 
uint32_t av_timecode_get_smpte_from_framenum (const AVTimecode *tc, int framenum)
 Convert frame number to SMPTE 12M binary representation. More...
 
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. More...
 
char * av_timecode_make_string (const AVTimecode *tc, char *buf, int framenum)
 Load timecode string in buf. More...
 
static unsigned bcd2uint (uint8_t bcd)
 
char * av_timecode_make_smpte_tc_string2 (char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
 Get the timecode string from the SMPTE timecode format. More...
 
char * av_timecode_make_smpte_tc_string (char *buf, uint32_t tcsmpte, int prevent_df)
 Get the timecode string from the SMPTE timecode format. More...
 
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). More...
 
static int check_fps (int fps)
 
static int check_timecode (void *log_ctx, AVTimecode *tc)
 
static int fps_from_frame_rate (AVRational rate)
 
int av_timecode_check_frame_rate (AVRational rate)
 Check if the timecode feature is available for the given frame rate. More...
 
int av_timecode_init (AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx)
 Init a timecode struct with the passed parameters. More...
 
int av_timecode_init_from_components (AVTimecode *tc, AVRational rate, int flags, int hh, int mm, int ss, int ff, void *log_ctx)
 Init a timecode struct from the passed timecode components. More...
 
int av_timecode_init_from_string (AVTimecode *tc, AVRational rate, const char *str, void *log_ctx)
 Parse timecode representation (hh:mm:ss[:;. More...
 

Detailed Description

Timecode helpers

See also
https://en.wikipedia.org/wiki/SMPTE_time_code
http://www.dropframetimecode.org

Definition in file timecode.c.

Function Documentation

◆ av_timecode_adjust_ntsc_framenum2()

int av_timecode_adjust_ntsc_framenum2 ( int  framenum,
int  fps 
)

Adjust frame number for NTSC drop frame time code.

Parameters
framenumframe number to adjust
fpsframe per second, multiples of 30
Returns
adjusted frame number
Warning
adjustment is only valid for multiples of NTSC 29.97

Definition at line 34 of file timecode.c.

Referenced by av_timecode_get_smpte_from_framenum(), and av_timecode_make_string().

◆ av_timecode_get_smpte_from_framenum()

uint32_t av_timecode_get_smpte_from_framenum ( const AVTimecode tc,
int  framenum 
)

Convert frame number to SMPTE 12M binary representation.

Parameters
tctimecode data correctly initialized
framenumframe number
Returns
the SMPTE binary representation

See SMPTE ST 314M-2005 Sec 4.4.2.2.1 "Time code pack (TC)" the format description as follows: bits 0-5: hours, in BCD(6bits) bits 6: BGF1 bits 7: BGF2 (NTSC) or FIELD (PAL) bits 8-14: minutes, in BCD(7bits) bits 15: BGF0 (NTSC) or BGF2 (PAL) bits 16-22: seconds, in BCD(7bits) bits 23: FIELD (NTSC) or BGF0 (PAL) bits 24-29: frames, in BCD(6bits) bits 30: drop frame flag (0: non drop, 1: drop) bits 31: color frame flag (0: unsync mode, 1: sync mode)

Note
BCD numbers (6 or 7 bits): 4 or 5 lower bits for units, 2 higher bits for tens.
Frame number adjustment is automatically done in case of drop timecode, you do NOT have to call av_timecode_adjust_ntsc_framenum2().
The frame number is relative to tc->start.
Color frame (CF) and binary group flags (BGF) bits are set to zero.

Definition at line 52 of file timecode.c.

Referenced by dv_write_pack(), mxf_write_system_item(), and decklink_input_callback::VideoInputFrameArrived().

◆ av_timecode_get_smpte()

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.

Parameters
rateframe rate in rational form
dropdrop flag
hhhour
mmminute
sssecond
ffframe number
Returns
the SMPTE binary representation

Definition at line 68 of file timecode.c.

Referenced by av_timecode_get_smpte_from_framenum(), h264_export_frame_props(), and set_side_data().

◆ av_timecode_make_string()

char* av_timecode_make_string ( const AVTimecode tc,
char *  buf,
int  framenum 
)

Load timecode string in buf.

Parameters
bufdestination buffer, must be at least AV_TIMECODE_STR_SIZE long
tctimecode data correctly initialized
framenumframe number
Returns
the buf parameter
Note
Timecode representation can be a negative timecode and have more than 24 hours, but will only be honored if the flags are correctly set.
The frame number is relative to tc->start.

Definition at line 102 of file timecode.c.

Referenced by draw_text(), mxf_add_timecode_metadata(), parse_timecode_in_framenum_format(), segment_end(), and decklink_input_callback::VideoInputFrameArrived().

◆ bcd2uint()

static unsigned bcd2uint ( uint8_t  bcd)
static

Definition at line 127 of file timecode.c.

Referenced by av_timecode_make_smpte_tc_string2().

◆ av_timecode_make_smpte_tc_string2()

char* av_timecode_make_smpte_tc_string2 ( char *  buf,
AVRational  rate,
uint32_t  tcsmpte,
int  prevent_df,
int  skip_field 
)

Get the timecode string from the SMPTE timecode format.

In contrast to av_timecode_make_smpte_tc_string this function supports 50/60 fps timecodes by using the field bit.

Parameters
bufdestination buffer, must be at least AV_TIMECODE_STR_SIZE long
rateframe rate of the timecode
tcsmptethe 32-bit SMPTE timecode
prevent_dfprevent the use of a drop flag when it is known the DF bit is arbitrary
skip_fieldprevent the use of a field flag when it is known the field bit is arbitrary (e.g. because it is used as PC flag)
Returns
the buf parameter

Definition at line 136 of file timecode.c.

Referenced by av_timecode_make_smpte_tc_string(), decode_frame(), dump_s12m_timecode(), dv_extract_timecode(), h264_export_frame_props(), set_side_data(), show_frame(), and wsd_read_header().

◆ av_timecode_make_smpte_tc_string()

char* av_timecode_make_smpte_tc_string ( char *  buf,
uint32_t  tcsmpte,
int  prevent_df 
)

Get the timecode string from the SMPTE timecode format.

Parameters
bufdestination buffer, must be at least AV_TIMECODE_STR_SIZE long
tcsmptethe 32-bit SMPTE timecode
prevent_dfprevent the use of a drop flag when it is known the DF bit is arbitrary
Returns
the buf parameter

Definition at line 160 of file timecode.c.

◆ av_timecode_make_mpeg_tc_string()

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).

Parameters
bufdestination buffer, must be at least AV_TIMECODE_STR_SIZE long
tc25bitthe 25-bits timecode
Returns
the buf parameter

Definition at line 165 of file timecode.c.

Referenced by filter_frame(), mpeg_decode_frame(), mpeg_decode_gop(), and show_frame().

◆ check_fps()

static int check_fps ( int  fps)
static

Definition at line 177 of file timecode.c.

Referenced by av_timecode_check_frame_rate(), and check_timecode().

◆ check_timecode()

static int check_timecode ( void *  log_ctx,
AVTimecode tc 
)
static

Definition at line 190 of file timecode.c.

Referenced by av_timecode_init(), and av_timecode_init_from_components().

◆ fps_from_frame_rate()

static int fps_from_frame_rate ( AVRational  rate)
static

◆ av_timecode_check_frame_rate()

int av_timecode_check_frame_rate ( AVRational  rate)

Check if the timecode feature is available for the given frame rate.

Returns
0 if supported, <0 otherwise

Definition at line 214 of file timecode.c.

Referenced by find_fps().

◆ av_timecode_init()

int av_timecode_init ( AVTimecode tc,
AVRational  rate,
int  flags,
int  frame_start,
void *  log_ctx 
)

Init a timecode struct with the passed parameters.

Parameters
log_ctxa pointer to an arbitrary struct of which the first field is a pointer to an AVClass struct (used for av_log)
tcpointer to an allocated AVTimecode
rateframe rate in rational form
flagsmiscellaneous flags such as drop frame, +24 hours, ... (see AVTimecodeFlag)
frame_startthe first frame number
Returns
0 on success, AVERROR otherwise

Definition at line 219 of file timecode.c.

Referenced by dv_write_header(), mxf_init_timecode(), mxf_parse_physical_source_package(), mxf_parse_structural_metadata(), and parse_timecode_in_framenum_format().

◆ av_timecode_init_from_components()

int av_timecode_init_from_components ( AVTimecode tc,
AVRational  rate,
int  flags,
int  hh,
int  mm,
int  ss,
int  ff,
void *  log_ctx 
)

Init a timecode struct from the passed timecode components.

Parameters
log_ctxa pointer to an arbitrary struct of which the first field is a pointer to an AVClass struct (used for av_log)
tcpointer to an allocated AVTimecode
rateframe rate in rational form
flagsmiscellaneous flags such as drop frame, +24 hours, ... (see AVTimecodeFlag)
hhhours
mmminutes
ssseconds
ffframes
Returns
0 on success, AVERROR otherwise

Definition at line 229 of file timecode.c.

Referenced by av_timecode_init_from_string(), and get_bmd_timecode().

◆ av_timecode_init_from_string()

int av_timecode_init_from_string ( AVTimecode tc,
AVRational  rate,
const char *  str,
void *  log_ctx 
)

Parse timecode representation (hh:mm:ss[:;.

]ff).

Parameters
log_ctxa pointer to an arbitrary struct of which the first field is a pointer to an AVClass struct (used for av_log).
tcpointer to an allocated AVTimecode
rateframe rate in rational form
strtimecode string which will determine the frame start
Returns
0 on success, AVERROR otherwise

Definition at line 250 of file timecode.c.

Referenced by dv_write_header(), init(), mov_check_timecode_track(), mxf_init_timecode(), and segment_end().