27 #define BUFFER_SIZE 4096*128
29 #define SC_PICTURE 0x00
36 #define PROG_STREAM_MAP 0xBC
37 #ifndef PRIVATE_STREAM1
38 #define PRIVATE_STREAM1 0xBD
40 #define PADDING_STREAM 0xBE
41 #ifndef PRIVATE_STREAM2
42 #define PRIVATE_STREAM2 0xBF
44 #define AUDIO_STREAM_S 0xC0
45 #define AUDIO_STREAM_E 0xDF
46 #define VIDEO_STREAM_S 0xE0
47 #define VIDEO_STREAM_E 0xEF
48 #define ECM_STREAM 0xF0
49 #define EMM_STREAM 0xF1
50 #define DSM_CC_STREAM 0xF2
51 #define ISO13522_STREAM 0xF3
52 #define PROG_STREAM_DIR 0xFF
63 static unsigned char buf(
long p)
71 if (fseek(
fp, p, SEEK_SET) == 0)
75 memset(&ringbuf, 0,
sizeof(ringbuf));
76 n = fread(ringbuf, 1,
sizeof(ringbuf),
fp);
78 if ((n <
sizeof(ringbuf)) && ferror(
fp))
80 fprintf(stderr,
"Could not read from %s: %s\n",
fname, strerror(errno));
89 static int readfile(
const unsigned char number)
94 sprintf(
fname,
"%03d.vdr", number);
100 fprintf(stderr,
"Could not open %s: %s\n",
fname, strerror(errno));
107 if (fseek(
fp, 0, SEEK_END) < 0)
109 fprintf(stderr,
"Could not goto end of %s: %s\n",
fname, strerror(errno));
112 if ((filesize = ftell(
fp)) < 0)
114 fprintf(stderr,
"Could not get size of %s: %s\n",
fname, strerror(errno));
120 printf(
"Reading %s, %ld kB.\n",
fname, (filesize >> 10));
127 if (
buf(c) == 0x00 &&
buf(c+1) == 0x00 &&
buf(c+2) == 0x01)
129 const long w = ((
buf(c+4) << 8) |
buf(c+5)) + 6;
130 const long l = w + c;
132 if (!((l > c) && (l <= filesize)))
150 long off = (
buf(c+8) + 9) + c;
151 for (;off < l; off++)
153 if (
buf(off) == 0x00 &&
buf(off+1) == 0x00 &&
buf(off+2) == 0x01 &&
156 const unsigned char Ptype = (
buf(off+5)>>3) & 0x07;
160 const struct tIndex i = {(int)c, Ptype, number, 0};
162 if (fwrite(&i, 1,
sizeof(i),
idx) !=
sizeof(i))
164 fprintf(stderr,
"Error writing index file: %s\n", strerror(errno));
169 printf(
"I-Frame found at %ld kB\r", (c >> 10));
179 fprintf(stderr,
"\nError while scanning file %s, broken mpeg file?\n",
fname);
194 if (!(
idx = fopen(
"index.vdr",
"w")))
196 fprintf(stderr,
"Could not open index.vdr: %s\n", strerror(errno));
199 for (c=1; ((ret =
readfile(c)) == 0); c++)
200 __asm__ __volatile__(
"": : :
"memory");
202 return (ret > 0 ? 0 : 1);
static unsigned char buf(long p)
static unsigned char fbuffer[BUFFER_SIZE]
static int readfile(const unsigned char number)