[MPlayer-dev-eng] to arpi: seeking in MPEG-PES
Johannes Feigl
jaf.corporation at gmx.at
Wed Dec 12 20:06:38 CET 2001
Hi arpi
here is the program I've talked about to regenerate the index.vdr of
VDR-Recording. Maybe you can implement it and so add seeking ?
mfg Johannes
-------------- next part --------------
//
//the program often found some frames "in a frame" or frames that aren't I B
//or P-Frames.
//Now it should be fixed. I've tested this with an ~1 h (Pro 7) recording and
//the
//index file didn't differ from the original file that VDR has produced.
//
//btw. this doesn't work with "mplexed" files. It seems, that searching for
// 0x00 0x00 0x01 0xE0 does not return the right offset of a video frame.
//
//
//Roland
//
//
//------------- genindex.c ----------
//
//usage: start genindex in the folder where 001.vdr is located
//
#include <stdio.h>
#define readbuffersize 1024*128
#define SC_VIDEO 0xE0
#define SC_PICTURE 0x00
unsigned char ringbuf[readbuffersize];
int offset;
FILE* fp ;
FILE* idx;
int Foffset;
unsigned char buf(int p)
{
if ((p >= Foffset) && ( p < (Foffset+readbuffersize)) )
{return ringbuf[p-Foffset];}
Foffset=p;
if (fseek(fp,p,SEEK_SET)==0)
{
fread(ringbuf, 1, readbuffersize, fp);
return ringbuf[p-Foffset];
}
return 0;
}
int readfile(const unsigned char number )
{
int filesize;
int length;
int c;
int d;
int e;
char fname[20];
sprintf(fname,"%03d.vdr",number);
printf("\nReading:");
printf(fname);
printf("\n");
fp = fopen(fname, "r");
if(!fp) { printf("Could not open the file\n"); return -1;}
fseek(fp, 0, SEEK_END);
filesize = ftell(fp);
Foffset=filesize;
for (c=0;c < filesize-32;c++)
{
if (buf(c) == 0 && buf(c+1) == 0 && buf(c+2) == 1 && buf(c+3)==SC_VIDEO)
{
d=c+8;
d+= buf(d)+1;
length=(buf(c+4) << 8) + buf(c +5)+6;
e=length;
if (e > 256) { e=256;}
// I think the Picture Header must be in the
// first 256 Bytes (also makes program faster :-)
e+=d; // d is offset of SC_Video
for (;(d < e) && (d < filesize -32);d++)
{
if (buf(d) == 0 && buf(d+1) == 0 && buf(d+2) == 1 && buf(d+3)==SC_PICTURE)
{
char Ptype=(buf(d+5)>>3) & 0x07;
if (Ptype > 0 && Ptype < 4)
{
char i[8]={c,c>>8,c>>16,c>>24,Ptype,number,0};
if(fwrite(i, 1, 8, idx) != 8)
{ printf("Error writing index file\n"); return -1;}
if (((buf(d+5)>>3) & 0x07)==1)
{ printf("IFrame found at: %d kB
\r",(c/1024));
fflush(stdout);
c+=length;
d=c;
}
}
}
}
}
}
fclose(fp);
return 0;
}
int main()
{
int c;
idx = fopen("index.vdr", "w");
for (c=1;readfile(c)==0;c++) { }
fclose(idx);
return 0;
}
More information about the MPlayer-dev-eng
mailing list