[MPlayer-dev-eng] [PATCH][RFC] transparent unpacking of .rar for transparent vobsub access

pl p_l at gmx.fr
Fri Jun 7 10:00:10 CEST 2002


Hi,

The attached patch allows reading vobsub "directly" from .rar.

Why?
The win dll allows this so vobsub .sub often ship as .rar.


It uses the 'rar' binary you've installed on your system to unpack the
foo.sub of the foo.rar in /tmp, then opens /tmp/foo.sub and unlinks
/tmp/foo.sub.


It's not clean (lots of debug output) and not ready for cvs inclusion
right now (a generic perl/shell filter wrapping .sub in .rar/.zip/.gz
etc would be much better IMO but I just wanted to make that work
first...)

I'd just like to know whether some people might be interested in
this feature and whether it's worth cleaning & committing.


Example of use:

If your movie is named foo.avi then mplayer searches foo.sub.
To test the patch just do 'rar a foo.rar foo.sub && rm -f foo.sub' then
'mplayer foo.avi'.

Also make sure you have enough space in "/tmp" (not configurable right
now & you can do symlink stuff so use with care ;)


-- 
Best regards,
  pl
-------------- next part --------------
Index: vobsub.c
===================================================================
RCS file: /cvsroot/mplayer/main/vobsub.c,v
retrieving revision 1.12
diff -u -r1.12 vobsub.c
--- vobsub.c	23 May 2002 15:24:59 -0000	1.12
+++ vobsub.c	6 Jun 2002 23:28:08 -0000
@@ -875,10 +875,101 @@
 	    if (spu && vob->orig_frame_width && vob->orig_frame_height)
 	      *spu = spudec_new_scaled_vobsub(vob->palette, vob->cuspal, vob->custom, vob->orig_frame_width, vob->orig_frame_height);
 
+
+#define RAR_SUPPORTED 1
+#if RAR_SUPPORTED
+	    do {
+	      // name == /path/foo
+	      char *fullnamedotsub = NULL;	// /path/foo.sub
+	      char *namedotsub = NULL;		// foo.sub
+	      char *fullnamedotrar = NULL;	// /path/foo.rar
+	      char *nametmpdotsub = NULL;	// /tmp/foo.sub
+  	      char * tmpdir = "/tmp";		// /tmp/
+	      char * cmd = NULL;		// cd /tmp && rar ...
+
+	      fullnamedotsub = malloc(strlen(name) + strlen(".sub") + 1);
+	      strcpy(fullnamedotsub, name);
+	      strcat(fullnamedotsub, ".sub");
+	      
+	      namedotsub = strrchr(fullnamedotsub, '/');
+	      if (namedotsub) {
+		namedotsub++;
+	      } else {
+	       	namedotsub = fullnamedotsub;
+	      }
+
+	      mpg = mpeg_open(fullnamedotsub);
+	      if (mpg == NULL) {
+		mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: cannot open SUB file %s\n", fullnamedotsub);
+	      } else {
+		mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: found & opened SUB file %s\n", fullnamedotsub);
+		goto out;
+	      }
+
+	      fullnamedotrar = malloc(strlen(name) + strlen(".rar") + 1);
+	      strcpy(fullnamedotrar, name);
+	      strcat(fullnamedotrar, ".rar");
+
+	      nametmpdotsub = malloc(strlen(tmpdir) + strlen("/") + strlen(namedotsub) + 1);
+	      strcpy(nametmpdotsub, tmpdir);
+	      strcat(nametmpdotsub, "/");
+	      strcat(nametmpdotsub, namedotsub);
+
+	      if (access(fullnamedotrar, R_OK) == -1) {
+		mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: cannot find SUB.RAR file %s\n", fullnamedotrar);
+		goto out;
+	      }
+
+	      mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: found SUB.RAR file %s\n", fullnamedotrar);
+
+	      // FIXME dirty malloc
+	      cmd = malloc(2048);
+	      sprintf(cmd, "cd \"%s\" && rar e -y \"%s\" \"%s\"", tmpdir, fullnamedotrar, namedotsub);
+
+	      mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: unpacking %s\n", fullnamedotrar);
+
+	      do {
+		FILE *f;
+		int ret;
+		
+  		printf("-------------------------------------------------------------------------------\n");
+  		printf("Executing: %s", cmd);
+  		fflush(stdout);
+  		fflush(stderr);
+
+		f = popen(cmd, "w");
+  		if (!f) {
+  		  goto out;
+  		}
+	  	ret = pclose(f);
+  		printf("Return status = %d\n", ret);
+  		printf("-------------------------------------------------------------------------------\n");
+	      } while (0);
+
+	      mpg = mpeg_open(nametmpdotsub);
+	      if (mpg == NULL) {
+		mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: cannot open tmp SUB file %s\n", nametmpdotsub);
+	      } else {
+		mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: found & opened tmp SUB file %s\n", nametmpdotsub);
+		if (-1 == unlink(nametmpdotsub)) {
+		  mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: could not unlink %s\n", nametmpdotsub);
+		}
+	      }
+
+out:
+	      if (fullnamedotsub) free(fullnamedotsub);
+	      if (fullnamedotrar) free(fullnamedotrar);
+	      if (nametmpdotsub) free(nametmpdotsub);
+	      if (cmd) free(cmd);
+
+	    } while (0);
+#else
 	    /* read the indexed mpeg_stream */
 	    strcpy(buf, name);
 	    strcat(buf, ".sub");
 	    mpg = mpeg_open(buf);
+#endif // RAR_SUPPORTED
+
 	    if (mpg == NULL) {
 	      if(force)
 		mp_msg(MSGT_VOBSUB,MSGL_ERR,"VobSub: Can't open SUB file");


More information about the MPlayer-dev-eng mailing list