Index: mencoder.c
===================================================================
--- mencoder.c	(.../tmp2)	(revision 565)
+++ mencoder.c	(.../stable)	(revision 565)
@@ -223,6 +223,14 @@
   return 0;
 }
 
+#ifdef USE_ASS
+#include "libass/ass.h"
+#include "libass/ass_mp.h"
+
+int ass_enabled = 0;// -ass option
+ass_track_t* ass_track = 0; // current track to render
+#endif
+
 //char *out_audio_codec=NULL; // override audio codec
 //char *out_video_codec=NULL; // override video codec
 
@@ -645,6 +653,23 @@
     }
   }
 
+#ifdef USE_ASS
+  // init libass
+  ass_track = 0;
+  if (ass_enabled) {
+    // free old track
+    if (ass_track)
+      ass_free_track(ass_track);
+    // try external subs first
+    if (sub_name && sub_name[0])
+      ass_track = ass_read_file(sub_name[0]);
+    // check matroska embedded subs
+    if (!ass_track && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
+        (demuxer->sub->id >= 0) && (((sh_sub_t *)demuxer->sub->sh)->type == 'a'))
+      ass_track = ((sh_sub_t *)demuxer->sub->sh)->ass_track;
+  }
+  if (!ass_track) {
+#endif
 #ifdef USE_SUB
 // after reading video params we should load subtitles because
 // we know fps so now we can adjust subtitles time to ~6 seconds AST
@@ -666,6 +691,9 @@
     free(tmp);
   }
 #endif	
+#ifdef USE_ASS
+  }
+#endif
 
 // set up video encoder:
 
@@ -854,8 +882,36 @@
       char* vf_args[] = { "osd", "1", NULL };
       sh_video->vfilter=vf_open_filter(sh_video->vfilter,"expand",vf_args);
     }
+#ifdef USE_ASS
+    if(ass_enabled) {
+      int i;
+      int insert = 1;
+      if (vf_settings)
+        for (i = 0; vf_settings[i].name; ++i)
+          if (strcmp(vf_settings[i].name, "ass") == 0) {
+            insert = 0;
+            break;
+          }
+      if (insert) {
+        extern vf_info_t vf_info_ass;
+        vf_info_t* libass_vfs[] = {&vf_info_ass, NULL};
+        char* vf_arg[] = {"auto", "1", NULL};
+        vf_instance_t* vf_ass = vf_open_plugin(libass_vfs,sh_video->vfilter,"ass",vf_arg);
+        if (vf_ass)
+          sh_video->vfilter=(void*)vf_ass;
+        else
+          mp_msg(MSGT_CPLAYER,MSGL_ERR, "ASS: cannot add video filter\n");
+      }
+    }
+#endif
     sh_video->vfilter=append_filters(sh_video->vfilter);
 
+#ifdef USE_ASS
+if (ass_enabled)
+  ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_EOSD, 0);
+#endif
+	
+
     mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
     init_best_video_codec(sh_video,video_codec_list,video_fm_list);
     mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
@@ -1320,7 +1376,7 @@
 default:
     // decode_video will callback down to ve_*.c encoders, through the video filters
     blit_frame=decode_video(sh_video,frame_data.start,frame_data.in_size,
-      skip_flag>0 && (!sh_video->vfilter || ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_SKIP_NEXT_FRAME, 0) != CONTROL_TRUE), MP_NOPTS_VALUE);
+      skip_flag>0 && (!sh_video->vfilter || ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_SKIP_NEXT_FRAME, 0) != CONTROL_TRUE), sh_video->pts);
     
     if (sh_video->vf_inited < 0) mencoder_exit(1, NULL);
     
@@ -1736,7 +1792,7 @@
 
         if (vfilter) {
             int softskip = (vfilter->control(vfilter, VFCTRL_SKIP_NEXT_FRAME, 0) == CONTROL_TRUE);
-            decode_video(sh_video, frame_data->start, frame_data->in_size, !softskip, MP_NOPTS_VALUE);
+            decode_video(sh_video, frame_data->start, frame_data->in_size, !softskip, sh_video->pts);
         }
 
         if (print_info) mp_msg(MSGT_MENCODER, MSGL_STATUS,
