[MPlayer-dev-eng] [PATCH] PNG frame skipping and ranges

Benjamin R. Ginter bginter at asicommunications.com
Sun Jan 20 15:02:17 CET 2002


D'oh!

Wouldn't you know it.  It occurred to me after sending this that -frames
already does what -skipstop does but for all video output drivers.  So
I've removed that, changed the options to use CONF_MIN instead of
CONF_RANGE (like -frames uses), and fixed a minor bug in -skipstart.  :)

Sorry.  Please use this patch instead.

Ben


On Sun, 20 Jan 2002, Benjamin R. Ginter wrote:

> Hello,
>
> This patch adds the command-line options -skip, -skipstart, and -skipstop
> for use with the PNG video output driver.
>
>   -skip N causes mplayer to only write a PNG file every N frames.
>
>   -skipstart N causes mplayer to skip the first N frames before writing.
>
>   -skipstop N causes mplayer to exit after N frames have been processed.
>
> Each option can be used alone or in any combination.
>
>
> Thanks for a great program!
>
> Benjamin R. Ginter
>
>
>

-------------- next part --------------
Index: main/cfg-mplayer.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-mplayer.h,v
retrieving revision 1.126
diff -u -r1.126 cfg-mplayer.h
--- main/cfg-mplayer.h	19 Jan 2002 16:59:59 -0000	1.126
+++ main/cfg-mplayer.h	20 Jan 2002 13:53:47 -0000
@@ -20,6 +20,8 @@
 #endif
 #ifdef HAVE_PNG
 extern int z_compression;
+extern int png_skip;
+extern int png_skip_start;
 #endif
 #ifdef HAVE_SDL
 //extern char *sdl_driver;
@@ -218,6 +220,8 @@
 
 #ifdef HAVE_PNG
 	{"z", &z_compression, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
+        {"skip", &png_skip, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
+        {"skipstart", &png_skip_start, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
 #endif
 #ifdef HAVE_SDL
 	{"sdl", "Use -vo sdl:driver instead of -vo sdl -sdl driver\n",
Index: main/libvo/vo_png.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_png.c,v
retrieving revision 1.8
diff -u -r1.8 vo_png.c
--- main/libvo/vo_png.c	8 Jan 2002 20:58:53 -0000	1.8
+++ main/libvo/vo_png.c	20 Jan 2002 13:53:49 -0000
@@ -24,6 +24,7 @@
 
 #include "../postproc/swscale.h"
 #include "../postproc/rgb2rgb.h"
+#include "../help_mp.h"
 
 LIBVO_EXTERN (png)
 
@@ -40,6 +41,8 @@
 
 extern int verbose;
 int z_compression = Z_NO_COMPRESSION;
+int png_skip = 0;
+int png_skip_start = 0;
 static int image_width;
 static int image_height;
 static int image_format;
@@ -113,7 +116,13 @@
 	    z_compression = Z_BEST_SPEED;
     }
     
-    if(verbose)	printf("PNG Compression level %i\n", z_compression);   
+    if(verbose)	{
+	    printf("PNG Compression level %i\n", z_compression);   
+
+	    if(png_skip) printf("Skipping %d frames between writes\n", png_skip);
+	    if(png_skip_start>0) printf("Skipping %d frames before writing\n", png_skip_start);
+		
+    }
 	  	
     return 0;
 }
@@ -214,26 +223,30 @@
     struct pngdata png;
     png_byte *row_pointers[image_height];
     
-    snprintf (buf, 100, "%08d.png", ++framenum);
+    framenum++;
 
+    if ( !do_frame() ) return 0;
+      
+    snprintf (buf, 100, "%08d.png", framenum);
+    
     png = create_png(buf);
-
+    
     if(png.status){
-	    printf("PNG Error in create_png\n");
-	    return 1;
+      printf("PNG Error in create_png\n");
+      return 1;
     }	     
-
+    
     if(verbose > 1) printf("PNG Creating Row Pointers\n");
     for ( k = 0; k < image_height; k++ ) row_pointers[k] = &src[0][image_width*k*bppmul];
     
     //png_write_flush(png.png_ptr);
     //png_set_flush(png.png_ptr, nrows);
-
+    
     if(verbose > 1) printf("PNG Writing Image Data\n");
     png_write_image(png.png_ptr, row_pointers);
-
+    
     return destroy_png(png);
-
+    
 }
 
 static void draw_osd(void)
@@ -249,24 +262,27 @@
     png_byte *row_pointers[image_height];
   
   if(image_format == IMGFMT_YV12) {
+    framenum++;
+    
+    if( !do_frame() ) return;
 
-    snprintf (buf, 100, "%08d.png", ++framenum);
-
+    snprintf (buf, 100, "%08d.png", framenum);
+    
     png = create_png(buf);
-
+    
     if(png.status){
-	    printf("PNG Error in create_png\n");
+      printf("PNG Error in create_png\n");
     }	     
-
+    
     if(verbose > 1) printf("PNG Creating Row Pointers\n");
     for ( k = 0; k < image_height; k++ ) row_pointers[k] = &image_data[image_width*k*bppmul];
     
     //png_write_flush(png.png_ptr);
     //png_set_flush(png.png_ptr, nrows);
-
+    
     if(verbose > 1) printf("PNG Writing Image Data\n");
     png_write_image(png.png_ptr, row_pointers);
-
+    
     destroy_png(png);
   }
 }
@@ -308,4 +324,24 @@
 
 static void check_events(void)
 {
+}
+
+int do_frame (void) {
+  if ( png_skip ) { 
+    if ( png_skip_start && framenum < png_skip_start ) {
+      return 0;
+    }
+
+    if ( framenum % png_skip != 0 ) {
+      return 0;
+    }
+
+    return 1;
+  }
+
+  if ( png_skip_start && framenum < png_skip_start ) {
+    return 0;
+  }
+
+  return 1;
 }


More information about the MPlayer-dev-eng mailing list