Index: src/mpgfile.cpp
===================================================================
--- src/mpgfile.cpp	(revision 178)
+++ src/mpgfile.cpp	(working copy)
@@ -50,7 +50,8 @@
 mpgfile::mpgfile(inbuffer &b, int initial_offset)
     : buf(b),
     videostreams(0),audiostreams(0),
-    initialoffset(initial_offset),idx(*this),pictures(0)
+    initialoffset(initial_offset),idx(*this),pictures(0),
+    time_base_num(1), time_base_den(25)
 {}
 
 mpgfile::~mpgfile()
@@ -175,6 +176,9 @@
 
         if (frameFinished)
         {
+	  fprintf(stderr, "* decoded frame %5d ilace:%d typ:%d pts=%f\n",
+		  pic, avf->interlaced_frame, avf->pict_type,
+		  (double)avf->pts/90000.0);
           if (last_cpn!=avf->coded_picture_number)
           {
             last_cpn=avf->coded_picture_number;
@@ -213,6 +217,15 @@
     }
   }
 
+  time_base_num = S->avcc->time_base.num;
+  time_base_den = S->avcc->time_base.den;
+#if LIBAVCODEC_VERSION_INT >= ((52<<16)+(23<<8)+0)
+  if (S->avcc->ticks_per_frame > 0) {
+    fprintf(stderr, "field rate -> frame rate\n");
+    time_base_num *= S->avcc->ticks_per_frame;
+  }
+#endif
+
   avcodec_close(S->avcc);
 }
 
@@ -697,7 +710,7 @@
   AVCodecContext *avcc=s[VIDEOSTREAM].avcc;
   if (!avcc)
     return;
-  s[VIDEOSTREAM].setvideoencodingparameters();
+  s[VIDEOSTREAM].setvideoencodingparameters(time_base_num, time_base_den, !framelist.empty() ? (*framelist.front())->interlaced_frame : 0);
 
   if (int rv=avcodec_open(avcc, s[VIDEOSTREAM].enc))
   {
Index: src/stream.h
===================================================================
--- src/stream.h	(revision 178)
+++ src/stream.h	(working copy)
@@ -55,7 +55,7 @@
     avcc=avcodec_alloc_context();
     avcodec_get_context_defaults(avcc);
     }
-  void setvideoencodingparameters(bool interlaced=false)
+  void setvideoencodingparameters(int tb_num, int tb_den, bool interlaced=false)
     {
     avcc->bit_rate=9500000;
     avcc->rc_min_rate=9500000;
@@ -68,6 +68,10 @@
     avcc->lmax= FF_QP2LAMBDA * 2;
     if (interlaced)
       avcc->flags |= CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME;
+    avcc->time_base.num = tb_num;
+    avcc->time_base.den = tb_den;
+    fprintf(stderr, "video %stb=%d/%d\n", (interlaced ? "interlaced " : ""),
+	    avcc->time_base.num, avcc->time_base.den);
     }
 
   friend class mpgfile;
Index: src/mpgfile.h
===================================================================
--- src/mpgfile.h	(revision 178)
+++ src/mpgfile.h	(working copy)
@@ -51,6 +51,7 @@
   int initialoffset;
   class index idx;
   int pictures;
+  int time_base_num, time_base_den;
 
   mpgfile(inbuffer &b, int initial_offset);
 
@@ -184,7 +185,7 @@
     }
   void setvideoencodingparameters()
     {
-    s[videostream()].setvideoencodingparameters();
+      s[videostream()].setvideoencodingparameters(time_base_num, time_base_den);
     }
 
   int generateindex(const char *savefilename=0, std::string *errorstring=0, logoutput *log=0)
