[xiph-cvs] cvs commit: vorbis-tools/vcut vcut.c vcut.h

Michael Smith msmith at xiph.org
Tue Nov 12 04:45:21 PST 2002



msmith      02/11/12 07:45:21

  Modified:    vcut     vcut.c vcut.h
  Log:
  Patch from Jared Anderson <jared at ieee.org>
  This allows setting vcut's cutpoint in (integer) seconds, by prefixing the
  cut point with a +

Revision  Changes    Path
1.7       +38 -11    vorbis-tools/vcut/vcut.c

Index: vcut.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vcut/vcut.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- vcut.c	29 Jan 2002 10:37:08 -0000	1.6
+++ vcut.c	12 Nov 2002 12:45:21 -0000	1.7
@@ -7,7 +7,7 @@
  * Simple application to cut an ogg at a specified frame, and produce two
  * output files.
  *
- * last modified: $Id: vcut.c,v 1.6 2002/01/29 10:37:08 msmith Exp $
+ * last modified: $Id: vcut.c,v 1.7 2002/11/12 12:45:21 msmith Exp $
  */
 
 #include <stdio.h>
@@ -24,9 +24,11 @@
 #include "i18n.h"
 
 #ifdef _WIN32
-#define FORMAT_INT64 "%I64d"
+#define FORMAT_INT64	  "%I64d"
+#define FORMAT_INT64_TIME "+%I64d"
 #else
-#define FORMAT_INT64 "%Ld"
+#define FORMAT_INT64	  "%Ld"
+#define FORMAT_INT64_TIME "+%Ld"
 #endif
 
 static vcut_packet *save_packet(ogg_packet *packet)
@@ -353,6 +355,8 @@
 }
                                                                         
 /* Pull out and save the 3 header packets from the input file.
+ * If the cutpoint arg was given as seconds, find the number
+ * of samples.
  */
 static int process_headers(vcut_state *s)
 {
@@ -362,6 +366,7 @@
         int bytes;
         int i;
         unsigned char *buffer;
+	ogg_int64_t samples;
 
         ogg_sync_init(s->sync_in);
         
@@ -435,6 +440,11 @@
 
         vorbis_comment_clear(&vc);
 
+	if(s->time) {
+	  samples = s->cutpoint * s->vi->rate;
+	  s->cutpoint = samples;
+	}
+
         return 0;
 }
 
@@ -442,8 +452,10 @@
 int main(int argc, char **argv)
 {
         ogg_int64_t cutpoint;
+	ogg_int64_t cutpoint_secs = 0;
         FILE *in,*out1,*out2;
         int ret=0;
+	int time=0;
         vcut_state *state;
 
         setlocale(LC_ALL, "");
@@ -453,7 +465,7 @@
         if(argc<5)
         {
                 fprintf(stderr, 
-				_("Usage: vcut infile.ogg outfile1.ogg outfile2.ogg cutpoint\n"));
+				_("Usage: vcut infile.ogg outfile1.ogg outfile2.ogg [cutpoint | +cutpoint]\n"));
                 exit(1);
         }
 
@@ -476,17 +488,27 @@
                 exit(1);
         }
 
-	if(sscanf(argv[4], FORMAT_INT64, &cutpoint) != 1) {
-        fprintf(stderr, _("Couldn't parse cutpoint \"%s\"\n"), argv[4]);
-        exit(1);
-    }
+	if(strchr(argv[4], '+') != NULL) {
+	  if(sscanf(argv[4], FORMAT_INT64_TIME, &cutpoint) != 1) {
+	    fprintf(stderr, _("Couldn't parse cutpoint \"%s\"\n"), argv[4]);
+            exit(1);
+	  }
+	  time = 1;
+	} else if(sscanf(argv[4], FORMAT_INT64, &cutpoint) != 1) {
+	    fprintf(stderr, _("Couldn't parse cutpoint \"%s\"\n"), argv[4]);
+            exit(1);
+	}
 
-	fprintf(stderr, _("Processing: Cutting at %lld\n"), cutpoint);
+	if(time) {
+	  fprintf(stderr, _("Processing: Cutting at %lld seconds\n"), cutpoint);
+	} else {
+	  fprintf(stderr, _("Processing: Cutting at %lld samples\n"), cutpoint);
+	}
 
         state = vcut_new();
 
         vcut_set_files(state, in,out1,out2);
-	vcut_set_cutpoint(state, cutpoint);
+	vcut_set_cutpoint(state, cutpoint, time);
 
         if(vcut_process(state))
         {
@@ -494,6 +516,7 @@
                 ret = 1;
         }
 
+
         vcut_free(state);
 
         fclose(in);
@@ -629,10 +652,14 @@
         s->out2 = out2;
 }
 
-void vcut_set_cutpoint(vcut_state *s, ogg_int64_t cutpoint)
+void vcut_set_cutpoint(vcut_state *s, ogg_int64_t cutpoint, int time)
 {
         s->cutpoint = cutpoint;
+	s->time = 1;
 }
 
+void vcut_time_to_samples(ogg_int64_t *time, ogg_int64_t *samples, FILE *in)
+{
 
+}
 

<p><p>1.5       +2 -1      vorbis-tools/vcut/vcut.h

Index: vcut.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vcut/vcut.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- vcut.h	20 Aug 2001 12:02:48 -0000	1.4
+++ vcut.h	12 Nov 2002 12:45:21 -0000	1.5
@@ -18,6 +18,7 @@
         vorbis_info *vi;
         int prevW;
         ogg_int64_t initialgranpos;
+	int time;
         ogg_int64_t cutpoint;
         unsigned int serial;
         vcut_packet **headers; /* 3 */
@@ -28,7 +29,7 @@
 
 int vcut_process(vcut_state *state);
 void vcut_set_files(vcut_state *s, FILE *in, FILE *out1, FILE *out2);
-void vcut_set_cutpoint(vcut_state *s, ogg_int64_t cutpoint);
+void vcut_set_cutpoint(vcut_state *s, ogg_int64_t cutpoint, int time);
 vcut_state *vcut_new(void);
 void vcut_free(vcut_state *state);
 

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list