[xiph-cvs] cvs commit: snatch README-MJPEG snatchconvert.c

Monty xiphmont at xiph.org
Fri Feb 22 13:34:02 PST 2002



xiphmont    02/02/22 13:34:02

  Modified:    .        README-MJPEG snatchconvert.c
  Log:
  add gap handling [cut large gaps in captures due to congestion,
  temporary outages]
  
  Monty

Revision  Changes    Path
1.2       +7 -1      snatch/README-MJPEG

Index: README-MJPEG
===================================================================
RCS file: /usr/local/cvsroot/snatch/README-MJPEG,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- README-MJPEG	2001/11/15 08:37:48	1.1
+++ README-MJPEG	2002/02/22 21:34:00	1.2
@@ -1,4 +1,4 @@
-Snatch 20011114
+Snatch 20020222
 
 Converting Snatch capture files to MPEG audio/video with MJPEG-1.4.1
 
@@ -7,6 +7,12 @@
 mjpegtools-1.4.1 is a nice little collection of MPEG audio and video
 utilities that, for the most part, work out of the box.  The output
 quality is very nice, and the tool set is intelligently arranged.
+
+(I'll note that 1.6.0 of mjpeg-tools is now out; I find that 1.4.1
+gives slightly better quality performance and still prefer it over its
+newer cousing.  Also, 1.6.0 changes the YUV file format used together
+by the tools in an incompatable way with 1.4.1, so supporting both
+will take some hacking).
 
 The various tools in the mjpeg-tools trade video in YUV format and
 audio as WAV.  Snatch support for mjpegtools consists of two

<p><p>1.11      +73 -33    snatch/snatchconvert.c

Index: snatchconvert.c
===================================================================
RCS file: /usr/local/cvsroot/snatch/snatchconvert.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- snatchconvert.c	2002/02/22 17:21:34	1.10
+++ snatchconvert.c	2002/02/22 21:34:00	1.11
@@ -36,6 +36,8 @@
 int video_p;
 
 double begin_time=0.;
+double last_time=-1.;
+double fudge_time=0.;
 double end_time=1e90;
 double global_zerotime=0.;
 
@@ -369,7 +371,21 @@
   }
 }
 
-
+static double snip_gap_cleanly(double now,int audio){
+  /* fudge the clock to zip through most/all of the gap or overlap */
+  
+  if(audio || !audio_p){
+    if(last_time!=-1){
+      if(last_time+2.<now){
+	fudge_time-=now-last_time-1.;
+      }
+      if(last_time>now)
+	fudge_time+=last_time-now;
+    }
+    last_time=now;
+  }
+  return(now+fudge_time);
+}
 
 /************************ snatch parsing *********************/
 
@@ -411,17 +427,17 @@
       buftempsize+=toread;
     }
     
-    if((long)fread(buftemp+buftemphead,1,toread,f)!=toread)return(0);
+    if((long)fread(buftemp+buftemphead,1,toread,f)!=toread)return(-1);
     buftemphead+=toread;
   }
 
   if(verify){
-    if(!strncmp(buftemp+buftemptail+length,"AUDIO",5))return(1);
-    if(!strncmp(buftemp+buftemptail+length,"VIDEO",5))return(1);
-    if(!strncmp(buftemp+buftemptail+length,"YUV12",5))return(1);
+    if(!strncmp(buftemp+buftemptail+length,"AUDIO",5))return(length);
+    if(!strncmp(buftemp+buftemptail+length,"VIDEO",5))return(length);
+    if(!strncmp(buftemp+buftemptail+length,"YUV12",5))return(length);
     return(0);
   }else{
-    return(1);
+    return(length);
   }
 }
 
@@ -454,8 +470,8 @@
   if(!s)return(0);
   length=atoi(s);
 
-  if(!read_snatch_frame_helper(f,length,1))
-    return(0);
+  if((ret=read_snatch_frame_helper(f,length,1))!=length)
+    return(ret);
 
   if(global_zerotime==0){
     global_zerotime=t;
@@ -463,9 +479,25 @@
     end_time+=t;
   }
 
-  if(t<begin_time)return(length);
+  if(audbuf_rate==0)audbuf_rate=ra;
+  if(audbuf_channels==0)audbuf_channels=ch;
+  
+  if(t<begin_time){
+    int bps=1;
+    switch(fmt){
+    case 5:case 6:case 8:case 9:
+      bps=2;
+      break;
+    }
+    samplesin+=length/(ch*bps);
+    return(length);
+  }
+
   if(t>end_time)
-    return(0);
+    return(-1);
+
+  /* do we have a large capture gap (eg>2s)? */
+  t=snip_gap_cleanly(t,1);
 
   if(audbuf_zerotime==0){
     audbuf_zerotime=t;
@@ -509,9 +541,6 @@
     }
   }
   
-  if(audbuf_rate==0)audbuf_rate=ra;
-  if(audbuf_channels==0)audbuf_channels=ch;
-  
   if(audbuf_rate!=ra && resampler[0].input_rate!=ra){
     /* set up resampling */
     resample_clear(&resampler[0]);
@@ -709,7 +738,6 @@
 
 }
 
-
 unsigned char     **vidbuf;
 long long *vidbuf_frameno;
 double     vidbuf_zerotime;
@@ -730,7 +758,7 @@
 long long framesmissing=0;
 long long framesdiscarded=0;
 
-double last_t=-1;
+double video_last_time=-1;
       
 static int process_video_frame(char *buffer,FILE *f,int notfakep,int yuvp){
   char *s=buffer+6;
@@ -755,8 +783,8 @@
   if(!s)return(0);
   length=atoi(s);
 
-  if(!read_snatch_frame_helper(f,length,1))
-    return(0);
+  if((ret=read_snatch_frame_helper(f,length,1))!=length)
+    return(ret);
 
   if(global_zerotime==0){
     global_zerotime=t;
@@ -766,17 +794,20 @@
 
   if(t<begin_time)return(length);
   if(t>end_time)
-    return(0);
+    return(-1);
+
+  /* do we have a large capture gap (eg>2s)? */
+  t=snip_gap_cleanly(t,0);
 
-  if(last_t!=-1){
-    double del_t=t-last_t;
+  if(video_last_time!=-1){
+    double del_t=t-video_last_time;
     if(del_t>0){
-      int val=ceil(1./(t-last_t));
+      int val=ceil(1./(t-video_last_time));
       if(val>0 && val<61)
         fpsgraph[val]++;
     }
   }
-  last_t=t;
+  video_last_time=t;
 
   /* video sync is fundamentally different from audio. We assume that
      frames never appear early; an frame that seems early in context
@@ -919,14 +950,19 @@
         if(audio || video || yuv12){
           if(audio)
             ret=process_audio_frame(audio, f, wa);
-	  else if(video)
+	  else if(video){
             ret=process_video_frame(video, f, wv,0);
-	  else
+	    framesin++;
+	  }else{
             ret=process_video_frame(yuv12, f, wv,1);
+	    framesin++;
+	  }
 
-	  buftemptail+=ret;
-	  return(ret);
-	  
+	  if(ret<0)return(0);
+	  if(ret>0){
+	    buftemptail+=ret;
+	    return(ret);
+	  }
         }
        
       }else{
@@ -975,6 +1011,7 @@
   fwrite(buf,1,vidbuf_width*vidbuf_height*3/2,f);
 }
 
+static int begun;
 static int synced;
 static int drain;
 static int header;
@@ -1015,11 +1052,14 @@
         long samples=0;
         int i;
 
-	if(process_audio)
-	  WriteWav(out,audbuf_channels,audbuf_rate,16);
-	if(process_video)
-	  WriteYuv(out,vidbuf_width,vidbuf_height,ratecode);
-	
+	if(!begun){
+	  if(process_audio)
+	    WriteWav(out,audbuf_channels,audbuf_rate,16);
+	  if(process_video)
+	    WriteYuv(out,vidbuf_width,vidbuf_height,ratecode);
+	  begun=1;
+	}
+
         /* we don't write frames/samples here; we queue new ones out
            ahead until everything's even */
 
@@ -1088,7 +1128,7 @@
     }
     return 1;
   }
-  
+
   if(video_p && process_video){
     while(vidbuf_head-vidbuf_tail>video_timeahead){
       int oframes= 

<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