mask mousewheel segv bug, mask opengl sw fallback read to ram, fix tiff config withou...
[goodguy/cinelerra.git] / cinelerra-5.1 / libzmpeg3 / mpeg3toc.C
1 // New version.
2 // Very basic table of contents utility since most of the time it's going to be
3 // built inside a graphical program.
4 #include "libzmpeg3.h"
5 #include <stdint.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <signal.h>
10
11 int done;
12
13 void sigint(int n)
14 {
15   done = 1;
16 }
17
18 void thumbnail(int track)
19 {
20 #if 0
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);
28   fclose(fp);
29 #endif
30 }
31
32 int main(int argc, char *argv[])
33 {
34   int i;
35   char *src = 0, *dst = 0;
36   int program = 0;
37   int verbose = 0;
38
39   if(argc < 3) {
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"
43       "\n"
44       "-v Print tracking information\n"
45       "-p <n> program number (default 0)\n"
46       "\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",
53       mpeg3_major(),
54       mpeg3_minor(),
55       mpeg3_release());
56     exit(1);
57   }
58
59   for( i=1; i<argc; ++i ) {
60     if( !strcmp(argv[i], "-v") ) {
61       verbose = 1;
62     }
63     else if( !strcmp(argv[i], "-p") ) {
64       if( ++i < argc ) program = atoi(argv[i]);
65     }
66     else if(argv[i][0] == '-') {
67       fprintf(stderr, "Unrecognized command %s\n", argv[i]);
68       exit(1);
69     }
70     else if(!src) {
71       src = argv[i];
72     }
73     else if(!dst) {
74       dst = argv[i];
75     }
76     else {
77       fprintf(stderr, "Ignoring argument \"%s\"\n", argv[i]);
78     }
79   }
80
81   if(!src) {
82     fprintf(stderr, "source path not supplied.\n");
83     exit(1);
84   }
85
86   if(!dst) {
87     fprintf(stderr, "destination path not supplied.\n");
88     exit(1);
89   }
90
91   int64_t total_bytes;
92   zmpeg3_t *file = mpeg3_start_toc(src, dst, program, &total_bytes);
93   if(!file) exit(1);
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);
99   done = 0;
100   signal(SIGINT, sigint);
101   //mpeg3_set_thumbnail_callback(file, thumbnail);
102   mpeg3_set_cpus(file, 3);
103   
104   while(!done) {
105     int64_t bytes_processed = 0;
106     mpeg3_do_toc(file, &bytes_processed);
107
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,
115         eta / 60, eta % 60);
116       fflush(stdout);
117       prev_time = new_time;
118     }
119
120     if(bytes_processed >= total_bytes) break;
121   }
122
123   mpeg3_stop_toc(file);
124   gettimeofday(&new_time, 0);
125   int64_t elapsed = new_time.tv_sec - start_time.tv_sec;
126   if(verbose) {
127     fprintf(stderr,"%jdm%jds elapsed           \n", 
128       elapsed / 60, elapsed % 60);
129   }
130
131   return 0;
132 }
133