[MPlayer-dev-eng] [PATCH] PNG frame skipping and ranges
Benjamin R. Ginter
bginter at asicommunications.com
Sun Jan 20 14:28:17 CET 2002
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:35:41 -0000
@@ -20,6 +20,9 @@
#endif
#ifdef HAVE_PNG
extern int z_compression;
+extern int png_skip;
+extern int png_skip_start;
+extern int png_skip_stop;
#endif
#ifdef HAVE_SDL
//extern char *sdl_driver;
@@ -218,6 +221,9 @@
#ifdef HAVE_PNG
{"z", &z_compression, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
+ {"skip", &png_skip, CONF_TYPE_INT, CONF_RANGE, 0, 648000, NULL},
+ {"skipstart", &png_skip_start, CONF_TYPE_INT, CONF_RANGE, 0, 648000, NULL},
+ {"skipstop", &png_skip_stop, CONF_TYPE_INT, CONF_RANGE, 0, 648000, 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:35:42 -0000
@@ -24,6 +24,7 @@
#include "../postproc/swscale.h"
#include "../postproc/rgb2rgb.h"
+#include "../help_mp.h"
LIBVO_EXTERN (png)
@@ -40,6 +41,9 @@
extern int verbose;
int z_compression = Z_NO_COMPRESSION;
+int png_skip = 0;
+int png_skip_start = 0;
+int png_skip_stop = 0;
static int image_width;
static int image_height;
static int image_format;
@@ -113,7 +117,21 @@
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);
+
+ if ( png_skip_stop > 0 ) {
+ if ( png_skip_stop < png_skip_start ) {
+ printf("PNG Warning: skip_stop less than skip_start. Ignored!\n");
+ }
+ else {
+ printf("Will stop writing after %d frames\n", png_skip_stop);
+ }
+ }
+ }
return 0;
}
@@ -214,26 +232,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 +271,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 +333,30 @@
static void check_events(void)
{
+ // exit if we've hit the png_skip_stop number of frames
+ if ( png_skip_stop > 0 && framenum >= png_skip_stop ) {
+ exit_player(MSGTR_Exit_frames);
+ }
+}
+
+// png_skip, png_skip_start, and png_skip_stop are all optional
+// return true by default
+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