[cvs-annodex] commit (/annodex): libannodex/trunk/src/tools/anxed.c

conrad nobody at lists.annodex.net
Fri Apr 1 15:42:41 EST 2005


Update of /annodex (new revision 1201)

Modified files:
   libannodex/trunk/src/tools/anxed.c

Log Message:
add --id argument to anxed, for testing named offset remuxing


Modified: libannodex/trunk/src/tools/anxed.c
===================================================================
--- libannodex/trunk/src/tools/anxed.c	2005-04-01 05:41:51 UTC (rev 1200)
+++ libannodex/trunk/src/tools/anxed.c	2005-04-01 05:42:41 UTC (rev 1201)
@@ -41,8 +41,13 @@
 
 #include "common.h"
 
+/*#define DEBUG*/
+
 #define ANX_CONTENT_TYPE "application/x-annodex"
 
+#define MEDIA_BUF_LEN 8192
+
+
 /*
  * usage ()
  *
@@ -56,11 +61,40 @@
   printf ("Options\n");
   printf ("  -o, --output      Specify output filename (default is stdout)\n\n");
   printf ("  -s, --seek-offset Specify time offset to seek input to\n");
-  printf ("  -e, --seek-end    Specify time offset to end input at\n\n");
+  printf ("  -e, --seek-end    Specify time offset to end input at\n");
+  printf ("  -i, --id          Specify the starting CMML id\n\n");
   printf ("  -h, --help        Display this help and exit\n");
   printf ("  --version         Output version information and exit\n\n");
 }
 
+static double
+ae_clip_time (char * filename, char * id)
+{
+  ANNODEX * anx;
+  int ret;
+  unsigned char buf[MEDIA_BUF_LEN];
+  long n = MEDIA_BUF_LEN;
+  double clip_offset;
+
+  anx = anx_new (ANX_WRITE);
+  ret = anx_write_import (anx, filename, NULL, NULL, 0.0, -1.0, 0);
+
+  /* Only spin through the file if the requested clip has not yet been
+   * inserted; avoid scanning media if 'filename' is a cmml file. */
+  if ((clip_offset = anx_get_clip_time_by_id (anx, id)) == -1.0) {
+    while ((n = anx_write_output (anx, buf, MEDIA_BUF_LEN)) > 0);
+
+    if ((clip_offset = anx_get_clip_time_by_id (anx, id)) == -1.0) {
+      clip_offset = 0.0;
+    }
+  }
+  
+  if (anx_close (anx) != NULL) {
+  }
+
+  return clip_offset;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -75,6 +109,7 @@
   /*  FILE * infile = stdin;*/
 
   double seek_offset = 0.0, seek_end = -1.0;
+  char * id = NULL;
 
   char * outfilename = NULL;
 
@@ -101,6 +136,9 @@
     } else if (OPT("--seek-offset") || OPT("-s")) {
       i++; if (i >= argc) goto usage_err;
       seek_offset = anx_parse_time (argv[i]);
+    } else if (OPT("--id") || OPT("-i")) {
+      i++; if (i >= argc) goto usage_err;
+      id = argv[i];
     } else if (OPT("--output") || OPT("-o")) {
       i++; if (i >= argc) goto usage_err;
       outfilename = argv[i];
@@ -134,6 +172,15 @@
     outfilename = outfilename_buf;
   }
 
+  anx_init_importers ("*/*");
+
+  if (seek_offset == 0.0 && id != NULL) {
+    seek_offset = ae_clip_time (infilename, id);
+#ifdef DEBUG
+    printf ("anxed: id %s has time %f\n", id, seek_offset);
+#endif
+  }
+
   anx = anx_open (outfilename, ANX_WRITE);
 
   if (anx == NULL) {
@@ -144,8 +191,6 @@
   anx_set_presentation_time (anx, seek_offset);
   anx_set_basetime (anx, 0.0);
 
-  anx_init_importers ("*/*");
-
 #ifdef DEBUG
     printf ("anxed: anx_writer_import %s @npt=%f-%f\n", infilename, seek_offset, seek_end);
 #endif


-- 
conrad



More information about the cvs-annodex mailing list