Hi,

I recently had a bunch of recordings which I wanted to copy & index at the 
same time with a cool command line like:

tsfilter <INPUT.tts | tee OUTPUT.ts | dvbcut -generateidx -idx OUTPUT.ts.idx -

when I noticed that this isn't no more possible! :-(

Doing some 'archeological excavations' I found out that this feature was 
already lost in the pre-svn aera (official 0.5.3 was able to do this kind of 
stuff) and the introduction of multifile input probabely wiped finally away 
the last code remnants... code for writing the index to STDOUT (without the 
-idx option) survived, but couldn't be used since the '-' was not allowed 
anymore as filename)... ;-)

The appendet patch now re-invents the 'wheel'... :)

Actually there was just a small change necessay to inbuffer::open
and makeing 'needseek' (used in inbuffer::providedata) globally visible.
The rest is just cosmetics...

Although, I'm not sure about the mmap-stuff in providedata (the part which is 
not used under windows... maybe we can skip that also for STDIN reading?).

I also forbbitted the usage of '-' as filename not only when in gui mode 
(which don't makes sense), but also when in batch-mode because it simply
don't works at the moment! Don't know why... actually it should,... at least 
I've no idea why not... maybe you have?

An application could be the usage of dvbcut as replacement for the above 
tsfilter (which is one of svens private tools to filter the TS from 
unwanted/unnecessary stuff to save disk space)... but ok...

ciao
Ralph

PS: Ahhh... forgot to mention that with this patch it's also possible to give 
-g/-i/-b as CLI switches..  or -gen/-ind/-bat... or whatever you want... ;-)
--- svn/src/buffer.cpp	2007-07-23 20:01:48.000000000 +0200
+++ mine/src/buffer.cpp	2007-10-03 21:39:52.000000000 +0200
@@ -167,6 +167,18 @@
 inbuffer::open(std::string filename, std::string *errmsg) {
   infile f;
 
+  // input from STDIN?
+  if (filename[0]=='-' && filename[1]==0) {
+    needseek=false;
+    f.fd = STDIN_FILENO;
+    f.off = filesize;
+    // is this large enough? ;-)
+    f.end = filesize += LLONG_MAX ;
+    files.push_back(f);
+    return true;
+  }
+
+  needseek=true;
   f.fd = ::open(filename.c_str(), O_RDONLY | O_BINARY);
   if (f.fd == -1) {
     if (errmsg)
@@ -255,6 +267,7 @@
   }
   assert(position >= i->off);
 
+  // should this be also switched off when reading from STDIN???
 #ifndef _WIN32
   // remove old mapping, if any
   if (mmapped) {
@@ -296,7 +309,7 @@
       writepos = len;
       pos = newpos;
       mmapped = true;
-      return inbytes();
+      return inbytes();     
     }
   }
 #endif
@@ -329,9 +342,9 @@
   }
   readpos = 0;
   pos = position;
-  bool needseek = true;
   while (writepos < amount) {
     dvbcut_off_t seekpos = pos + writepos;
+    // this never will/should happen when reading from STDIN (because "end" is too large ;-))
     while (seekpos >= i->end) {
       ++i;
       assert(i != files.end());
@@ -346,7 +359,7 @@
       off_t relpos = seekpos - i->off;
       if (::lseek(i->fd, relpos, SEEK_SET) == -1)
 #endif /* __WIN32__ */
-	return -1;
+        return -1;
       needseek = false;
     }
     size_t len = size - writepos;
--- svn/src/buffer.h	2007-07-23 20:01:48.000000000 +0200
+++ mine/src/buffer.h	2007-10-03 16:11:27.000000000 +0200
@@ -156,6 +156,7 @@
   bool mmapped;
   static long pagesize;
   bool sequential;
+  bool needseek;
 
   void close();
 
--- svn/src/main.cpp	2007-09-07 18:38:55.000000000 +0200
+++ mine/src/main.cpp	2007-10-03 19:06:46.000000000 +0200
@@ -46,7 +46,10 @@
 usage_exit(int rv=1) {
   fprintf(stderr,"Usage:\n"
     "  %s -generateidx [-idx <indexfilename>] <mpgfilename> ...\n"
-    "  %s -batch <prjfilename> | <mpgfilename> ...\n",
+    "  %s -batch <prjfilename> | <mpgfilename> ...\n"
+    "Option -generateidx will read MPEG2 data from STDIN with '-' given as\n"
+    "<mpgfilename> and writes to STDOUT if also no <indexfilename> is given.\n"
+    "All switches can be abbreviated if unambiguous!\n",
     argv0, argv0);
   exit(rv);
 }
@@ -62,15 +65,17 @@
   /*
    * process arguments
    */
+  // for the lazy ones compare only the first view letters (instead n from below)... ;-) 
+  size_t mincmp=2;
   for (i = 1; i < argc && argv[i][0] == '-'; ++i) {
     size_t n = strlen(argv[i]);
-    if (n == 1)	// "-"
+    if (n == 1)	// "-" (reading from STDIN in GUI mode... really? Hmmm,... ok... ;-))
       break;
-    else if (strncmp(argv[i], "-batch", n) == 0)
+    else if (strncmp(argv[i], "-batch", mincmp) == 0)
       batchmode = true;
-    else if (strncmp(argv[i], "-generateidx", n) == 0)
+    else if (strncmp(argv[i], "-generateidx", mincmp) == 0)
       generateidx = true;
-    else if (strncmp(argv[i], "-idx", n) == 0 && ++i < argc)
+    else if (strncmp(argv[i], "-idx", mincmp) == 0 && ++i < argc)
       idxfilename = argv[i];
     else
       usage_exit();
@@ -89,7 +94,11 @@
     std::string mpgfilename = argv[i];	// use first one (for now)
 
     if (idxfilename.empty())
-      idxfilename = mpgfilename + ".idx";
+      if (mpgfilename=="-")
+        // write index to STDOUT if file read from STDIN!
+        idxfilename="-";
+      else 
+        idxfilename = mpgfilename + ".idx";
 
     mpgfile *mpg = 0;
     std::string errormessage;
@@ -125,6 +134,8 @@
 
     return 0;
   }
+  else if (QString(argv[i])=="-") // reading from STDIN not possible in batch/gui mode (at the moment?)
+    usage_exit();
 
   QApplication a(argc, argv);
   QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
--- svn/src/dvbcut.cpp	2007-09-27 18:55:09.000000000 +0200
+++ mine/src/dvbcut.cpp	2007-10-03 21:38:30.000000000 +0200
@@ -303,6 +303,8 @@
       int lastslash(newexpfilen.rfind("/"));
       if (lastdot>=0 && lastslash<lastdot)
         newexpfilen=newexpfilen.substr(0,lastdot);
+      if(newexpfilen=="-")
+        newexpfilen="stdin";
       expfilen=newexpfilen+".mpg";
       int nr=0;
       while (QFileInfo(QString(expfilen)).exists())
@@ -1274,7 +1276,7 @@
   std::string errormessage;
   std::list<std::string>::const_iterator it = filenames.begin();
   while (it != filenames.end() && buf.open(*it, &errormessage))
-    ++it;
+    ++it;  
   buf.setsequential(true);
   if (it == filenames.end()) {
     mpg = mpgfile::open(buf, &errormessage);
@@ -1288,7 +1290,11 @@
   }
 
   if (nogui && idxfilename.empty())
-    idxfilename = filename + ".idx";
+    if (filename=="-")
+      // look for a default file if reading from STDIN and nothing's given?
+      idxfilename = "stdin.idx";
+    else 
+      idxfilename = filename + ".idx";
 
   if (idxfilename.empty()) {
     QString s=QFileDialog::getSaveFileName(
@@ -1312,6 +1318,7 @@
   pictures=-1;
 
   if (!idxfilename.empty()) {
+    //UNFORTUNATELY the existing indexfile is not accepted from loadindex if reading from STDIN!!!  
     std::string errorstring;
     busy.setbusy(true);
     pictures=mpg->loadindex(idxfilename.c_str(),&errorstring);
@@ -1343,6 +1350,7 @@
   }
 
   if (pictures<0) {
+    //UNFORTUNATELY the indexfile is created but there's an endless loop when exporting if reading from STDIN!!!  
     progressstatusbar psb(statusBar());
     psb.setprogress(500);
     psb.print("Indexing '%s'...",filename.c_str());
@@ -1350,7 +1358,7 @@
     busy.setbusy(true);
     pictures=mpg->generateindex(idxfilename.empty()?0:idxfilename.c_str(),&errorstring,&psb);
     busy.setbusy(false);
-    if (nogui && pictures > 0)
+    //if (nogui && pictures > 0)
       fprintf(stderr,"Generated index with %d pictures!\n",pictures);
 
     if (psb.cancelled()) {
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
DVBCUT-devel mailing list
DVBCUT-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dvbcut-devel

Reply via email to