--- vdr-1.3.42-orig/recorder.c	2006-01-08 13:01:25.000000000 +0200
+++ vdr-1.3.42/recorder.c	2006-02-06 03:21:00.000000000 +0200
@@ -26,10 +26,12 @@
   cRemux *remux;
   cFileName *fileName;
   cIndexFile *index;
   uchar pictureType;
   int fileSize;
+char *baseFileName;
+cMarks myMarks;
   cUnbufferedFile *recordFile;
   time_t lastDiskSpaceCheck;
   bool RunningLowOnDiskSpace(void);
   bool NextFile(void);
 protected:
@@ -55,15 +57,18 @@
   // Create the index file:
   index = new cIndexFile(FileName, true);
   if (!index)
      esyslog("ERROR: can't allocate index");
      // let's continue without index, so we'll at least have the recording
+myMarks.Load(FileName);
+baseFileName = strdup(FileName);
 }
 
 cFileWriter::~cFileWriter()
 {
   Cancel(3);
+free(baseFileName);
   delete index;
   delete fileName;
 }
 
 bool cFileWriter::RunningLowOnDiskSpace(void)
@@ -88,22 +93,63 @@
         }
      }
   return recordFile != NULL;
 }
 
+#if 1
+static int ScanVP(const uchar *Data, int Count, int Offset)
+{
+  int Length = Count; //GetPacketLength(Data, Count, Offset);
+  if (Length > 0) {
+    if (Length >= 8) {
+      int i = Offset + 8; // the minimum length of the video packet header
+      i += Data[i] + 1;   // possible additional header bytes
+      for (; i < Offset + Length - 5; i++) {
+	if (Data[i] == 0 && Data[i + 1] == 0 && Data[i + 2] == 1) {
+	  switch (Data[i + 3]) {
+	  case 0xb3:
+	    //fprintf(stderr,"A=%x\n", Data[i + 7] >> 4); fflush(stderr);
+	    return Data[i + 7] >> 4;
+	  }
+	}
+      }
+    }
+  }
+  return -1;
+}
+#endif
+
 void cFileWriter::Action(void)
 {
+int last_asp = -1, mark_set = 0;
   time_t t = time(NULL);
   while (Running()) {
         int Count;
         uchar *p = remux->Get(Count, &pictureType);
         if (p) {
            if (!Running() && pictureType == I_FRAME) // finish the recording before the next 'I' frame
               break;
+int asp = ScanVP(p, Count, 0);
+if(last_asp == -1)
+  last_asp = asp;
+else if(asp != -1 && asp != last_asp) {
+  fprintf(stderr,"ASPECT CHANGED %x -> %x\n", last_asp, asp);fflush(stderr);
+  last_asp = asp;
+  mark_set = !mark_set;
+}
+
            if (NextFile()) {
-              if (index && pictureType != NO_PICTURE)
+	      if (index && pictureType != NO_PICTURE) {
                  index->Write(pictureType, fileName->Number(), fileSize);
+if(mark_set && pictureType == I_FRAME) {
+  myMarks.Load(baseFileName);
+  myMarks.Add(index->Last());
+  myMarks.Save();
+  mark_set = 0;
+  fprintf(stderr,"    index %d\n", index->Last());fflush(stderr);
+ }
+}
               if (recordFile->Write(p, Count) < 0) {
                  LOG_ERROR_STR(fileName->Name());
                  break;
                  }
               fileSize += Count;
