7 void test_32bit_overflow(char *outfile, int (*out_counter), FILE *(*out))
9 if( ftell(*out) > 0x7f000000 ) {
12 sprintf(string, "%s%03d", outfile, ++(*out_counter));
13 (*out) = fopen(string, "wb");
17 int main(int argc, char *argv[])
20 int i, j, len, result = 0;
22 float *audio_output_f;
23 unsigned char *audio_output_i;
26 int decompress_audio = 0;
28 /* Print cell offsets */
29 int print_offsets = 0;
34 printf( "Dump information or extract audio to a 24 bit pcm file.\n"
35 "Example: dump -a0 outputfile.pcm take1.vob\n");
39 for( i=1; i < argc; ++i ) {
40 if( !strncmp(argv[i], "-a", 2) ) {
41 // Check for track number
42 if( strlen(argv[i]) > 2 ) {
43 audio_track = atol(argv[i] + 2);
48 strcpy(outfile, argv[++i]);
52 fprintf(stderr, "-a must be paired with a filename.\n");
56 // Check if file exists
57 if( (out = fopen(outfile, "r")) ) {
58 fprintf(stderr, "%s exists.\n", outfile);
65 file = mpeg3_open(argv[argc - 1], &error);
67 out = fopen(outfile, "wb");
73 fprintf(stderr, "total_astreams=%d\n", mpeg3_total_astreams(file));
75 for( i=0; i < mpeg3_total_astreams(file); ++i ) {
76 fprintf(stderr, " Stream 0x%04x: channels=%d rate=%d samples=%ld format=%s\n",
77 file->atrack[i]->demuxer->astream,
78 mpeg3_audio_channels(file, i),
79 mpeg3_sample_rate(file, i),
80 mpeg3_audio_samples(file, i),
81 mpeg3_audio_format(file, i));
84 fprintf(stderr, "total_sample_offsets=%d\n", file->atrack[i]->total_sample_offsets);
85 for( j=0; j < file->atrack[i]->total_sample_offsets; ++j ) {
86 fprintf(stderr, "%jx ", file->atrack[i]->sample_offsets[j]);
87 if( j > 0 && !(j % 8)) fprintf(stderr, "\n" );
89 fprintf(stderr, "\n");
94 fprintf(stderr, "total_vstreams=%d\n", mpeg3_total_vstreams(file));
96 for( i=0; i < mpeg3_total_vstreams(file); ++i ) {
97 fprintf(stderr, " Stream 0x%04x: w=%d h=%d framerate=%0.3f frames=%ld coding=%s\n",
98 file->vtrack[i]->demuxer->vstream,
99 mpeg3_video_width(file, i),
100 mpeg3_video_height(file, i),
101 mpeg3_frame_rate(file, i),
102 mpeg3_video_frames(file, i),
103 mpeg3_colormodel(file, i) == zmpeg3_t::cmdl_YUV420P ? "420" : "422");
105 if( print_offsets ) {
106 fprintf(stderr, "total_frame_offsets=%d\n", file->vtrack[i]->total_frame_offsets);
107 for( j=0; j < file->vtrack[i]->total_frame_offsets; ++j ) {
108 fprintf(stderr, "%d=%jx ", j, file->vtrack[i]->frame_offsets[j]);
109 if( j > 0 && !(j % 8)) fprintf(stderr, "\n" );
111 fprintf(stderr, "\n");
113 fprintf(stderr, "total_keyframe_numbers=%d\n", file->vtrack[i]->total_keyframe_numbers);
114 for( j=0; j < file->vtrack[i]->total_keyframe_numbers; ++j ) {
115 fprintf(stderr, "%d ", file->vtrack[i]->keyframe_numbers[j]);
116 if( j > 0 && !(j % 8)) fprintf(stderr, "\n" );
118 fprintf(stderr, "\n");
123 printf("total subtitle tracks: %d\n", mpeg3_subtitle_tracks(file));
124 for( i=0; i < mpeg3_subtitle_tracks(file); ++i ) {
125 zstrack_t *strack = file->strack[i];
126 printf(" stream: 0x%02x total_offsets: %d\n",
127 strack->id, strack->total_offsets);
128 if( print_offsets ) {
129 for( j=0; j < strack->total_offsets; ++j ) {
130 printf("%jx ", strack->offsets[j]);
137 fprintf(stderr, "total_titles=%d\n", file->demuxer->total_titles);
138 for( i=0; i < file->demuxer->total_titles; ++i ) {
139 fprintf(stderr, " Title path=%s total_bytes=%jx cell_table_size=%d\n",
140 file->demuxer->titles[i]->fs->path,
141 file->demuxer->titles[i]->total_bytes,
142 file->demuxer->titles[i]->cell_table_size);
144 if( print_offsets ) {
145 for( j=0; j < file->demuxer->titles[i]->cell_table_size; ++j )
146 fprintf(stderr, " Cell: %jx-%jx %jx-%jx\n",
147 file->demuxer->titles[i]->cell_table[j].program_start,
148 file->demuxer->titles[i]->cell_table[j].program_end,
149 file->demuxer->titles[i]->cell_table[j].title_start,
150 file->demuxer->titles[i]->cell_table[j].title_end);
156 zdemuxer_t *demuxer = file->demuxer;
157 printf("Total PIDs=%d\n", demuxer->total_pids);
158 for( i=0; i < demuxer->total_pids; ++i ) {
159 printf("0x%04x ", demuxer->pid_table[i]);
165 if( decompress_audio ) {
166 mpeg3_set_cpus(file, 2);
167 audio_output_f = new float[BUFSIZE];
168 len = BUFSIZE * 3 * mpeg3_audio_channels(file, audio_track);
169 audio_output_i = new unsigned char[len];
171 //printf("%d\n", mpeg3_end_of_audio(file, audio_track));
172 while( !mpeg3_end_of_audio(file, audio_track) && !result ) {
173 test_32bit_overflow(outfile, &out_counter, &out);
175 for( i=0; i < mpeg3_audio_channels(file, audio_track); ++i ) {
177 result = mpeg3_read_audio(file, audio_output_f,
178 0, i, BUFSIZE, audio_track);
179 else /* Pointer to pre-allocated buffer of floats */
180 result = mpeg3_reread_audio(file, audio_output_f,
181 0, i, BUFSIZE, audio_track);
182 for( j=0; j < BUFSIZE; ++j ) {
183 int sample = audio_output_f[j] * 0x7fffff;
184 unsigned char * output_i = audio_output_i + j * 3 *
185 mpeg3_audio_channels(file, audio_track) + i * 3;
186 if( sample > 0x7fffff )
188 else if( sample < -0x7fffff )
190 *output_i++ = (sample & 0xff0000) >> 16;
191 *output_i++ = (sample & 0xff00) >> 8;
192 *output_i = sample & 0xff;
196 len = BUFSIZE * 3 * mpeg3_audio_channels(file, audio_track);
197 result = !fwrite(audio_output_i, len, 1, out);
202 * len = BUFSIZE * 2 * mpeg3_audio_channels(file, 0);
203 * audio_output_i = unsigned char[len];
204 * mpeg3_seek_percentage(file, 0.1);
205 * result = mpeg3_read_audio(file, 0, audio_output_i, 1, BUFSIZE, 0);
209 * len = mpeg3_video_width(file, 0) * mpeg3_video_height(file, 0) * 3 + 4;
210 * output = unsigned char[len];
211 * len = sizeof(unsigned char*) * mpeg3_video_height(file, 0);
212 * output_rows = unsigned char *[len];
213 * for( i=0; i < mpeg3_video_height(file, 0); ++i )
214 * output_rows[i] = &output[i * mpeg3_video_width(file, 0) * 3];
215 * printf("dump 1\n");
216 * mpeg3_seek_percentage(file, 0.375);
217 * result = mpeg3_read_frame(file,
221 * mpeg3_video_width(file, 0),
222 * mpeg3_video_height(file, 0),
223 * mpeg3_video_width(file, 0),
224 * mpeg3_video_height(file, 0),
227 * printf("dump 2\n");