Last active
November 5, 2015 11:59
-
-
Save yohhoy/c3d2755d02b736cfab92 to your computer and use it in GitHub Desktop.
NDF/DF SMPTE timecode, frame number w/ FFmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -std=c99 -I/usr/include/ffmpeg ndf.c -lavutil | |
#include <stdio.h> | |
#include <libavutil/timecode.h> | |
int main() { | |
AVRational fps = { 30000, 1001 }; | |
AVTimecode tc1, tc2; | |
av_timecode_init(&tc1, fps, 0, 0, NULL); // NDF TC | |
av_timecode_init(&tc2, fps, AV_TIMECODE_FLAG_DROPFRAME, 0, NULL); // DF TC | |
int prev_fn_df = 0; | |
for (int fn = 0; ; fn++) { | |
uint32_t tc_ndf = av_timecode_get_smpte_from_framenum(&tc1, fn); // SMPTE 12M(NDF) | |
uint32_t tc_df = av_timecode_get_smpte_from_framenum(&tc2, fn); // SMPTE 12M(DF) | |
int fn_df = av_timecode_adjust_ntsc_framenum2(fn, tc1.fps); // frame number (for DF) | |
char buf1[AV_TIMECODE_STR_SIZE], buf2[AV_TIMECODE_STR_SIZE]; | |
printf("%8d %s %8d %s%s\n", | |
fn, av_timecode_make_smpte_tc_string(buf1, tc_ndf, 0), | |
fn_df, av_timecode_make_smpte_tc_string(buf2, tc_df, 0), | |
(prev_fn_df + 1 == fn_df) ? "" : " *"); | |
prev_fn_df = fn_df; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment