Quote:
Originally Posted by @MeGui
Can we see your small program here?
|
Sure. Unrefined C code hack.
Code:
#include <stdio.h>
#include <stdlib.h>
// use: chapadd chap_start_num time_to_add chapter_file
// limitation: < 100 chapters
int main(int argc, char **argv) {
int hour, min, sec, thousands;
int chap_num;
int h, m, s, t;
FILE *fp;
char buffer[128];
if (argc != 4) {
fprintf(stderr, "Usage: chapadd chapter_start start_time chapter_file\n");
fprintf(stderr, " - chapter_start: the new chapter to start at\n");
fprintf(stderr, " - start_time: length of first movie file [hh:mm:ss.hhh]\n");
fprintf(stderr, " - chapter_file: OGG chapter file to rewrite\n");
return 0;
}
chap_num = atoi(argv[1]);
sscanf(argv[2], "%d:%d:%d.%d", &hour, &min, &sec, &thousands);
fp = fopen(argv[3], "rt");
if (fp == NULL) {
fprintf(stderr, "Error opening OGG chapter file.\n");
return 0;
}
// Loop through chapter file
// Expected input format:
// CHAPTERnn=hh:mm:ss.hhh
// CHAPTERnnNAME=Chapter n
while (fgets(buffer, 128, fp) != NULL) {
sscanf(&buffer[10], "%d:%d:%d.%d", &h, &m, &s, &t);
t += thousands;
if (t >= 1000) {
s++;
t -= 1000;
}
s += sec;
if (s >= 60) {
m++;
s -= 60;
}
m += min;
if (m >= 60) {
h++;
m -= 60;
}
h += hour;
// output new chapter data to stdout (user can copy/paste from there)
printf("CHAPTER%02d=%02d:%02d:%02d.%03d\n", chap_num,
h, m, s, t);
printf("CHAPTER%02dNAME=Chapter %d\n", chap_num, chap_num);
chap_num++;
fgets(buffer, 128, fp); // discard the second line of each chapter
}
fclose(fp);
return 0;
}