[xiph-cvs] cvs commit: snatch snatch2yuv.c snatchconvert.c

Monty xiphmont at xiph.org
Fri Feb 22 08:33:10 PST 2002



xiphmont    02/02/22 08:33:10

  Modified:    .        snatch2yuv.c snatchconvert.c
  Log:
  add fps graphing, and split input/output fps settings
  
  Monty

Revision  Changes    Path
1.4       +36 -6     snatch/snatch2yuv.c

Index: snatch2yuv.c
===================================================================
RCS file: /usr/local/cvsroot/snatch/snatch2yuv.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- snatch2yuv.c	2001/11/15 08:37:48	1.3
+++ snatch2yuv.c	2002/02/22 16:33:09	1.4
@@ -35,7 +35,8 @@
 
 extern int        vidbuf_height;
 extern int        vidbuf_width;
-extern double     vidbuf_fps;
+extern double     vidin_fps;
+extern double     vidout_fps;
 extern int        ratecode;
 extern int        video_timeahead;
                          
@@ -46,6 +47,7 @@
 extern long long framesout;
 extern long long framesmissing;
 extern long long framesdiscarded;
+extern long fpsgraph[61];
       
 int snatch_iterator(FILE *in,FILE *out,int process_a,int process_v);
 
@@ -72,7 +74,14 @@
           "                  7, 59.940fps\n"
           "                  8, 60.000fps\n"
           "              N=5, 30fps default\n"
+	  "  -g        : graph distribution of frame time deltas [to help\n"
+	  "              determine correct input fps]\n"              
           "  -h        : this information to stdout\n"
+	  "  -i <N>    : force input to specific number of frames per \n"
+	  "              second.  Setting this to the 'correct' input fps\n"
+	  "              is never necessary, but it will smooth the video\n "
+	  "              motion in a capture that contains jerks/dropouts.\n"
+	  "              Use the actual fps for <N>, not MPEG mode as above.\n"
           "  -n <N>    : output only up to the last frame beginning \n"
           "              before <N> seconds elapsed from start of file\n"
           "              (if preceeding or without -b) or from start of\n"
@@ -82,15 +91,17 @@
           "              width W by height H\n\n");
 }
 
-const char *optstring = "b:f:hn:qs:";
+const char *optstring = "b:f:ghi:n:qs:";
 
 int main(int argc,char *argv[]){
   int done=0;
   int noisy=1;
   int c;
+  int graph=0;
 
   ratecode=5;
-  vidbuf_fps=30;
+  vidin_fps=30;
+  vidout_fps=30;
   video_timeahead=15;
 
   while((c=getopt(argc,argv,optstring))!=EOF){
@@ -102,8 +113,16 @@
       ratecode=atoi(optarg);
       if(ratecode<1)ratecode=1;
       if(ratecode>8)ratecode=8;
-      vidbuf_fps=framerates[ratecode];
+      vidout_fps=framerates[ratecode];
       break;
+    case 'g':
+      graph=1;
+      break;
+    case 'i':
+      vidin_fps=atof(optarg);
+      if(vidin_fps<1.)vidin_fps=1.;
+      if(vidin_fps>60.)vidin_fps=60.;
+      break;
     case 'h':
       usage(stdout);
       return(0);
@@ -139,7 +158,7 @@
     done=snatch_iterator(stdin,stdout,0,1);
 
     if(noisy){
-      long seconds=framesout/vidbuf_fps;
+      long seconds=framesout/vidout_fps;
       long minutes=seconds/60;
       long hours;
 
@@ -151,8 +170,19 @@
               (long)framesin,(long)framesout,(long)framesdiscarded,(long)framesmissing,
               hours,minutes,seconds);
     }
+  }
+
+  if(graph){
+    long total=0;
+    int i;
+
+    if(noisy)fprintf(stderr,"\n");
+    for(i=1;i<=60;i++)
+      total+=fpsgraph[i];
+    for(i=1;i<=60;i++)
+      fprintf(stderr,"%3dfps|%*c\n",i,fpsgraph[i]*70/total,'*');
   }
-	      
+    
   if(noisy)fprintf(stderr,"\n");
   return(0);
 }

<p><p>1.9       +42 -15    snatch/snatchconvert.c

Index: snatchconvert.c
===================================================================
RCS file: /usr/local/cvsroot/snatch/snatchconvert.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- snatchconvert.c	2002/02/22 15:16:01	1.8
+++ snatchconvert.c	2002/02/22 16:33:09	1.9
@@ -44,6 +44,8 @@
 long           buftemptail;
 long           buftempsize;
 
+long  fpsgraph[61];
+
 /* audio resampling ripped from sox and simplified */
 /*
  * July 5, 1991
@@ -391,6 +393,9 @@
   video_p=0;
   if(buffer[6]=='A')audio_p=1;
   if(buffer[7]=='V')video_p=1;
+
+
+  memset(fpsgraph,0,sizeof(fpsgraph));
   return(1);
 }
 
@@ -712,7 +717,8 @@
 int        vidbuf_size;
 int        vidbuf_height;
 int        vidbuf_width;
-double     vidbuf_fps;
+double     vidin_fps;
+double     vidout_fps;
                          
 int scale_width;
 int scale_height;
@@ -721,6 +727,8 @@
 long long framesout=0;
 long long framesmissing=0;
 long long framesdiscarded=0;
+
+double last_t=-1;
       
 static int process_video_frame(char *buffer,FILE *f,int notfakep,int yuvp){
   char *s=buffer+6;
@@ -756,6 +764,16 @@
   if(t<begin_time)return(length);
   if(t>end_time)return(0);
 
+  if(last_t!=-1){
+    double del_t=t-last_t;
+    if(del_t>0){
+      int val=ceil(1./(t-last_t));
+      if(val>0 && val<61)
+	fpsgraph[val]++;
+    }
+  }
+  last_t=t;
+
   /* video sync is fundamentally different from audio. We assume that
      frames never appear early; an frame that seems early in context
      of the previous frame is due backlogged framebuffer catching up
@@ -765,7 +783,7 @@
     vidbuf_zerotime=t;
   }else{
     double ideal=(double)vidbuf_frames;
-    double actual=(t-vidbuf_zerotime)*vidbuf_fps;
+    double actual=(t-vidbuf_zerotime)*vidin_fps;
     double drift=actual-ideal;
     int i;
 
@@ -1004,9 +1022,9 @@
         if(time_dif>0){
           /* audio started first; prestretch video, then repad with
              audio */
-	  frames=ceil(time_dif*vidbuf_fps);
-	  time_dif-=(frames/vidbuf_fps);
-	  vidbuf_zerotime-=(frames/vidbuf_fps);
+	  frames=ceil(time_dif*vidin_fps);
+	  time_dif-=(frames/vidin_fps);
+	  vidbuf_zerotime-=(frames/vidin_fps);
           for(i=vidbuf_tail+1;i<vidbuf_head;i++)
             vidbuf_frameno[i]+=frames;
           framesmissing+=frames;
@@ -1040,15 +1058,20 @@
     
     if(video_p){
       for(i=vidbuf_tail;i<vidbuf_head;i++){
-	int frames=(i+1<vidbuf_head)?
-	  vidbuf_frameno[i+1]-vidbuf_frameno[i]:
+	int oframes=(i+1<vidbuf_head)?
+	  vidbuf_frameno[i+1]*vidout_fps/vidin_fps-
+	  vidbuf_frameno[i]  *vidout_fps/vidin_fps:
+	  vidout_fps/vidin_fps;
+	int iframes=(i+1<vidbuf_head)?
+	  vidbuf_frameno[i+1]-
+	  vidbuf_frameno[i]  :
           1;
         
-	framesout+=frames;
-	framesmissing+=(frames-1);
+	framesout+=oframes;
+	framesmissing+=iframes-1;
         
         if(process_video)
-	  while(frames--)
+	  while(oframes--)
             YUVout(vidbuf[i],out);
       }
     }
@@ -1064,13 +1087,17 @@
   
   if(video_p && process_video){
     while(vidbuf_head-vidbuf_tail>video_timeahead){
-      int frames= vidbuf_frameno[vidbuf_tail+1]-
-	vidbuf_frameno[vidbuf_tail];
-      framesout+=frames;
-      framesmissing+=(frames-1);
+      int oframes= 
+	vidbuf_frameno[vidbuf_tail+1]*vidout_fps/vidin_fps-
+	vidbuf_frameno[vidbuf_tail]  *vidout_fps/vidin_fps;
+      int iframes= 
+	vidbuf_frameno[vidbuf_tail+1]-
+	vidbuf_frameno[vidbuf_tail]  ;
+      framesout+=oframes;
+      framesmissing+=iframes-1;
       
       if(process_video)
-	while(frames--)
+	while(oframes--)
           YUVout(vidbuf[vidbuf_tail],out);
       
       vidbuf_tail++;

<p><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