libltc: ltcdecode.c

| libltc 1.3.2 Linear/Logitudinal Time Code (LTC) Library

ltcdecode.c
#include <stdio.h>
#include <math.h>
#include <ltc.h>
#ifdef _WIN32
#include <fcntl.h> // for _fmode
#endif
#define BUFFER_SIZE (1024)
int main(int argc, char **argv) {
int apv = 1920;
ltcsnd_sample_t sound[BUFFER_SIZE];
size_t n;
long int total;
FILE* f;
char* filename;
LTCDecoder *decoder;
LTCFrameExt frame;
if (argc > 1) {
filename = argv[1];
if (argc > 2) {
sscanf(argv[2], "%i", &apv);
}
} else {
printf("Usage: %s <filename> [audio-frames-per-video-frame]\n", argv[0]);
return -1;
}
#ifdef _WIN32
// see https://msdn.microsoft.com/en-us/library/ktss1a9b.aspx and
// https://github.com/x42/libltc/issues/18
_set_fmode(_O_BINARY);
#endif
f = fopen(filename, "r");
if (!f) {
fprintf(stderr, "error opening '%s'\n", filename);
return -1;
}
fprintf(stderr, "* reading from: %s\n", filename);
total = 0;
decoder = ltc_decoder_create(apv, 32);
do {
n = fread(sound, sizeof(ltcsnd_sample_t), BUFFER_SIZE, f);
ltc_decoder_write(decoder, sound, n, total);
while (ltc_decoder_read(decoder, &frame)) {
SMPTETimecode stime;
ltc_frame_to_time(&stime, &frame. ltc, 1);
printf("%04d-%02d-%02d %s ",
((stime. years < 67) ? 2000+stime.years : 1900+stime.years),
stime. months,
stime. days,
stime. timezone
);
printf("%02d:%02d:%02d%c%02d | %8lld %8lld%s\n",
stime. hours,
stime. mins,
stime. secs,
(frame.ltc. dfbit) ? '.' : ':',
stime. frame,
frame. off_start,
frame. off_end,
frame. reverse ? " R" : ""
);
}
total += n;
} while (n);
fclose(f);
ltc_decoder_free(decoder);
return 0;
}
ltc.h
libltc - en+decode linear timecode
LTCFrameExt::off_end
ltc_off_t off_end
the sample in the stream corresponding to the end of the LTC frame.
Definition ltc.h:302
ltc_decoder_create
LTCDecoder * ltc_decoder_create(int apv, int queue_size)
SMPTETimecode::frame
unsigned char frame
sub-second frame 0..(FPS - 1)
Definition ltc.h:327
ltcsnd_sample_t
unsigned char ltcsnd_sample_t
Definition ltc.h:88
SMPTETimecode::months
unsigned char months
valid months are 1..12
Definition ltc.h:321
SMPTETimecode::mins
unsigned char mins
minute 0..60
Definition ltc.h:325
ltc_decoder_read
int ltc_decoder_read(LTCDecoder *d, LTCFrameExt *frame)
SMPTETimecode::hours
unsigned char hours
hour 0..23
Definition ltc.h:324
LTCFrameExt::off_start
ltc_off_t off_start
the approximate sample in the stream corresponding to the start of the LTC frame.
Definition ltc.h:301
ltc_frame_to_time
void ltc_frame_to_time(SMPTETimecode *stime, LTCFrame *frame, int flags)
LTCFrameExt::reverse
int reverse
if non-zero, a reverse played LTC frame was detected. Since the frame was reversed,...
Definition ltc.h:303
LTCFrameExt::ltc
LTCFrame ltc
the actual LTC frame. see LTCFrame
Definition ltc.h:300
SMPTETimecode::days
unsigned char days
day of month 1..31
Definition ltc.h:322
LTCFrame::dfbit
unsigned int dfbit
indicated drop-frame timecode
Definition ltc.h:229
ltc_decoder_write
void ltc_decoder_write(LTCDecoder *d, ltcsnd_sample_t *buf, size_t size, ltc_off_t posinfo)
SMPTETimecode::timezone
char timezone[6]
the timezone 6bytes: "+HHMM" textual representation
Definition ltc.h:319
SMPTETimecode::secs
unsigned char secs
second 0..60
Definition ltc.h:326
LTCDecoder
struct LTCDecoder LTCDecoder
Definition ltc.h:340
ltc_decoder_free
int ltc_decoder_free(LTCDecoder *d)
SMPTETimecode::years
unsigned char years
LTC-date uses 2-digit year 00.99.
Definition ltc.h:320
LTCFrameExt
Definition ltc.h:299
SMPTETimecode
Definition ltc.h:318