Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linux-dvb] Re: problems with genindex



Henning Holtschneider wrote:
....
> genindex scans the entire file and reports I-frames from the beginning to
> the end, but when I replay the file from within VDR, only a fraction of
> the real size is shown and replayed. I took a 1-hour file and got 10
> minutes, a 5 minute recording was shown to be 30 seconds long and so on
> .... Can anyone with more knowledge about VDR and MPEG tell me what could
> be wrong and what I can do to solve the problem?

The data genindex recognizes does not have the same format
in all flavors of MPEG files.

I had the same trouble you described and I was able to fix it.
The following version works better for me:

#include <stdio.h>

#define BUFFER_SIZE  1024*128

#define SC_PICTURE   0x00

#define I_FRAME      1
#define P_FRAME      2
#define B_FRAME      3


static FILE* fp;
static FILE* idx;
static int Foffset;

unsigned char buf(int p)
{
   static unsigned char ringbuf[BUFFER_SIZE];

   if ((p >= Foffset) && ( p < (Foffset+BUFFER_SIZE)) )
       {return ringbuf[p-Foffset];}
   Foffset=p;
   if (fseek(fp, p, SEEK_SET)==0)
   {
      fread(ringbuf, 1, BUFFER_SIZE, fp);
      return ringbuf[p-Foffset];
   }
   return 0;
}


int readfile(const unsigned char number)
{ 
   int filesize;
   int c;
   char fname[20];

   sprintf(fname,"%03d.vdr", number);
   fp = fopen(fname, "r");
   if(!fp) { printf("Could not open %s.          \n", fname); return -1;}
   fseek(fp, 0, SEEK_END);
   filesize = ftell(fp);
   printf("\nReading %s, %d bytes.\n", fname, filesize);
   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_PICTURE)
      {
         const char Ptype=(buf(c+5)>>3) & 0x07;
         if ((Ptype == I_FRAME) || (Ptype == P_FRAME) || (Ptype == B_FRAME))
         {
            const char index_entry[8]={c, c>>8, c>>16, c>>24, Ptype, number, 0};
            const int  length = (buf(c+4) << 8) + buf(c+5) + 6;
            
            if (fwrite(index_entry, 1, 8, idx) != 8)
            { printf("Error writing index file\n"); return -1;}
            if (Ptype == I_FRAME)
            {
               printf("I-Frame found at %d\r", c);
               fflush(stdout);
            }
            c+=length;
         }
      }
   fclose(fp);
   return 0;
}

int main()
{
   int c;
   idx = fopen("index.vdr", "w");
   for (c=1; readfile(c)==0; c++) { }
   fclose(idx);
   return 0;
}


Unfortunately, I am not an expert in MPEG file formats, so I am not
exactly sure why the above version works better for me and what
possible problems my modifications may cause. Maybe one of the real
experts would like to comment on this or even provide us with a 
generalized version of genindex that works properly with all MPEG
files?

In any event: use with caution and a sense of humor. Your mileage
may vary. No gaurantees of any kind. :-)

Carsten.


-- 
Info:
To unsubscribe send a mail to listar@linuxtv.org with "unsubscribe linux-dvb" as subject.



Home | Main Index | Thread Index