libcmml 0.9.1
cmml-seek-offset.c

Seeking to a temporal offset into a CMML file

Sometimes you'll need to seek to a temporal offset in seconds into a CMML file. Note: The seconds offset is calculated with respect to the basetime attribute of the stream tag. libcmml provides an API for this functionality through the cmml_skip_to_secs() function.

The procedure is illustrated in cmml-seek-offset.c, which seeks to an offset given in seconds and prints out the descriptions of all the following clips:

#include <stdio.h>
#include <cmml.h>
#define BUFSIZE 100000
static int
read_clip (CMML * cmml, const CMML_Clip * clip, void * user_data) {
puts(clip->desc_text);
return 0;
}
int main(int argc, char *argv[])
{
char *filename = NULL;
CMML * doc;
double seconds = 0.0;
long n = 0;
if (argc < 2) {
fprintf (stderr, "Usage: %s <CMMLfile> <seconds>\n", argv[0]);
exit (1);
}
filename = argv[1];
if (argv[2]) seconds = atof(argv[2]);
doc = cmml_open(filename);
/* seek to time offset; if not found, to file end */
cmml_skip_to_secs (doc, seconds);
cmml_set_read_callbacks (doc, NULL, NULL, read_clip, NULL);
while (((n = cmml_read (doc, BUFSIZE)) > 0));
cmml_close(doc);
return 0;
}
int main(int argc, char *argv[])
Definition: cmml-validate.c:212
static int read_clip(CMML *cmml, const CMML_Clip *clip, void *user_data)
Definition: cmml-validate.c:189
#define BUFSIZE
Definition: cmml-validate.c:79
void CMML
Definition: cmml.h:50
double cmml_skip_to_secs(CMML *cmml, double seconds)
CMML * cmml_close(CMML *cmml)
long cmml_read(CMML *cmml, long n)
CMML * cmml_open(char *XMLfilename)
int cmml_set_read_callbacks(CMML *cmml, CMMLReadStream read_stream, CMMLReadHead read_head, CMMLReadClip read_clip, void *user_data)
Definition: cmml.h:242
char * desc_text
Definition: cmml.h:271