2 #include "mpeg3protos.h"
8 void test_32bit_overflow(char *outfile
, int (*out_counter
), FILE *(*out
))
10 if(ftell(*out
) > 0x7f000000)
14 sprintf(string
, "%s%03d", outfile
, ++(*out_counter
));
15 (*out
) = fopen(string
, "wb");
19 int main(int argc
, char *argv
[])
23 unsigned char *output
, **output_rows
;
25 float *audio_output_f
;
26 unsigned char *audio_output_i
;
27 long total_samples
= 0;
30 int decompress_audio
= 0, decompress_video
= 0;
32 /* Print cell offsets */
33 int print_offsets
= 0;
40 "Dump information or extract audio to a 24 bit pcm file.\n"
41 "Example: dump -a0 outputfile.pcm take1.vob\n"
46 for(i
= 1; i
< argc
; i
++)
48 if(!strncmp(argv
[i
], "-a", 2))
50 // Check for track number
51 if(strlen(argv
[i
]) > 2)
53 audio_track
= atol(argv
[i
] + 2);
59 strcpy(outfile
, argv
[++i
]);
64 fprintf(stderr
, "-a must be paired with a filename.\n");
68 // Check if file exists
69 if(out
= fopen(outfile
, "r"))
71 fprintf(stderr
, "%s exists.\n", outfile
);
78 file
= mpeg3_open(argv
[argc
- 1], &error
);
81 out
= fopen(outfile
, "wb");
95 fprintf(stderr
, "total_astreams=%d\n", mpeg3_total_astreams(file
));
97 for(i
= 0; i
< mpeg3_total_astreams(file
); i
++)
99 fprintf(stderr
, " Stream 0x%04x: channels=%d rate=%d samples=%ld format=%s\n",
100 file
->atrack
[i
]->demuxer
->astream
,
101 mpeg3_audio_channels(file
, i
),
102 mpeg3_sample_rate(file
, i
),
103 mpeg3_audio_samples(file
, i
),
104 mpeg3_audio_format(file
, i
));
108 fprintf(stderr
, "total_sample_offsets=%d\n", file
->atrack
[i
]->total_sample_offsets
);
109 for(j
= 0; j
< file
->atrack
[i
]->total_sample_offsets
; j
++)
111 fprintf(stderr
, "%llx ", file
->atrack
[i
]->sample_offsets
[j
]);
112 if(j
> 0 && !(j
% 8)) fprintf(stderr
, "\n");
114 fprintf(stderr
, "\n");
121 fprintf(stderr
, "total_vstreams=%d\n", mpeg3_total_vstreams(file
));
123 for(i
= 0; i
< mpeg3_total_vstreams(file
); i
++)
125 fprintf(stderr
, " Stream 0x%04x: w=%d h=%d framerate=%0.3f frames=%ld coding=%s\n",
126 file
->vtrack
[i
]->demuxer
->vstream
,
127 mpeg3_video_width(file
, i
),
128 mpeg3_video_height(file
, i
),
129 mpeg3_frame_rate(file
, i
),
130 mpeg3_video_frames(file
, i
),
131 mpeg3_colormodel(file
, i
) == MPEG3_YUV420P
? "420" : "422");
135 fprintf(stderr
, "total_frame_offsets=%d\n", file
->vtrack
[i
]->total_frame_offsets
);
136 for(j
= 0; j
< file
->vtrack
[i
]->total_frame_offsets
; j
++)
138 fprintf(stderr
, "%d=%llx ", j
, file
->vtrack
[i
]->frame_offsets
[j
]);
139 if(j
> 0 && !(j
% 8)) fprintf(stderr
, "\n");
141 fprintf(stderr
, "\n");
143 fprintf(stderr
, "total_keyframe_numbers=%d\n", file
->vtrack
[i
]->total_keyframe_numbers
);
144 for(j
= 0; j
< file
->vtrack
[i
]->total_keyframe_numbers
; j
++)
146 fprintf(stderr
, "%lld ", file
->vtrack
[i
]->keyframe_numbers
[j
]);
147 if(j
> 0 && !(j
% 8)) fprintf(stderr
, "\n");
149 fprintf(stderr
, "\n");
154 printf("total subtitle tracks: %d\n", mpeg3_subtitle_tracks(file
));
155 for(i
= 0; i
< mpeg3_subtitle_tracks(file
); i
++)
157 mpeg3_strack_t
*strack
= file
->strack
[i
];
158 printf(" stream: 0x%02x total_offsets: %d\n",
160 strack
->total_offsets
);
163 for(j
= 0; j
< strack
->total_offsets
; j
++)
165 printf("%llx ", strack
->offsets
[j
]);
172 fprintf(stderr
, "total_titles=%d\n", file
->demuxer
->total_titles
);
173 for(i
= 0; i
< file
->demuxer
->total_titles
; i
++)
175 fprintf(stderr
, " Title path=%s total_bytes=%llx cell_table_size=%d\n",
176 file
->demuxer
->titles
[i
]->fs
->path
,
177 file
->demuxer
->titles
[i
]->total_bytes
,
178 file
->demuxer
->titles
[i
]->cell_table_size
);
182 for(j
= 0; j
< file
->demuxer
->titles
[i
]->cell_table_size
; j
++)
183 fprintf(stderr
, " Cell: %llx-%llx %llx-%llx program=%d\n",
184 file
->demuxer
->titles
[i
]->cell_table
[j
].program_start
,
185 file
->demuxer
->titles
[i
]->cell_table
[j
].program_end
,
186 file
->demuxer
->titles
[i
]->cell_table
[j
].title_start
,
187 file
->demuxer
->titles
[i
]->cell_table
[j
].title_end
,
188 file
->demuxer
->titles
[i
]->cell_table
[j
].program
);
197 mpeg3_demuxer_t
*demuxer
= file
->demuxer
;
198 printf("Total PIDs=%d\n", demuxer
->total_pids
);
199 for(i
= 0; i
< demuxer
->total_pids
; i
++)
201 printf("0x%04x ", demuxer
->pid_table
[i
]);
211 mpeg3_set_cpus(file
, 2);
212 audio_output_f
= malloc(BUFSIZE
* sizeof(float));
213 audio_output_i
= malloc(BUFSIZE
* 3 * mpeg3_audio_channels(file
, audio_track
));
215 //printf("%d\n", mpeg3_end_of_audio(file, audio_track));
216 while(!mpeg3_end_of_audio(file
, audio_track
) && !result
)
218 test_32bit_overflow(outfile
, &out_counter
, &out
);
220 for(i
= 0; i
< mpeg3_audio_channels(file
, audio_track
); i
++)
223 result
= mpeg3_read_audio(file
,
230 result
= mpeg3_reread_audio(file
,
231 audio_output_f
, /* Pointer to pre-allocated buffer of floats */
232 0, /* Pointer to pre-allocated buffer of int16's */
233 i
, /* Channel to decode */
234 BUFSIZE
, /* Number of samples to decode */
237 for(j
= 0; j
< BUFSIZE
; j
++)
239 int sample
= audio_output_f
[j
] * 0x7fffff;
240 unsigned char *output_i
= audio_output_i
+ j
* 3 * mpeg3_audio_channels(file
, audio_track
) + i
* 3;
241 if(sample
> 0x7fffff)
244 if(sample
< -0x7fffff)
246 *output_i
++ = (sample
& 0xff0000) >> 16;
247 *output_i
++ = (sample
& 0xff00) >> 8;
248 *output_i
= sample
& 0xff;
253 result
= !fwrite(audio_output_i
, BUFSIZE
* 3 * mpeg3_audio_channels(file
, audio_track
), 1, out
);
258 * audio_output_i = malloc(BUFSIZE * 2 * mpeg3_audio_channels(file, 0));
259 * mpeg3_seek_percentage(file, 0.1);
260 * result = mpeg3_read_audio(file, 0, audio_output_i, 1, BUFSIZE, 0);
264 * output = malloc(mpeg3_video_width(file, 0) * mpeg3_video_height(file, 0) * 3 + 4);
265 * output_rows = malloc(sizeof(unsigned char*) * mpeg3_video_height(file, 0));
266 * for(i = 0; i < mpeg3_video_height(file, 0); i++)
267 * output_rows[i] = &output[i * mpeg3_video_width(file, 0) * 3];
268 * printf("dump 1\n");
269 * mpeg3_seek_percentage(file, 0.375);
270 * result = mpeg3_read_frame(file,
274 * mpeg3_video_width(file, 0),
275 * mpeg3_video_height(file, 0),
276 * mpeg3_video_width(file, 0),
277 * mpeg3_video_height(file, 0),
280 * printf("dump 2\n");