Skip to content

Instantly share code, notes, and snippets.

@nu774
Created May 3, 2014 12:58
Show Gist options
  • Save nu774/dd9b3eedd1fc37e08993 to your computer and use it in GitHub Desktop.
Save nu774/dd9b3eedd1fc37e08993 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <lsmash.h>
#define BAILIF(expr) \
do { \
if (expr) { \
fprintf(stderr, "ERROR: %s\n", #expr); \
exit(2); \
} \
} while (0)
int main(int argc, char **argv)
{
lsmash_root_t *root;
lsmash_file_parameters_t file_params = { 0 };
lsmash_file_t *file;
BAILIF(argc == 1);
BAILIF((root = lsmash_create_root()) == NULL);
BAILIF(lsmash_open_file(argv[1], 1, &file_params));
BAILIF((file = lsmash_set_file(root, &file_params)) == NULL);
BAILIF(lsmash_read_file(file, &file_params) < 0);
char *title;
double seconds;
uint32_t count = lsmash_count_tyrant_chapter(root);
fprintf(stderr, "%u chapters found\n", count);
for (uint32_t i = 1;
(title = lsmash_get_tyrant_chapter(root, i, &seconds)) != NULL;
++i)
{
int hh = seconds / 3600;
seconds -= hh * 3600;
int mm = seconds / 60;
seconds -= mm * 60;
fprintf(stderr, "%02d:%02d:%06.3f %s\n", hh, mm, seconds, title);
}
lsmash_destroy_root(root);
lsmash_close_file(&file_params);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment