2 #include "mpeg3protos.h"
7 void test_32bit_overflow(char *outfile
, int (*out_counter
), FILE *(*out
))
9 if(ftell(*out
) > 0x7f000000)
13 sprintf(string
, "%s%03d", outfile
, ++(*out_counter
));
14 (*out
) = fopen(string
, "wb");
18 int main(int argc
, char *argv
[])
22 unsigned char *output
, **output_rows
;
24 float *audio_output_f
;
25 unsigned char *audio_output_i
;
26 long total_samples
= 0;
29 int decompress_audio
= 0, decompress_video
= 0;
31 /* Print cell offsets */
32 int print_offsets
= 1;
39 "Dump information or extract audio to a 24 bit pcm file.\n"
40 "Example: dump -a0 outputfile.pcm take1.vob\n"
45 for(i
= 1; i
< argc
; i
++)
47 if(!strncmp(argv
[i
], "-a", 2))
49 // Check for track number
50 if(strlen(argv
[i
]) > 2)
52 audio_track
= atol(argv
[i
] + 2);
58 strcpy(outfile
, argv
[++i
]);
63 fprintf(stderr
, "-a must be paired with a filename.\n");
67 // Check if file exists
68 if(out
= fopen(outfile
, "r"))
70 fprintf(stderr
, "%s exists.\n", outfile
);
76 file
= mpeg3_open(argv
[argc
- 1]);
79 out
= fopen(outfile
, "wb");
93 fprintf(stderr
, "have_mmx=%d\n", file
->have_mmx
);
94 fprintf(stderr
, "total_astreams=%d\n", mpeg3_total_astreams(file
));
96 for(i
= 0; i
< mpeg3_total_astreams(file
); i
++)
98 fprintf(stderr
, " Stream 0x%04x: channels=%d rate=%d samples=%ld format=%s\n",
99 file
->atrack
[i
]->demuxer
->astream
,
100 mpeg3_audio_channels(file
, i
),
101 mpeg3_sample_rate(file
, i
),
102 mpeg3_audio_samples(file
, i
),
103 mpeg3_audio_format(file
, i
));
107 fprintf(stderr
, "total_sample_offsets=%d\n", file
->atrack
[i
]->total_sample_offsets
);
108 for(j
= 0; j
< file
->atrack
[i
]->total_sample_offsets
; j
++)
110 fprintf(stderr
, "%llx ", file
->atrack
[i
]->sample_offsets
[j
]);
111 if(j
> 0 && !(j
% 8)) fprintf(stderr
, "\n");
113 fprintf(stderr
, "\n");
120 fprintf(stderr
, "total_vstreams=%d\n", mpeg3_total_vstreams(file
));
122 for(i
= 0; i
< mpeg3_total_vstreams(file
); i
++)
124 fprintf(stderr
, " Stream 0x%04x: w=%d h=%d framerate=%0.3f frames=%ld coding=%s\n",
125 file
->vtrack
[i
]->demuxer
->vstream
,
126 mpeg3_video_width(file
, i
),
127 mpeg3_video_height(file
, i
),
128 mpeg3_frame_rate(file
, i
),
129 mpeg3_video_frames(file
, i
),
130 mpeg3_colormodel(file
, i
) == MPEG3_YUV420P
? "420" : "422");
134 fprintf(stderr
, "total_frame_offsets=%d\n", file
->vtrack
[i
]->total_frame_offsets
);
135 for(j
= 0; j
< file
->vtrack
[i
]->total_frame_offsets
; j
++)
137 fprintf(stderr
, "%d=%llx ", j
, file
->vtrack
[i
]->frame_offsets
[j
]);
138 if(j
> 0 && !(j
% 8)) fprintf(stderr
, "\n");
140 fprintf(stderr
, "\n");
142 fprintf(stderr
, "total_keyframe_numbers=%d\n", file
->vtrack
[i
]->total_keyframe_numbers
);
143 for(j
= 0; j
< file
->vtrack
[i
]->total_keyframe_numbers
; j
++)
145 fprintf(stderr
, "%lld ", file
->vtrack
[i
]->keyframe_numbers
[j
]);
146 if(j
> 0 && !(j
% 8)) fprintf(stderr
, "\n");
148 fprintf(stderr
, "\n");
154 fprintf(stderr
, "total_titles=%d\n", file
->demuxer
->total_titles
);
155 for(i
= 0; i
< file
->demuxer
->total_titles
; i
++)
157 fprintf(stderr
, " Title path=%s total_bytes=%llx cell_table_size=%d\n",
158 file
->demuxer
->titles
[i
]->fs
->path
,
159 file
->demuxer
->titles
[i
]->total_bytes
,
160 file
->demuxer
->titles
[i
]->timecode_table_size
);
164 for(j
= 0; j
< file
->demuxer
->titles
[i
]->timecode_table_size
; j
++)
165 fprintf(stderr
, " Cell: %llx-%llx program=%d\n",
166 file
->demuxer
->titles
[i
]->timecode_table
[j
].start_byte
,
167 file
->demuxer
->titles
[i
]->timecode_table
[j
].end_byte
,
168 file
->demuxer
->titles
[i
]->timecode_table
[j
].program
);
177 mpeg3_demuxer_t
*demuxer
= file
->demuxer
;
178 printf("Total PIDs=%d\n", demuxer
->total_pids
);
179 for(i
= 0; i
< demuxer
->total_pids
; i
++)
181 printf("0x%04x ", demuxer
->pid_table
[i
]);
191 mpeg3_set_cpus(file
, 2);
192 audio_output_f
= malloc(BUFSIZE
* sizeof(float));
193 audio_output_i
= malloc(BUFSIZE
* 3 * mpeg3_audio_channels(file
, audio_track
));
195 //printf("%d\n", mpeg3_end_of_audio(file, audio_track));
196 while(!mpeg3_end_of_audio(file
, audio_track
) && !result
)
198 test_32bit_overflow(outfile
, &out_counter
, &out
);
200 for(i
= 0; i
< mpeg3_audio_channels(file
, audio_track
); i
++)
203 result
= mpeg3_read_audio(file
,
210 result
= mpeg3_reread_audio(file
,
211 audio_output_f
, /* Pointer to pre-allocated buffer of floats */
212 0, /* Pointer to pre-allocated buffer of int16's */
213 i
, /* Channel to decode */
214 BUFSIZE
, /* Number of samples to decode */
217 for(j
= 0; j
< BUFSIZE
; j
++)
219 int sample
= audio_output_f
[j
] * 0x7fffff;
220 unsigned char *output_i
= audio_output_i
+ j
* 3 * mpeg3_audio_channels(file
, audio_track
) + i
* 3;
221 if(sample
> 0x7fffff)
224 if(sample
< -0x7fffff)
226 *output_i
++ = (sample
& 0xff0000) >> 16;
227 *output_i
++ = (sample
& 0xff00) >> 8;
228 *output_i
= sample
& 0xff;
233 result
= !fwrite(audio_output_i
, BUFSIZE
* 3 * mpeg3_audio_channels(file
, audio_track
), 1, out
);
238 * audio_output_i = malloc(BUFSIZE * 2 * mpeg3_audio_channels(file, 0));
239 * mpeg3_seek_percentage(file, 0.1);
240 * result = mpeg3_read_audio(file, 0, audio_output_i, 1, BUFSIZE, 0);
244 * output = malloc(mpeg3_video_width(file, 0) * mpeg3_video_height(file, 0) * 3 + 4);
245 * output_rows = malloc(sizeof(unsigned char*) * mpeg3_video_height(file, 0));
246 * for(i = 0; i < mpeg3_video_height(file, 0); i++)
247 * output_rows[i] = &output[i * mpeg3_video_width(file, 0) * 3];
248 * printf("dump 1\n");
249 * mpeg3_seek_percentage(file, 0.375);
250 * result = mpeg3_read_frame(file,
254 * mpeg3_video_width(file, 0),
255 * mpeg3_video_height(file, 0),
256 * mpeg3_video_width(file, 0),
257 * mpeg3_video_height(file, 0),
260 * printf("dump 2\n");