HOW-TO stream video directly out of .rar files
#1
Big Grin 
almost everything i watch with xbmc comes packaged in multiple .rar volumes. it's always a pain having to unrar stuff before being able to watch it (can take a few minutes, may not have enough temporary space available, may want to keep original .rar files for archive purposes etc), so i made some small changes in xbmc and in the ccxstream stream server for linux which make it possible to watch divx / vcd / svcd / dvd video straight from .rar files without unraring.

what you need:

xbmc compiled from current sources (util.cpp / util.h / mplayer.cpp / mplayer.h updates committed 03-24).
you need to add ".rar" to the list of <videoextensions> in your xboxmediacenter.xml.

a linux box as your stream server, on which you need:

/usr/bin/rar (using version 3.30 here)
ccxstream (http://prdownloads.sourceforge.net/xbmc/....15.tar.gz) with the following patch applied:

Quote:*** ccxstream.c mon mar 17 14:29:15 2003
--- ccxstream.c wed mar 24 04:48:48 2004
***************
*** 973,977 ****
return 1;
}
! conn->f[fh] = fopen(hlp, "r");
cc_xfree(hlp);
cc_xfree(s);
--- 973,989 ----
return 1;
}
! if (strcasecmp(&hlp[strlen(hlp)-4], ".rar") == 0) /* omg c sucks for string operations */
! {
! char *unrar_exec_str;
! unrar_exec_str = cc_xmalloc(strlen(hlp)+60);
! sprintf(unrar_exec_str, "/usr/bin/rar p -inul \"%s\" \"*.mpg\" \"*.avi\" \"*.img\" \"*.bin\"", hlp);
! conn->f[fh] = popen(unrar_exec_str, "r");
! }
! else
! {
! /* if filename doesnt contain .rar it must be a normal file so open it directly */
! conn->f[fh] = fopen(hlp, "r");
! }
!
cc_xfree(hlp);
cc_xfree(s);

(download patch or full ccxstream.c, then run "make" and start ccxstream)

how it works: when xbmc requests a .rar file from the patched ccxstream, instead of sending the .rar as-is, ccx launches rar and sends the unrared data directly to xbmc without it being saved on the pc.
the only change necessary in xbmc was to tell mplayer to not try loading the index from the end of .avi files if we are attempting to load from a .rar (the end of the file is not available when we've just started unraring). this also means that seeking is totally disabled while playing .avis from rars (you can still pause or stop). for mpeg videos, you can seek a little bit forward as far as your lan streaming buffer permits.

note to windows users: don't ask me how to set something like this up under windows. maybe someone else will patch a windows stream server in the same way.

i would welcome any feedback in case someone else finds this useful and has it working on their system.

---

addendum (2003-05-02): pre-patched versions of ccxstream and xbms (a linux/freebsd xns protocol stream server) with unrar support are now available to download here: http://sourceforge.net/project....d=97904



read the xbmc online-manual, faq and search the forums before posting! do not e-mail the xbmc-team asking for support!
read/follow the forum rules! note! team-xbmc never have and never will host or distribute ms-xdk binaries/executables!
Reply
#2
extremly cool Image poing is this patch your work or someone elses? i'm no linux user so i'll just have to wait and see what happens on win. i have no doubt that the demand for such a thing on win is tremendously big.
Reply
#3
i made the above patch for ccxstream and also the changes in xbmc. it may be possible to adapt the patch so that the win32/cygwin compiled version of ccxstream calls rar.exe, which also has the same "p" unrar-to-stdout parameter. i couldn't get "rar.exe p -inul movie.rar | mplayer.exe -" to work, however (the problem may lie with mplayer/win32 not accepting input from stdin like mplayer/linux does). someone familiar with compiling ccxstream on win32 would have to look into it.



read the xbmc online-manual, faq and search the forums before posting! do not e-mail the xbmc-team asking for support!
read/follow the forum rules! note! team-xbmc never have and never will host or distribute ms-xdk binaries/executables!
Reply
#4
very cool poing. i hope someone will make it work, if not it will be one more reason to install linux Wink
Reply
#5
hi,

here is a patch for xbms, its alot more ugly compared to poings patch, cause it seems xns needs the correct file size. therefor i run a second rar lt to list the file size and grep it using the nice egrep and gawk tools, so make sure you have them on your shell, if not, either patch xbmc or write some internal c code for xbms Wink

here we go (patch xbms using patch -p0 < rar.diff, make sure you apply the xbmc-patch before on xbms_0.30.6.tar.gz from
http://www.h4x0rz.de/ (the xbmc-patch includes the comma one)

Quote:--- server.c 2004-03-28 00:25:34.000000000 +0100
+++ server.c 2004-03-28 00:05:56.000000000 +0100
@@ -427,14 +427,16 @@
char *cmd;
char *ptr;
char *filename;
- char *targetfilename;
+ char *targetfilename,*tmpfilename,*tmprarsize;
struct stat st;
int size1,size2;
static char *tempbuf;
unsigned long cnt;
- int ret=0;
+ int open_ok,ret=0;
+ int f_size=0;
char *temp_path;
char *target_path = main_config->root_dir;
+ file *size_file;

*cmd = (char *)malloc(max_msg_length);
memset(*cmd,0x0,max_msg_length);
@@ -487,7 +489,40 @@
/* to open the requested file. otherwise processing should continue */
if (!strstr(filename,"/../"))
{
- if (!(*file = fopen(targetfilename,"r")))
+ tmpfilename=strrchr(targetfilename,'.');
+ if (tmpfilename==null) {
+ sprintf(*cmd,"%-32d",-1);
+ free(filename);
+ free(targetfilename);
+ ret=1;
+ } else {
+ if (!strcasecmp(tmpfilename,".rar")) {
+ tmpfilename=(char *)malloc(4096);
+ sprintf(tmpfilename,"/usr/bin/rar p -inul \"%s\" \"*.mpg\" \"*.avi\" \"*.img\" \"*.bin\"",targetfilename);
+ d_log("open file: %s\n",tmpfilename);
+ open_ok=(int)(*file = popen(tmpfilename,"r"));
+ if (open_ok) {
+ //this is ugly, but it seems lie xns protkoll really needs a "valid" size for the file,
+ //and since rars are mostyl splited lets use some bash stuff to get the actual size
+ tmprarsize=(char *)malloc(4096);
+ sprintf(tmprarsize,"/usr/bin/rar lt \"%s\" | egrep -ei \"\\.mpg |\\.avi |\\.img |\\.bin \" | gawk '{ print $2 }'" ,targetfilename);
+ d_log("filesize: %s\n",tmprarsize);
+ if ((size_file = popen(tmprarsize,"r"))) {
+ bzero(tmpfilename,4096);
+ fread(tmpfilename,1,4096,size_file);
+ pclose(size_file);
+ d_log("filesize: %s\n",tmpfilename);
+ f_size=atol(tmpfilename);
+ }
+ free(tmprarsize);
+ }
+ free(tmpfilename);
+ } else {
+ open_ok=(int)(*file = fopen(targetfilename,"r"));
+ stat(targetfilename,&st);
+ f_size=(int)st.st_size;
+ }
+ if (!open_ok)
{
if (main_config->debug_lvl >= 1) {
d_log("cannot open file: %s\n",targetfilename);
@@ -499,10 +534,9 @@
}
else
{
- fstat(fileno(*file),&st);
/* set it to 32 char, so player understands it.*/
- sprintf(*cmd,"%-32d",(int)st.st_size);
-
+ sprintf(*cmd,"%-32i",(int)f_size);
+ d_log("ok file is running!\n");
free(filename);
free(targetfilename);
ret = 1;
}
+ }
}
else d_log("illegal string in filename: %s\n", filename);
Reply
#6
have made it partly working in windows. it just don't wanna play all the files (only plays the one selected)

Quote:if ((hlp, ".rar") == 0) /* omg c sucks for string operations */
      {
      char *unrar_exec_str;
      unrar_exec_str = cc_xmalloc(strlen(hlp)+60);
      sprintf(unrar_exec_str, "rar.exe p -inul \"%s\" \"*.mpg\" \"*.avi\" \"*.img\" \"*.bin\"", hlp);
      conn->f[fh] = popen(unrar_exec_str, "r");
      }
      else
        {
        /* if filename doesnt contain .rar it must be a normal file so open it directly */
conn->f[fh] = _open(hlp, _o_binary|_o_rdonly ,_s_iread  );
        }

//[xc]d-ice

** hmm....looks like it don't work anyway..... Sad



Reply
#7
ok... now i got it compiled with the following code, but when trying to launch a rar file on the xbox, xbmc just freeze.... any ideas? (rar is located in the same folder as ccxstream)

Quote:if (stricmp(&hlp[strlen(hlp)-4], ".rar") == 0) /* omg c sucks for string operations */
      {
      char *unrar_exec_str;
      unrar_exec_str = cc_xmalloc(strlen(hlp)+60);
      sprintf(unrar_exec_str, "rar p -inul \"%s\" \"*.mpg\" \"*.avi\" \"*.img\" \"*.bin\"", hlp);
      conn->f[fh] = _popen(unrar_exec_str, "r");
      }
      else
        {
        /* if filename doesnt contain .rar it must be a normal file so open it directly */
        conn->f[fh] = _open(hlp, _o_binary|_o_rdonly ,_s_iread );
        }

//[xc]d-ice



Reply
#8
are you sure strlen(hlp) >= 4

safer (paranoid) would be:

Quote:char* szextension = strrchr(szfilename,'.');
char* szexpected = szfilename+(strlen(szfilename)-4);

// ensure file has a 3 letter .rar extension
if ((szextension!=null) && (szexpected==szextension) && (strcmpi(szextension,".rar")==0) )
{
 ...
}
XBMC Project Founder (Retired)
Reply
#9
oh im ashamed, thx to your post a did a look at my solution and noticed a big flaw in handling a extension less filename. you have to add a else {
and
}
to my patch. i edited my above post to the correct version.
as a sitenote, im using this xbms and xbmc for some days now and im very happy with it. no problems so far if you dont mind a av delay when i tried ff and rewind on a divx several times. but ff does really work, even on rared avi. maybe you can enable the 1 and 10min forward jumps for avis in rars too?
Reply
#10
Thumbs Up 
@tric, can you please upload or send me a pre-patched version of xbms for us to host to the public?, tia Smile
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#11
cant wait for a public windows version! =) great work all people involved in this.
Reply
#12
(gamester17 @ april 05 2004,12:42 Wrote:@tric, can you please upload or send me a pre-patched version of xbms for us to host to the public?, tia Smile
yeah of course, done.

sorry i cant reach my own hoster at the moment so i used only this forum
Reply
#13
Sad 
(tric @ april 06 2004,02:18 Wrote:yeah of course, done.
k, which version number do you want to give this complete patched code? ps! does this have all the previous patches included in it?
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#14
hmm, maybe 0.30.6r Wink
and yes all previous patches are included
Reply
#15
Thumbs Up 
(tric @ april 06 2004,13:33 Wrote:hmm, maybe 0.30.6r Wink
and yes all previous patches are included
k, added to downloads. however you might like to make a new build with a rar enable/disable switch so don't have to have separate builds?
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply

Logout Mark Read Team Forum Stats Members Help
HOW-TO stream video directly out of .rar files0