File: lsdvd.c

package info (click to toggle)
lsdvd 0.16-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, squeeze, wheezy
  • size: 456 kB
  • ctags: 156
  • sloc: sh: 3,509; ansic: 944; makefile: 56
file content (507 lines) | stat: -rw-r--r-- 18,470 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/*
 *  lsdvd.c
 *
 *  DVD info lister
 *
 *  Copyright (C) 2003  EFF
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation;
 *
 *  2003	by Chris Phillips
 *  2003-04-19  Cleanups get_title_name, added dvdtime2msec, added helper macros,
 *			  output info structures in form of a Perl module, by Henk Vergonet.
 */
#include <stdint.h>
#include <dvdread/ifo_read.h>
#include <string.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "lsdvd.h"
#include "ocode.h"

static struct { char code[3];	char name[20];}
language[] = {
	{ "  ", "Not Specified" }, { "aa", "Afar" },	{ "ab", "Abkhazian" }, { "af", "Afrikaans" },	{ "am", "Amharic" },
	{ "ar", "Arabic" }, { "as", "Assamese" },	{ "ay", "Aymara" }, { "az", "Azerbaijani" }, { "ba", "Bashkir" },
	{ "be", "Byelorussian" }, { "bg", "Bulgarian" }, { "bh", "Bihari" }, { "bi", "Bislama" }, { "bn", "Bengali; Bangla" },
	{ "bo", "Tibetan" }, { "br", "Breton" }, { "ca", "Catalan" }, { "co", "Corsican" }, { "cs", "Czech" },
	{ "cy", "Welsh" }, { "da", "Dansk" }, { "de", "Deutsch" }, { "dz", "Bhutani" }, { "el", "Greek" }, { "en", "English" },
	{ "eo", "Esperanto" }, { "es", "Espanol" }, { "et", "Estonian" }, { "eu", "Basque" }, { "fa", "Persian" },
	{ "fi", "Suomi" }, { "fj", "Fiji" }, { "fo", "Faroese" }, { "fr", "Francais" }, { "fy", "Frisian" }, { "ga", "Gaelic" },
	{ "gd", "Scots Gaelic" }, { "gl", "Galician" }, { "gn", "Guarani" }, { "gu", "Gujarati" }, { "ha", "Hausa" },
	{ "he", "Hebrew" }, { "hi", "Hindi" }, { "hr", "Hrvatski" }, { "hu", "Magyar" }, { "hy", "Armenian" },
	{ "ia", "Interlingua" }, { "id", "Indonesian" }, { "ie", "Interlingue" }, { "ik", "Inupiak" }, { "in", "Indonesian" },
	{ "is", "Islenska" }, { "it", "Italiano" }, { "iu", "Inuktitut" }, { "iw", "Hebrew" }, { "ja", "Japanese" },
	{ "ji", "Yiddish" }, { "jw", "Javanese" }, { "ka", "Georgian" }, { "kk", "Kazakh" }, { "kl", "Greenlandic" },
	{ "km", "Cambodian" }, { "kn", "Kannada" }, { "ko", "Korean" }, { "ks", "Kashmiri" }, { "ku", "Kurdish" },
	{ "ky", "Kirghiz" }, { "la", "Latin" }, { "ln", "Lingala" }, { "lo", "Laothian" }, { "lt", "Lithuanian" },
	{ "lv", "Latvian, Lettish" }, { "mg", "Malagasy" }, { "mi", "Maori" }, { "mk", "Macedonian" }, { "ml", "Malayalam" },
	{ "mn", "Mongolian" }, { "mo", "Moldavian" }, { "mr", "Marathi" }, { "ms", "Malay" }, { "mt", "Maltese" },
	{ "my", "Burmese" }, { "na", "Nauru" }, { "ne", "Nepali" }, { "nl", "Nederlands" }, { "no", "Norsk" }, { "oc", "Occitan" },
	{ "om", "Oromo" }, { "or", "Oriya" }, { "pa", "Punjabi" }, { "pl", "Polish" }, { "ps", "Pashto, Pushto" },
	{ "pt", "Portugues" }, { "qu", "Quechua" }, { "rm", "Rhaeto-Romance" }, { "rn", "Kirundi" }, { "ro", "Romanian"  },
	{ "ru", "Russian" }, { "rw", "Kinyarwanda" }, { "sa", "Sanskrit" }, { "sd", "Sindhi" }, { "sg", "Sangho" },
	{ "sh", "Serbo-Croatian" }, { "si", "Sinhalese" }, { "sk", "Slovak" }, { "sl", "Slovenian" }, { "sm", "Samoan" },
 	{ "sn", "Shona"  }, { "so", "Somali" }, { "sq", "Albanian" }, { "sr", "Serbian" }, { "ss", "Siswati" },
	{ "st", "Sesotho" }, { "su", "Sundanese" }, { "sv", "Svenska" }, { "sw", "Swahili" }, { "ta", "Tamil" },
	{ "te", "Telugu" }, { "tg", "Tajik" }, { "th", "Thai" }, { "ti", "Tigrinya" }, { "tk", "Turkmen" }, { "tl", "Tagalog" },
	{ "tn", "Setswana" }, { "to", "Tonga" }, { "tr", "Turkish" }, { "ts", "Tsonga" }, { "tt", "Tatar" }, { "tw", "Twi" },
	{ "ug", "Uighur" }, { "uk", "Ukrainian" }, { "ur", "Urdu" }, { "uz", "Uzbek" }, { "vi", "Vietnamese" },
	{ "vo", "Volapuk" }, { "wo", "Wolof" }, { "xh", "Xhosa" }, { "yi", "Yiddish" }, { "yo", "Yoruba" }, { "za", "Zhuang" },
	{ "zh", "Chinese" }, { "zu", "Zulu" }, { "xx", "Unknown" }, { "\0", "Unknown" } };
char *video_format[2] = {"NTSC", "PAL"};
/* 28.9.2003: Chicken run's aspect ratio is 16:9 or 1.85:1, at index
   1.  Addionaly using ' in the quoting makes the perl output not
   parse so changed to " */
char *aspect_ratio[4] = {"4/3", "16/9", "\"?:?\"", "16/9"};
char *quantization[4] = {"16bit", "20bit", "24bit", "drc"};
char *mpeg_version[2] = {"mpeg1", "mpeg2"};
/* 28.9.2003: The European chicken run title has height index 3, and
   576 lines seems right, mplayer -vop cropdetect shows from 552 to
   576 lines.  What the correct value is for index 2 is harder to say */
char *video_height[4] = {"480", "576", "???", "576"};
char *video_width[4]  = {"720", "704", "352", "352"};
char *permitted_df[4] = {"P&S + Letter", "Pan&Scan", "Letterbox", "?"};
char *audio_format[7] = {"ac3", "?", "mpeg1", "mpeg2", "lpcm ", "sdds ", "dts"};
int   audio_id[7]     = {0x80, 0, 0xC0, 0xC0, 0xA0, 0, 0x88};
/* 28.9.2003: Chicken run again, it has frequency index of 1.
   According to dvd::rip the frequency is 48000 */
char *sample_freq[2]  = {"48000", "48000"};
char *audio_type[5]   = {"Undefined", "Normal", "Impaired", "Comments1", "Comments2"};
char *subp_type[16]   = {"Undefined", "Normal", "Large", "Children", "reserved", "Normal_CC", "Large_CC", "Children_CC",
	"reserved", "Forced", "reserved", "reserved", "reserved", "Director", "Large_Director", "Children_Director"};
double frames_per_s[4] = {-1.0, 25.00, -1.0, 29.97};

char* program_name;

//extern void operl_print(struct dvd_info *dvd_info);
//extern void oxml_print(struct dvd_info *dvd_info);
//extern void oruby_print(struct dvd_info *dvd_info);
//extern void ohuman_print(struct dvd_info *dvd_info);

int dvdtime2msec(dvd_time_t *dt)
{
	double fps = frames_per_s[(dt->frame_u & 0xc0) >> 6];
	long   ms;
	ms  = (((dt->hour &   0xf0) >> 3) * 5 + (dt->hour   & 0x0f)) * 3600000;
	ms += (((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f)) * 60000;
	ms += (((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f)) * 1000;

	if(fps > 0)
	ms += ((dt->frame_u & 0x30) >> 3) * 5 + (dt->frame_u & 0x0f) * 1000.0 / fps;

	return ms;
}

/*
 * This is used to add up sets of times in the struct. it's not elegant at all
 * but a quick way to easily add up 4 times at once. tracking the times in usec's 
 * constantly is easier, but without using math.h, it sucks to actually DO anything with it
 * also it ***has*** to be better to return the playback_time, not just mess with it like this
 */
void converttime(playback_time_t *pt, dvd_time_t *dt)
{
	double fps = frames_per_s[(dt->frame_u & 0xc0) >> 6];

	pt->usec = pt->usec + ((dt->frame_u & 0x30) >> 3) * 5 + (dt->frame_u & 0x0f) * 1000.0 / fps;
	pt->second = pt->second + ((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f);
	pt->minute = pt->minute + ((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f);
	pt->hour = pt->hour + ((dt->hour &   0xf0) >> 3) * 5 + (dt->hour   & 0x0f);

	if ( pt->usec >= 1000 ) { pt->usec -= 1000; pt->second++; }
	if ( pt->second >= 60 ) { pt->second -= 60; pt->minute++; }
	if ( pt->minute > 59 ) { pt->minute -= 60; pt->hour++; }
}

/*
 *  The following method is based on code from vobcopy, by Robos, with thanks.
 */
int get_title_name(const char* dvd_device, char* title)
{
	FILE *filehandle = 0;
	int  i;

	if (! (filehandle = fopen(dvd_device, "r"))) {
		fprintf(stderr, "Couldn't open %s for title\n", dvd_device);
		strcpy(title, "unknown");
		return -1;
	}

	if ( fseek(filehandle, 32808, SEEK_SET )) {
		fclose(filehandle);
		fprintf(stderr, "Couldn't seek in %s for title\n", dvd_device);
		strcpy(title, "unknown");
		return -1;
	}

	if ( 32 != (i = fread(title, 1, 32, filehandle)) ) {
		fclose(filehandle);
		fprintf(stderr, "Couldn't read enough bytes for title.\n");
		strcpy(title, "unknown");
		return -1;
	}

	fclose (filehandle);

	title[32] = '\0';
	while(i-- > 2)
	if(title[i] == ' ') title[i] = '\0';
	return 0;
}

char* lang_name(char* code)
{
	int k=0;
	while (memcmp(language[k].code, code, 2) && language[k].name[0] ) { k++; }
	return language[k].name;
}

void version()
{
	fprintf(stderr, "lsdvd "VERSION" - GPL Copyright (c) 2002, 2003, 2004, 2005 \"Written\" by Chris Phillips <acid_kewpie@users.sf.net>\n");
}

void usage()
{
	version();
	fprintf(stderr, "Usage: %s [options] [-t track_number] [dvd path] \n", program_name);
	fprintf(stderr, "\n");
	fprintf(stderr, "Options:\n");
	fprintf(stderr, "\tExtra information:\n");
	fprintf(stderr, "\t  -a audio streams\n");
	fprintf(stderr, "\t  -d cells\n");
	fprintf(stderr, "\t  -n angles\n");
	fprintf(stderr, "\t  -c chapters\n");
	fprintf(stderr, "\t  -s subpictures\n");
	fprintf(stderr, "\t  -P palette\n");
	fprintf(stderr, "\t  -v video\n");
	fprintf(stderr, "\t  -x all information\n");
	fprintf(stderr, "\n");
	fprintf(stderr, "\tFormatting:\n");
	fprintf(stderr, "\t  -Oh output as human readable (default)\n");
	fprintf(stderr, "\t  -Op output as Perl\n");
	fprintf(stderr, "\t  -Oy output as Python\n");
	fprintf(stderr, "\t  -Or output as Ruby\n");
	fprintf(stderr, "\t  -Ox output as XML\n");
	//fprintf(stderr, "\t  -p output as Perl [deprecated]\n");
	fprintf(stderr, "\n");
	fprintf(stderr, "\tOther options:\n");
	fprintf(stderr, "\t  -q quiet - no summary totals\n");
	fprintf(stderr, "\t  -h this message\n");
	fprintf(stderr, "\t  -V version information\n");
	fprintf(stderr, "\n");
}

int opt_a=0, opt_c=0, opt_n=0, opt_p=0, opt_q=0, opt_s=0, opt_t=0, opt_v=0, opt_x=0, opt_d=0, opt_P=0;
char opt_O='h';

char output_option(char *arg)
{
	if (strlen(arg) == 1) {
		return arg[0];
	} else if (strcmp(arg, "perl") == 0) {
		return 'p';
	} else if (strcmp(arg, "python") == 0) {
		return 'y';
	} else if (strcmp(arg, "ruby") == 0) {
		return 'r';
	} else if (strcmp(arg, "ruby2") == 0) {
		return '2';
	} else if (strcmp(arg, "xml") == 0) {
		return 'x';
	} else if (strcmp(arg, "human") == 0) {
		return 'h';
	} else {
		return '\0';
	}
}
										

int main(int argc, char *argv[])
{
	char title[33];
	dvd_reader_t *dvd;
	ifo_handle_t *ifo_zero, **ifo;
	pgcit_t *vts_pgcit;
	vtsi_mat_t *vtsi_mat;
	vmgi_mat_t *vmgi_mat;
	audio_attr_t *audio_attr;
	video_attr_t *video_attr;
	subp_attr_t *subp_attr;
	pgc_t *pgc;
	int i, j, c, titles, cell, vts_ttn, title_set_nr;
 	char lang_code[3];
	char *dvd_device = "/dev/dvd";
	int has_title = 0, ret = 0;
	int max_length = 0, max_track = 0;
	struct stat dvd_stat;

	program_name = argv[0];

	while ((c = getopt(argc, argv, "acnpPqsdvt:O:xhV?")) != EOF) {
		switch (c) {
		case 'h':
		case '?':	usage();		return 0;
		case 'V':	version();		return 0;
		case 'a':	opt_a = 1;		break;
		case 'd':	opt_d = 1;		break;
		case 's':	opt_s = 1;		break;
		case 'q':	opt_q = 1;		break;
		case 'c':	opt_c = 1;		break;
		case 'n':	opt_n = 1;		break;
		case 'p':	opt_p = 1;		break;
		case 'P':	opt_P = 1;		break;
		case 't':	opt_t = atoi(optarg);	break;
		case 'O':	opt_O = output_option(optarg);	break;
		case 'v':	opt_v = 1;		break;
		case 'x':	opt_x = 1;
				opt_a = 1;
				opt_c = 1;
				opt_s = 1;
				opt_P = 1;
				opt_d = 1;
				opt_n = 1;
				opt_v = 1;		break;
		}
	}

	if (argv[optind]) { dvd_device = argv[optind];	}
	
	ret = stat(dvd_device, &dvd_stat);
	if ( ret < 0 ) {
		fprintf(stderr, "Can't find device %s\n", dvd_device);
		return 1;
	}
	
	dvd = DVDOpen(dvd_device);
	if( !dvd ) {
		fprintf( stderr, "Can't open disc %s!\n", dvd_device);
		return 2;
	}
	ifo_zero = ifoOpen(dvd, 0);
	if ( !ifo_zero ) {
		fprintf( stderr, "Can't open main ifo!\n");
		return 3;
	}

	ifo = (ifo_handle_t **)malloc((ifo_zero->vts_atrt->nr_of_vtss + 1) * sizeof(ifo_handle_t *));

	for (i=1; i <= ifo_zero->vts_atrt->nr_of_vtss; i++) {
		ifo[i] = ifoOpen(dvd, i);
		if ( !ifo[i] ) {
			fprintf( stderr, "Can't open ifo %d!\n", i);
			return 4;
		}
	}

	titles = ifo_zero->tt_srpt->nr_of_srpts;

	if ( opt_t > titles || opt_t < 0) {
		fprintf (stderr, "Only %d titles on this disc!", titles);
		return 5;
	}

	has_title = get_title_name(dvd_device, title);

	vmgi_mat = ifo_zero->vmgi_mat;

	struct dvd_info dvd_info;
		
	dvd_info.discinfo.device = dvd_device;
	dvd_info.discinfo.disc_title = has_title ? "unknown" : title;
	dvd_info.discinfo.vmg_id =  vmgi_mat->vmg_identifier;
	dvd_info.discinfo.provider_id = vmgi_mat->provider_identifier;
	
	dvd_info.title_count = titles;
	dvd_info.titles = calloc(titles, sizeof(*dvd_info.titles));

	for (j=0; j < titles; j++)
	{

	if ( opt_t == j+1 || opt_t == 0 ) {

	// GENERAL
	if (ifo[ifo_zero->tt_srpt->title[j].title_set_nr]->vtsi_mat) {

		dvd_info.titles[j].enabled = 1;

		vtsi_mat   = ifo[ifo_zero->tt_srpt->title[j].title_set_nr]->vtsi_mat;
		vts_pgcit  = ifo[ifo_zero->tt_srpt->title[j].title_set_nr]->vts_pgcit;
		video_attr = &vtsi_mat->vts_video_attr;
		vts_ttn = ifo_zero->tt_srpt->title[j].vts_ttn;
		vmgi_mat = ifo_zero->vmgi_mat;
		title_set_nr = ifo_zero->tt_srpt->title[j].title_set_nr;
		pgc = vts_pgcit->pgci_srp[ifo[title_set_nr]->vts_ptt_srpt->title[vts_ttn - 1].ptt[0].pgcn - 1].pgc;

		dvd_info.titles[j].general.length = dvdtime2msec(&pgc->playback_time)/1000.0;
		converttime(&dvd_info.titles[j].general.playback_time, &pgc->playback_time);
		dvd_info.titles[j].general.vts_id = vtsi_mat->vts_identifier;
				
		if (dvdtime2msec(&pgc->playback_time) > max_length) {
			max_length = dvdtime2msec(&pgc->playback_time);
			max_track = j+1;
		}

		dvd_info.titles[j].chapter_count_reported = ifo_zero->tt_srpt->title[j].nr_of_ptts;
		dvd_info.titles[j].cell_count = pgc->nr_of_cells;
		dvd_info.titles[j].audiostream_count = vtsi_mat->nr_of_vts_audio_streams;
		dvd_info.titles[j].subtitle_count = vtsi_mat->nr_of_vts_subp_streams;  

		if(opt_v) {
			dvd_info.titles[j].parameter.vts = ifo_zero->tt_srpt->title[j].title_set_nr;
			dvd_info.titles[j].parameter.ttn = ifo_zero->tt_srpt->title[j].vts_ttn;
			dvd_info.titles[j].parameter.fps = frames_per_s[(pgc->playback_time.frame_u & 0xc0) >> 6];
			dvd_info.titles[j].parameter.format = video_format[video_attr->video_format];
			dvd_info.titles[j].parameter.aspect = aspect_ratio[video_attr->display_aspect_ratio];
			dvd_info.titles[j].parameter.width = video_width[video_attr->picture_size];
			dvd_info.titles[j].parameter.height = video_height[video_attr->video_format];
			dvd_info.titles[j].parameter.df = permitted_df[video_attr->permitted_df];

		}

		// PALETTE
		if (opt_P) {
			dvd_info.titles[j].palette = malloc(16 * sizeof(int));
        	        for (i=1; i < 16; i++) { dvd_info.titles[j].palette[i] = pgc->palette[i]; }
		} else {
			dvd_info.titles[j].palette = NULL;
		}

		// ANGLES

		if (opt_n) {
			dvd_info.titles[j].angle_count = ifo_zero->tt_srpt->title[j].nr_of_angles;
		} else {
			dvd_info.titles[j].angle_count = 0;
		}

		// AUDIO

		if (opt_a) {

			dvd_info.titles[j].audiostreams = calloc(dvd_info.titles[j].audiostream_count, sizeof(*dvd_info.titles[j].audiostreams));

			for (i=0; i<dvd_info.titles[j].audiostream_count; i++)
			{
				audio_attr = &vtsi_mat->vts_audio_attr[i];
				sprintf(lang_code, "%c%c", audio_attr->lang_code>>8, audio_attr->lang_code & 0xff);
				if (!lang_code[0]) { lang_code[0] = 'x'; lang_code[1] = 'x'; }

				dvd_info.titles[j].audiostreams[i].langcode = strdup(lang_code);
				dvd_info.titles[j].audiostreams[i].language = lang_name(lang_code);
				dvd_info.titles[j].audiostreams[i].format = audio_format[audio_attr->audio_format];
				dvd_info.titles[j].audiostreams[i].frequency = sample_freq[audio_attr->sample_frequency];
				dvd_info.titles[j].audiostreams[i].quantization = quantization[audio_attr->quantization];
				dvd_info.titles[j].audiostreams[i].channels = audio_attr->channels+1;
				dvd_info.titles[j].audiostreams[i].ap_mode = audio_attr->application_mode;
				dvd_info.titles[j].audiostreams[i].content = audio_type[audio_attr->lang_extension];
				dvd_info.titles[j].audiostreams[i].streamid = audio_id[audio_attr->audio_format] + i;
			}
		} else {
			dvd_info.titles[j].audiostreams = NULL;
		}

		// CHAPTERS

		cell = 0;
		if (opt_c) {
			dvd_info.titles[j].chapter_count = pgc->nr_of_programs;
			dvd_info.titles[j].chapters = calloc(dvd_info.titles[j].chapter_count, sizeof(*dvd_info.titles[j].chapters));

						int ms;
			for (i=0; i<pgc->nr_of_programs; i++)
			{	   
				ms=0;
				int next = pgc->program_map[i+1];   
				if (i == pgc->nr_of_programs - 1) next = pgc->nr_of_cells + 1;

				while (cell < next - 1)
				{
					ms = ms + dvdtime2msec(&pgc->cell_playback[cell].playback_time);
		               		converttime(&dvd_info.titles[j].chapters[i].playback_time, &pgc->cell_playback[cell].playback_time);
					cell++;
				}
				dvd_info.titles[j].chapters[i].startcell = pgc->program_map[i];
				dvd_info.titles[j].chapters[i].length = ms * 0.001;


			}
		}

		// CELLS


		dvd_info.titles[j].cells = calloc(dvd_info.titles[j].cell_count, sizeof(*dvd_info.titles[j].cells));

		if (opt_d) {
			for (i=0; i<pgc->nr_of_cells; i++)
			{
				dvd_info.titles[j].cells[i].length = dvdtime2msec(&pgc->cell_playback[i].playback_time)/1000.0;
                                converttime(&dvd_info.titles[j].cells[i].playback_time, &pgc->cell_playback[i].playback_time);
			}
		} else {
			dvd_info.titles[j].cells = NULL;
		}

		// SUBTITLES

		dvd_info.titles[j].subtitles = calloc(dvd_info.titles[j].subtitle_count, sizeof(*dvd_info.titles[j].subtitles));

		if (opt_s) {
			for (i=0; i<vtsi_mat->nr_of_vts_subp_streams; i++)
			{
				subp_attr = &vtsi_mat->vts_subp_attr[i];
				sprintf(lang_code, "%c%c", subp_attr->lang_code>>8, subp_attr->lang_code & 0xff);
				if (!lang_code[0]) { lang_code[0] = 'x'; lang_code[1] = 'x'; }
				
				dvd_info.titles[j].subtitles[i].langcode = strdup(lang_code);
				dvd_info.titles[j].subtitles[i].language = lang_name(lang_code);
				dvd_info.titles[j].subtitles[i].content = subp_type[subp_attr->lang_extension];
				dvd_info.titles[j].subtitles[i].streamid = 0x20 + i;				
			}
		} else {
			dvd_info.titles[j].subtitles = NULL;
		}

 	} // if vtsi_mat
	} // if not -t
	} // for each title
	
	if (! opt_t) { dvd_info.longest_track = max_track; }

	if (opt_p) {
		ocode_print(&perl_syntax, &dvd_info);
	} else {
		switch(opt_O) {
			case 'p':	
				ocode_print(&perl_syntax, &dvd_info);		
				break;
                        case 'y':
			       ocode_print(&python_syntax, &dvd_info);           
				break;
			case 'x':
				oxml_print(&dvd_info);		
				break;
			case 'r':
				ocode_print(&ruby_syntax, &dvd_info);		
				break;
                        case 'd':
				ocode_print(&debug_syntax, &dvd_info);           
				break;
			default :
				ohuman_print(&dvd_info);	
				break;
		}
	}

	for (i=1; i <= ifo_zero->vts_atrt->nr_of_vtss; i++) { ifoClose(ifo[i]);	}

	ifoClose(ifo_zero);
	DVDClose(dvd);

	return 0;
}