Index: libass/ass.c
===================================================================
--- libass/ass.c	(revision 23373)
+++ libass/ass.c	(working copy)
@@ -982,17 +982,9 @@
 	return track;
 }
 
-/**
- * \brief Read subtitles from file.
- * \param library libass library object
- * \param fname file name
- * \param codepage recode buffer contents from given codepage
- * \return newly allocated track
-*/ 
-ass_track_t* ass_read_file(ass_library_t* library, char* fname, char* codepage)
+char* read_file_recode(char* fname, char* codepage, int* size)
 {
 	char* buf;
-	ass_track_t* track;
 	size_t bufsize;
 	
 	buf = read_file(fname, &bufsize);
@@ -1007,6 +999,26 @@
 	if (!buf)
 		return 0;
 #endif
+	*size = bufsize;
+	return buf;
+}
+
+/**
+ * \brief Read subtitles from file.
+ * \param library libass library object
+ * \param fname file name
+ * \param codepage recode buffer contents from given codepage
+ * \return newly allocated track
+*/ 
+ass_track_t* ass_read_file(ass_library_t* library, char* fname, char* codepage)
+{
+	char* buf;
+	ass_track_t* track;
+	size_t bufsize;
+
+	buf = read_file_recode(fname, codepage, &bufsize);
+	if (!buf)
+		return 0;
 	track = parse_memory(library, buf);
 	free(buf);
 	if (!track)
Index: libass/ass.h
===================================================================
--- libass/ass.h	(revision 23373)
+++ libass/ass.h	(working copy)
@@ -162,6 +162,8 @@
 */
 void ass_process_chunk(ass_track_t* track, char *data, int size, long long timecode, long long duration);
 
+char* read_file_recode(char* fname, char* codepage, int* size);
+
 /**
  * \brief Read subtitles from file.
  * \param fname file name
Index: subreader.c
===================================================================
--- subreader.c	(revision 23373)
+++ subreader.c	(working copy)
@@ -19,6 +19,7 @@
 #include "mp_msg.h"
 #include "subreader.h"
 #include "stream/stream.h"
+#include "libass/ass.h"
 
 #ifdef HAVE_ENCA
 #include <enca.h>
@@ -1336,6 +1337,8 @@
 
 sub_data* sub_read_file (char *filename, float fps) {
     stream_t* fd;
+    unsigned char* subfile_buf;
+    size_t subfile_size;
     int n_max, n_first, i, j, sub_first, sub_orig;
     subtitle *first, *second, *sub, *return_sub;
     sub_data *subt_data;
@@ -1360,8 +1363,15 @@
     struct subreader *srp;
     
     if(filename==NULL) return NULL; //qnx segfault
+
     i = 0;
-    fd=open_stream (filename, NULL, &i); if (!fd) return NULL;
+    subfile_buf = read_file_recode(filename, sub_cp, &subfile_size);
+    if (!subfile_buf) return 0;
+    fd = new_memory_stream(subfile_buf, subfile_size);
+    if (!fd) {
+      free(subfile_buf);
+      return 0;
+    }
     
     sub_format=sub_autodetect (fd, &uses_time);
     mpsub_multiplier = (uses_time ? 100.0 : 1.0);
@@ -1372,30 +1382,14 @@
     stream_reset(fd);
     stream_seek(fd,0);
 
-#ifdef USE_ICONV
     sub_utf8_prev=sub_utf8;
-    {
-	    int l,k;
-	    k = -1;
-	    if ((l=strlen(filename))>4){
-		    char *exts[] = {".utf", ".utf8", ".utf-8" };
-		    for (k=3;--k>=0;)
-			if (l >= strlen(exts[k]) && !strcasecmp(filename+(l - strlen(exts[k])), exts[k])){
-			    sub_utf8 = 1;
-			    break;
-			}
-	    }
-	    if (k<0) subcp_open(fd);
-    }
-#endif
+    sub_utf8 = 1;
 
     sub_num=0;n_max=32;
     first=malloc(n_max*sizeof(subtitle));
     if(!first){
-#ifdef USE_ICONV
-	  subcp_close();
-          sub_utf8=sub_utf8_prev;
-#endif
+      sub_utf8 = sub_utf8_prev;
+      free(subfile_buf);
 	    return NULL;
     }
     
@@ -1416,18 +1410,13 @@
 	memset(sub, '\0', sizeof(subtitle));
         sub=srp->read(fd,sub);
         if(!sub) break;   // EOF
-#ifdef USE_ICONV
-	if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub);
-#endif
 #ifdef USE_FRIBIDI
 	if (sub!=ERR) sub=sub_fribidi(sub,sub_utf8);
 #endif
 	if ( sub == ERR )
 	 {
-#ifdef USE_ICONV
-          subcp_close();
-#endif
     	  if ( first ) free(first);
+	  free(subfile_buf);
 	  return NULL; 
 	 }
         // Apply any post processing that needs recoding first
@@ -1476,11 +1465,8 @@
     }
     
     free_stream(fd);
+    free(subfile_buf);
 
-#ifdef USE_ICONV
-    subcp_close();
-#endif
-
 //    printf ("SUB: Subtitle format %s time.\n", uses_time?"uses":"doesn't use");
     mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Read %i subtitles", sub_num);
     if (sub_errs) mp_msg(MSGT_SUBREADER,MSGL_INFO,", %i bad line(s).\n", sub_errs);
