summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmpeg3/mpeg3toc.c
blob: 84b31cba7f6562b45c5bf6dc8e7ac819374e2c4b (plain)
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
#include "libmpeg3.h"
#include "mpeg3protos.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	int i;
/*	FILE *output; */
	char new_path[1024], *ext;
	struct stat st;
	long size;
	int timecode_search = 0;

	if(argc < 2)
	{
		fprintf(stderr, "Create a table of contents for a DVD.\n"
			"	Usage: mpeg3toc [-t] <filename>...\n"
			"	-t Perform timecode search.\n"
			"\n"
			"	The filenames should be absolute paths unless you plan\n"
			"	to always run your movie player from the same directory\n"
			"	as the filename.  Alternatively you can edit the toc by\n"
			"	hand.\n"
			"	The timecode search allows XMovie to play the Matrix.\n"
			"Example: mpeg3toc /cd2/video_ts/vts_01_*.vob > titanic.toc\n");
		exit(1);
	}

	for(i = 1; i < argc; i++)
	{
		if(!strcmp(argv[i], "-t"))
		{
			timecode_search = 1;
		}
		else
		{
/* Get just name */
			ext = strrchr(argv[i], '/');
			if(ext)
			{
				ext++;
				strcpy(new_path, ext);
			}
			else
				strcpy(new_path, argv[i]);


/* Replace suffix */
			ext = strrchr(new_path, '.');
			if(ext)
			{
				sprintf(ext, ".toc");
			}
			else
				strcat(new_path, ".toc");

/*			fprintf(stderr, "Creating %s\n", new_path); */

			stat(argv[i], &st);
			size = (long)st.st_size;

			if(!size)
			{
				fprintf(stderr, "%s is 0 length.  Skipping\n", new_path);
			}
			else
			{
/* Just want the first title's streams */
				if(mpeg3_generate_toc(stdout, argv[i], timecode_search, i == argc - 1))
				{
					fprintf(stderr, "Skipping %s\n", argv[i]);
				}
			}
		}
	}
}