2 // Very basic table of contents utility since most of the time it's going to be
3 // built inside a graphical program.
18 void thumbnail(int track)
21 int64_t framenum; uint8_t *tdat; int mw, mh;
22 mpeg3_get_thumbnail(track, &framenum, &tdat, &mw, &mh);
23 char fn[256]; FILE *fp;
24 sprintf(fn,"/tmp/dat/s%df%05d.pbm",track,framenum);
25 if( !(fp=fopen(fn,"w")) ) return;
26 fprintf(fp,"P5\n%d %d\n255\n",w,h);
27 fwrite(tdat,mw,mh,fp);
32 int main(int argc, char *argv[])
35 char *src = 0, *dst = 0;
40 fprintf(stderr, "Table of contents generator version %d.%d.%d\n"
41 "Create a table of contents for a DVD or mpeg stream.\n"
42 "Usage: mpeg3toc <path> <output>\n"
44 "-v Print tracking information\n"
45 "-p <n> program number (default 0)\n"
47 "The path should be absolute unless you plan\n"
48 "to always run your movie editor from the same directory\n"
49 "as the filename. For renderfarms the filesystem prefix\n"
50 "should be / and the movie directory mounted under the same\n"
51 "directory on each node.\n\n"
52 "Example: mpeg3toc -v /cdrom/video_ts/vts_01_0.ifo titanic.toc\n",
59 for( i=1; i<argc; ++i ) {
60 if( !strcmp(argv[i], "-v") ) {
63 else if( !strcmp(argv[i], "-p") ) {
64 if( ++i < argc ) program = atoi(argv[i]);
66 else if(argv[i][0] == '-') {
67 fprintf(stderr, "Unrecognized command %s\n", argv[i]);
77 fprintf(stderr, "Ignoring argument \"%s\"\n", argv[i]);
82 fprintf(stderr, "source path not supplied.\n");
87 fprintf(stderr, "destination path not supplied.\n");
92 zmpeg3_t *file = mpeg3_start_toc(src, dst, program, &total_bytes);
94 struct timeval new_time;
95 struct timeval prev_time;
96 struct timeval start_time;
97 gettimeofday(&prev_time, 0);
98 gettimeofday(&start_time, 0);
100 signal(SIGINT, sigint);
101 //mpeg3_set_thumbnail_callback(file, thumbnail);
102 mpeg3_set_cpus(file, 3);
105 int64_t bytes_processed = 0;
106 mpeg3_do_toc(file, &bytes_processed);
108 gettimeofday(&new_time, 0);
109 if( verbose && new_time.tv_sec - prev_time.tv_sec > 1 ) {
110 int64_t elapsed_seconds = new_time.tv_sec - start_time.tv_sec;
111 int64_t total_seconds = elapsed_seconds * total_bytes / bytes_processed;
112 int64_t eta = total_seconds - elapsed_seconds;
113 fprintf(stderr,"%jd%% ETA: %jdm%jds \r",
114 bytes_processed * 100 / total_bytes,
117 prev_time = new_time;
120 if(bytes_processed >= total_bytes) break;
123 mpeg3_stop_toc(file);
124 gettimeofday(&new_time, 0);
125 int64_t elapsed = new_time.tv_sec - start_time.tv_sec;
127 fprintf(stderr,"%jdm%jds elapsed \n",
128 elapsed / 60, elapsed % 60);